annotate MoinMoin/Page.py @ 5829:a744f573fe30

advancedsearch: fix problem with non-ascii chars breaking up words for OR and NOT terms
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 04 Feb 2012 16:52:24 +0100
parents bf0b4b96dcb4
children 3b1b875eb4f2
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - Page class
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
4
1909
be140a589f11 improved some module docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1908
diff changeset
5 Page is used for read-only access to a wiki page. For r/w access see PageEditor.
be140a589f11 improved some module docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1908
diff changeset
6 A Page object is used to access a wiki page (in general) as well as to access
be140a589f11 improved some module docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1908
diff changeset
7 some specific revision of a wiki page.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
8
1909
be140a589f11 improved some module docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1908
diff changeset
9 The RootPage is some virtual page located at / and is mainly used to do namespace
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
10 operations like getting the page list.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
11
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
12 Currently, this is all a big mixture between high-level page code, intermediate
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
13 data/underlay layering code, caching code and low-level filesystem storage code.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
14 To see the filesystem storage layout we use, best is to look into data/pages/
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
15 (underlay dir uses the same format).
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
16
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
17 TODO:
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
18 * Cleanly separate the code into packages for:
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
19 * Page (or rather: Item)
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
20 * Layering
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
21 * Cache
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
22 * Storage
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
23 * ACLs should be handled on a low layer, raising an Exception when access
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
24 is denied, so we won't have security issues just because someone forgot to check
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
25 user.may.read(secretpage).
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
26 * The distinction between a item and a item revision should be clearer.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
27 * Items can be anything, not just wiki pages, but also files of any mimetype.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
28 The mimetype hierarchy should be modelled by a MimeTypeItem class hierarchy.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
29
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1909
diff changeset
30 @copyright: 2000-2004 by Juergen Hermann <jh@web.de>,
3127
ea5383222f2f refactored misc. modules to use own logger instead of request.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3110
diff changeset
31 2005-2008 by MoinMoin:ThomasWaldmann,
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
32 2006 by MoinMoin:FlorianFesti,
1993
93877b7d87b9 fixing copyright headers:unified my name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1964
diff changeset
33 2007 by MoinMoin:ReimarBauer
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
35 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
36
3285
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
37 import os, re, codecs
3110
a48929a5036c logging: make it work correctly by doing logging configuration very early
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3085
diff changeset
38
a48929a5036c logging: make it work correctly by doing logging configuration very early
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3085
diff changeset
39 from MoinMoin import log
a48929a5036c logging: make it work correctly by doing logging configuration very early
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3085
diff changeset
40 logging = log.getLogger(__name__)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
41
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42 from MoinMoin import config, caching, user, util, wikiutil
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43 from MoinMoin.logfile import eventlog
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
44
1126
fd05b2dc86a4 Now it even works on Python < 2.5
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1124
diff changeset
45 def is_cache_exception(e):
fd05b2dc86a4 Now it even works on Python < 2.5
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1124
diff changeset
46 args = e.args
fd05b2dc86a4 Now it even works on Python < 2.5
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1124
diff changeset
47 return not (len(args) != 1 or args[0] != 'CacheNeedsUpdate')
fd05b2dc86a4 Now it even works on Python < 2.5
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1124
diff changeset
48
1618
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
49
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
50 class ItemCache:
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
51 """ Cache some page item related data, as meta data or pagelist
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
52
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
53 We only cache this to RAM in request.cfg (this is the only kind of
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
54 server object we have), because it might be too big for pickling it
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
55 in and out.
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
56 """
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
57 def __init__(self, name):
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
58 """ Initialize ItemCache object.
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
59 @param name: name of the object, used for display in logging and
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
60 influences behaviour of refresh().
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
61 """
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
62 self.name = name
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
63 self.cache = {}
1836
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
64 self.log_pos = None # TODO: initialize this to EOF pos of log
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
65 # to avoid reading in the whole log on first request
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
66 self.requests = 0
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
67 self.hits = 0
1853
3ddf2193a16e reduced cache logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1836
diff changeset
68 self.loglevel = logging.NOTSET
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
69
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
70 def putItem(self, request, name, key, data):
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
71 """ Remembers some data for item name under a key.
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
72 @param request: currently unused
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
73 @param name: name of the item (page), unicode
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
74 @param key: used as secondary access key after name
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
75 @param data: the data item that should be remembered
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
76 """
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1639
diff changeset
77 d = self.cache.setdefault(name, {})
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1639
diff changeset
78 d[key] = data
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
79
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
80 def getItem(self, request, name, key):
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
81 """ Returns some item stored for item name under key.
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
82 @param request: the request object
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
83 @param name: name of the item (page), unicode
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
84 @param key: used as secondary access key after name
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
85 @return: the data or None, if there is no such name or key.
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
86 """
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
87 self.refresh(request)
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
88 try:
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
89 data = self.cache[name][key]
1626
189bbdd56620 ItemCache: minor code cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1624
diff changeset
90 self.hits += 1
189bbdd56620 ItemCache: minor code cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1624
diff changeset
91 hit_str = 'hit'
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
92 except KeyError:
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
93 data = None
1626
189bbdd56620 ItemCache: minor code cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1624
diff changeset
94 hit_str = 'miss'
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
95 self.requests += 1
1853
3ddf2193a16e reduced cache logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1836
diff changeset
96 logging.log(self.loglevel, "%s cache %s (h/r %2.1f%%) for %r %r" % (
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
97 self.name,
1622
7d199191cb1f use new item meta data cache for acls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1621
diff changeset
98 hit_str,
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
99 float(self.hits * 100) / self.requests,
1622
7d199191cb1f use new item meta data cache for acls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1621
diff changeset
100 name,
7d199191cb1f use new item meta data cache for acls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1621
diff changeset
101 key,
7d199191cb1f use new item meta data cache for acls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1621
diff changeset
102 ))
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
103 return data
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
104
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
105 def refresh(self, request):
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
106 """ Refresh the cache - if anything has changed in the wiki, we see it
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
107 in the edit-log and either delete cached data for the changed items
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
108 (for 'meta') or the complete cache ('pagelists').
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
109 @param request: the request object
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
110 """
4149
769850545997 Removed request.editlog
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3620
diff changeset
111 from MoinMoin.logfile import editlog
769850545997 Removed request.editlog
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3620
diff changeset
112 elog = editlog.EditLog(request)
1836
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
113 old_pos = self.log_pos
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
114 new_pos, items = elog.news(old_pos)
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
115 if items:
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
116 if self.name == 'meta':
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
117 for item in items:
1853
3ddf2193a16e reduced cache logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1836
diff changeset
118 logging.log(self.loglevel, "cache: removing %r" % item)
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
119 try:
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
120 del self.cache[item]
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
121 except:
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
122 pass
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
123 elif self.name == 'pagelists':
1853
3ddf2193a16e reduced cache logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1836
diff changeset
124 logging.log(self.loglevel, "cache: clearing pagelist cache")
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
125 self.cache = {}
1836
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
126 self.log_pos = new_pos # important to do this at the end -
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
127 # avoids threading race conditions
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
128
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
129
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
130 class Page(object):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
131 """ Page - Manage an (immutable) page associated with a WikiName.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
132 To change a page's content, use the PageEditor class.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
133 """
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
134 def __init__(self, request, page_name, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
135 """ Create page object.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
136
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
137 Note that this is a 'lean' operation, since the text for the page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
138 is loaded on demand. Thus, things like `Page(name).link_to()` are
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
139 efficient.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
140
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
141 @param page_name: WikiName of the page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
142 @keyword rev: number of older revision
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
143 @keyword formatter: formatter instance or mimetype str,
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
144 None or no kw arg will use default formatter
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
145 @keyword include_self: if 1, include current user (default: 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
146 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
147 self.request = request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
148 self.cfg = request.cfg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
149 self.page_name = page_name
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
150 self.rev = kw.get('rev', 0) # revision of this page
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
151 self.include_self = kw.get('include_self', 0)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
152
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
153 formatter = kw.get('formatter', None)
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
154 if isinstance(formatter, (str, unicode)): # mimetype given
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
155 mimetype = str(formatter)
622
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
156 self.formatter = None
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
157 self.output_mimetype = mimetype
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
158 self.default_formatter = mimetype == "text/html"
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
159 elif formatter is not None: # formatter instance given
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
160 self.formatter = formatter
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
161 self.default_formatter = 0
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
162 self.output_mimetype = "text/todo" # TODO where do we get this value from?
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
163 else:
622
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
164 self.formatter = None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
165 self.default_formatter = 1
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
166 self.output_mimetype = "text/html"
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
167
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
168 self.output_charset = config.charset # correct for wiki pages
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1564
diff changeset
169
1627
82e8a6a2eb1b ItemCache usage: fix handling of Missing[Home]Page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1626
diff changeset
170 self._text_filename_force = None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
171 self.hilite_re = None
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
172
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
173 self.__body = None # unicode page body == metadata + data
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
174 self.__body_modified = 0 # was __body modified in RAM so it differs from disk?
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
175 self.__meta = None # list of raw tuples of page metadata (currently: the # stuff at top of the page)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
176 self.__pi = None # dict of preprocessed page metadata (processing instructions)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
177 self.__data = None # unicode page data = body - metadata
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
178
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
179 self.reset()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
180
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
181 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
182 """ Reset page state """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
183 page_name = self.page_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
184 # page_name quoted for file system usage, needs to be reset to
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
185 # None when pagename changes
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
186
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
187 qpagename = wikiutil.quoteWikinameFS(page_name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
188 self.page_name_fs = qpagename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
189
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
190 # the normal and the underlay path used for this page
1618
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
191 normalpath = os.path.join(self.cfg.data_dir, "pages", qpagename)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
192 if not self.cfg.data_underlay_dir is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
193 underlaypath = os.path.join(self.cfg.data_underlay_dir, "pages", qpagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
194 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
195 underlaypath = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
196
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
197 # TUNING - remember some essential values
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
198
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
199 # does the page come from normal page storage (0) or from
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
200 # underlay dir (1) (can be used as index into following list)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
201 self._underlay = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
202
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
203 # path to normal / underlay page dir
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
204 self._pagepath = [normalpath, underlaypath]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
205
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
206 # now we define some properties to lazy load some attributes on first access:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
207
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
208 def get_body(self):
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
209 if self.__body is None:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
210 # try to open file
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
211 try:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
212 f = codecs.open(self._text_filename(), 'rb', config.charset)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
213 except IOError, er:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
214 import errno
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
215 if er.errno == errno.ENOENT:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
216 # just doesn't exist, return empty text (note that we
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
217 # never store empty pages, so this is detectable and also
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
218 # safe when passed to a function expecting a string)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
219 return ""
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
220 else:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
221 raise
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
222
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
223 # read file content and make sure it is closed properly
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
224 try:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
225 text = f.read()
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
226 text = self.decodeTextMimeType(text)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
227 self.__body = text
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
228 finally:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
229 f.close()
2057
c071cddde1e4 Added a cosmetic newline to test if push works.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2036
diff changeset
230 return self.__body
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
231
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
232 def set_body(self, newbody):
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
233 self.__body = newbody
1885
9e4aeac3abff Page: if we set a new body, we need to invalidate old meta and old data
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1882
diff changeset
234 self.__meta = None
9e4aeac3abff Page: if we set a new body, we need to invalidate old meta and old data
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1882
diff changeset
235 self.__data = None
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
236 body = property(fget=get_body, fset=set_body) # complete page text
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
237
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
238 def get_meta(self):
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
239 if self.__meta is None:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
240 self.__meta, self.__data = wikiutil.get_processing_instructions(self.body)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
241 return self.__meta
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
242 meta = property(fget=get_meta) # processing instructions, ACLs (upper part of page text)
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
243
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
244 def get_data(self):
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
245 if self.__data is None:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
246 self.__meta, self.__data = wikiutil.get_processing_instructions(self.body)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
247 return self.__data
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
248 data = property(fget=get_data) # content (lower part of page text)
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
249
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
250 def get_pi(self):
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
251 if self.__pi is None:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
252 self.__pi = self.parse_processing_instructions()
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
253 return self.__pi
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
254 pi = property(fget=get_pi) # processed meta stuff
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
255
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
256 def getlines(self):
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
257 """ Return a list of all lines in body.
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
258
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
259 @rtype: list
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
260 @return: list of strs body_lines
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
261 """
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
262 return self.body.split('\n')
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
263
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
264 def get_raw_body(self):
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
265 """ Load the raw markup from the page file.
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
266
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
267 @rtype: unicode
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
268 @return: raw page contents of this page, unicode
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
269 """
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
270 return self.body
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
271
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
272 def get_raw_body_str(self):
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
273 """ Returns the raw markup from the page file, as a string.
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
274
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
275 @rtype: str
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
276 @return: raw page contents of this page, utf-8-encoded
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
277 """
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
278 return self.body.encode("utf-8")
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
279
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
280 def set_raw_body(self, body, modified=0):
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
281 """ Set the raw body text (prevents loading from disk).
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
282
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
283 TODO: this should not be a public function, as Page is immutable.
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
284
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
285 @param body: raw body text
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
286 @param modified: 1 means that we internally modified the raw text and
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
287 that it is not in sync with the page file on disk. This is
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
288 used e.g. by PageEditor when previewing the page.
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
289 """
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
290 self.body = body
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
291 self.__body_modified = modified
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
292
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
293 def get_current_from_pagedir(self, pagedir):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
294 """ Get the current revision number from an arbitrary pagedir.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
295 Does not modify page object's state, uncached, direct disk access.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
296 @param pagedir: the pagedir with the 'current' file to read
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
297 @return: int currentrev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
298 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
299 revfilename = os.path.join(pagedir, 'current')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
300 try:
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1618
diff changeset
301 revfile = file(revfilename)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
302 revstr = revfile.read().strip()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
303 revfile.close()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
304 rev = int(revstr)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
305 except:
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
306 rev = 99999999 # XXX do some better error handling
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
307 return rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
308
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
309 def get_rev_dir(self, pagedir, rev=0):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
310 """ Get a revision of a page from an arbitrary pagedir.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
311
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
312 Does not modify page object's state, uncached, direct disk access.
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
313
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
314 @param pagedir: the path to the page storage area
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
315 @param rev: int revision to get (default is 0 and means the current
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
316 revision (in this case, the real revint is returned)
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
317 @return: (str path to file of the revision,
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
318 int realrevint,
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
319 bool exists)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
320 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
321 if rev == 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
322 rev = self.get_current_from_pagedir(pagedir)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
323
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
324 revstr = '%08d' % rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
325 pagefile = os.path.join(pagedir, 'revisions', revstr)
1681
fc03cd8ff0f3 avoid accessing invalid page revisions, tune caching code (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1675
diff changeset
326 if rev != 99999999:
fc03cd8ff0f3 avoid accessing invalid page revisions, tune caching code (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1675
diff changeset
327 exists = os.path.exists(pagefile)
fc03cd8ff0f3 avoid accessing invalid page revisions, tune caching code (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1675
diff changeset
328 if exists:
fc03cd8ff0f3 avoid accessing invalid page revisions, tune caching code (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1675
diff changeset
329 self._setRealPageName(pagedir)
fc03cd8ff0f3 avoid accessing invalid page revisions, tune caching code (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1675
diff changeset
330 else:
fc03cd8ff0f3 avoid accessing invalid page revisions, tune caching code (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1675
diff changeset
331 exists = False
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
332 return pagefile, rev, exists
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
333
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
334 def _setRealPageName(self, pagedir):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
335 """ Set page_name to the real case of page name
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
336
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
337 On case insensitive file system, "pagename" exists even if the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
338 real page name is "PageName" or "PAGENAME". This leads to
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1618
diff changeset
339 confusion in urls, links and logs.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
340 See MoinMoinBugs/MacHfsPlusCaseInsensitive
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
341
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
342 Correct the case of the page name. Elements created from the
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1618
diff changeset
343 page name in reset() are not updated because it's too messy, and
3085
fdb68a8f92da fix wrong pagename when creating new pages on Mac OS X (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3013
diff changeset
344 this fix seems to be enough for now.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
345
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
346 Problems to fix later:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
347
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
348 - ["helponnavigation"] link to HelpOnNavigation but not
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
349 considered as backlink.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
350
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
351 @param pagedir: the storage path to the page directory
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
352 """
3085
fdb68a8f92da fix wrong pagename when creating new pages on Mac OS X (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3013
diff changeset
353 if self._text_filename_force is None:
fdb68a8f92da fix wrong pagename when creating new pages on Mac OS X (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3013
diff changeset
354 # we only do this for normal pages, but not for the MissingPage,
fdb68a8f92da fix wrong pagename when creating new pages on Mac OS X (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3013
diff changeset
355 # because the code below is wrong in that case
fdb68a8f92da fix wrong pagename when creating new pages on Mac OS X (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3013
diff changeset
356 realPath = util.filesys.realPathCase(pagedir)
fdb68a8f92da fix wrong pagename when creating new pages on Mac OS X (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3013
diff changeset
357 if realPath is not None:
fdb68a8f92da fix wrong pagename when creating new pages on Mac OS X (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3013
diff changeset
358 realPath = wikiutil.unquoteWikiname(realPath)
fdb68a8f92da fix wrong pagename when creating new pages on Mac OS X (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3013
diff changeset
359 self.page_name = realPath[-len(self.page_name):]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
360
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
361 def get_rev(self, use_underlay=-1, rev=0):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
362 """ Get information about a revision.
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
363
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
364 filename, number, and (existance test) of this page and revision.
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
365
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
366 @param use_underlay: -1 == auto, 0 == normal, 1 == underlay
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
367 @param rev: int revision to get (default is 0 and means the current
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
368 revision (in this case, the real revint is returned)
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
369 @return: (str path to current revision of page,
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
370 int realrevint,
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
371 bool exists)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
372 """
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
373 def layername(underlay):
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
374 if underlay == -1:
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
375 return 'layer_auto'
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
376 elif underlay == 0:
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
377 return 'layer_normal'
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
378 else: # 1
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
379 return 'layer_underlay'
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
380
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
381 request = self.request
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
382 cache_name = self.page_name
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
383 cache_key = layername(use_underlay)
1627
82e8a6a2eb1b ItemCache usage: fix handling of Missing[Home]Page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1626
diff changeset
384 if self._text_filename_force is None:
82e8a6a2eb1b ItemCache usage: fix handling of Missing[Home]Page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1626
diff changeset
385 cache_data = request.cfg.cache.meta.getItem(request, cache_name, cache_key)
82e8a6a2eb1b ItemCache usage: fix handling of Missing[Home]Page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1626
diff changeset
386 if cache_data and (rev == 0 or rev == cache_data[1]):
82e8a6a2eb1b ItemCache usage: fix handling of Missing[Home]Page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1626
diff changeset
387 # we got the correct rev data from the cache
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1698
diff changeset
388 #logging.debug("got data from cache: %r %r %r" % cache_data)
1627
82e8a6a2eb1b ItemCache usage: fix handling of Missing[Home]Page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1626
diff changeset
389 return cache_data
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
390
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
391 # Figure out if we should use underlay or not, if needed.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
392 if use_underlay == -1:
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
393 underlay, pagedir = self.getPageStatus(check_create=0)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
394 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
395 underlay, pagedir = use_underlay, self._pagepath[use_underlay]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
396
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
397 # Find current revision, if automatic selection is requested.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
398 if rev == 0:
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
399 realrev = self.get_current_from_pagedir(pagedir)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
400 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
401 realrev = rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
402
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
403 data = self.get_rev_dir(pagedir, realrev)
1627
82e8a6a2eb1b ItemCache usage: fix handling of Missing[Home]Page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1626
diff changeset
404 if rev == 0 and self._text_filename_force is None:
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
405 # we only save the current rev to the cache
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
406 request.cfg.cache.meta.putItem(request, cache_name, cache_key, data)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
407
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
408 return data
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
409
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
410 def current_rev(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
411 """ Return number of current revision.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
412
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
413 This is the same as get_rev()[1].
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
414
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
415 @return: int revision
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
416 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
417 pagefile, rev, exists = self.get_rev()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
418 return rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
419
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
420 def get_real_rev(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
421 """ Returns the real revision number of this page.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
422 A rev==0 is translated to the current revision.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
423
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
424 @returns: revision number > 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
425 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
426 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
427 if self.rev == 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
428 return self.current_rev()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
429 return self.rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
430
1698
35ebda626b4b getPageBasePath: add default value for use_underlay and improve docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1693
diff changeset
431 def getPageBasePath(self, use_underlay=-1):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
432 """ Get full path to a page-specific storage area. `args` can
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
433 contain additional path components that are added to the base path.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
434
1698
35ebda626b4b getPageBasePath: add default value for use_underlay and improve docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1693
diff changeset
435 @param use_underlay: force using a specific pagedir, default -1
35ebda626b4b getPageBasePath: add default value for use_underlay and improve docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1693
diff changeset
436 -1 = automatically choose page dir
35ebda626b4b getPageBasePath: add default value for use_underlay and improve docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1693
diff changeset
437 1 = use underlay page dir
35ebda626b4b getPageBasePath: add default value for use_underlay and improve docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1693
diff changeset
438 0 = use standard page dir
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
439 @rtype: string
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
440 @return: int underlay,
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
441 str the full path to the storage area
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
442 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
443 standardpath, underlaypath = self._pagepath
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
444 if underlaypath is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
445 use_underlay = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
446
1618
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
447 if use_underlay == -1: # automatic
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
448 if self._underlay is None:
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
449 underlay, path = 0, standardpath
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
450 pagefile, rev, exists = self.get_rev(use_underlay=0)
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
451 if not exists:
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
452 pagefile, rev, exists = self.get_rev(use_underlay=1)
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
453 if exists:
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
454 underlay, path = 1, underlaypath
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
455 self._underlay = underlay
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
456 else:
1618
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
457 underlay = self._underlay
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
458 path = self._pagepath[underlay]
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
459 else: # normal or underlay
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1605
diff changeset
460 underlay, path = use_underlay, self._pagepath[use_underlay]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
461
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
462 return underlay, path
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
463
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
464 def getPageStatus(self, *args, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
465 """ Get full path to a page-specific storage area. `args` can
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
466 contain additional path components that are added to the base path.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
467
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
468 @param args: additional path components
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
469 @keyword use_underlay: force using a specific pagedir, default '-1'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
470 -1 = automatically choose page dir
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
471 1 = use underlay page dir
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
472 0 = use standard page dir
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
473 @keyword check_create: if true, ensures that the path requested really exists
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
474 (if it doesn't, create all directories automatically).
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
475 (default true)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
476 @keyword isfile: is the last component in args a filename? (default is false)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
477 @rtype: string
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
478 @return: (int underlay (1 if using underlay, 0 otherwise),
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
479 str the full path to the storage area )
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
480 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
481 check_create = kw.get('check_create', 1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
482 isfile = kw.get('isfile', 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
483 use_underlay = kw.get('use_underlay', -1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
484 underlay, path = self.getPageBasePath(use_underlay)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
485 fullpath = os.path.join(*((path, ) + args))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
486 if check_create:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
487 if isfile:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
488 dirname, filename = os.path.split(fullpath)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
489 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
490 dirname = fullpath
2930
dc0f45b10ae6 fix os.path.exists() vs. os.makedirs() race
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2845
diff changeset
491 try:
1428
8a89649ab5f0 remove util.filesys.make[dD]irs - not needed any more due to os.umask() use
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1419
diff changeset
492 os.makedirs(dirname)
2930
dc0f45b10ae6 fix os.path.exists() vs. os.makedirs() race
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2845
diff changeset
493 except OSError, err:
dc0f45b10ae6 fix os.path.exists() vs. os.makedirs() race
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2845
diff changeset
494 if not os.path.exists(dirname):
5635
244737a44ec8 fix exception raising
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5612
diff changeset
495 raise
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
496 return underlay, fullpath
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
497
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
498 def getPagePath(self, *args, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
499 """ Return path to the page storage area. """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
500 return self.getPageStatus(*args, **kw)[1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
501
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
502 def _text_filename(self, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
503 """ The name of the page file, possibly of an older page.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
504
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
505 @keyword rev: page revision, overriding self.rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
506 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
507 @return: complete filename (including path) to this page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
508 """
1627
82e8a6a2eb1b ItemCache usage: fix handling of Missing[Home]Page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1626
diff changeset
509 if self._text_filename_force is not None:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
510 return self._text_filename_force
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
511 rev = kw.get('rev', 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
512 if not rev and self.rev:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
513 rev = self.rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
514 fname, rev, exists = self.get_rev(-1, rev)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
515 return fname
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
516
3547
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
517 def editlog_entry(self):
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
518 """ Return the edit-log entry for this Page object (can be an old revision).
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
519 """
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
520 request = self.request
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
521 use_cache = self.rev == 0 # use the cache for current rev
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
522 if use_cache:
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
523 cache_name, cache_key = self.page_name, 'lastlog'
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
524 entry = request.cfg.cache.meta.getItem(request, cache_name, cache_key)
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
525 else:
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
526 entry = None
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
527 if entry is None:
1631
9f02d3c64f48 use ItemCache for page local edit-log, speedup InterWikiMap page handling if page does not exist
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1629
diff changeset
528 from MoinMoin.logfile import editlog
3548
419335c7d8ad optimize Page.editlog_entry(): read log in reverse direction, move str/int conversion outside the loop
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3547
diff changeset
529 wanted_rev = "%08d" % self.get_real_rev()
419335c7d8ad optimize Page.editlog_entry(): read log in reverse direction, move str/int conversion outside the loop
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3547
diff changeset
530 edit_log = editlog.EditLog(request, rootpagename=self.page_name)
419335c7d8ad optimize Page.editlog_entry(): read log in reverse direction, move str/int conversion outside the loop
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3547
diff changeset
531 for entry in edit_log.reverse():
419335c7d8ad optimize Page.editlog_entry(): read log in reverse direction, move str/int conversion outside the loop
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3547
diff changeset
532 if entry.rev == wanted_rev:
3547
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
533 break
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
534 else:
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
535 entry = () # don't use None
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
536 if use_cache:
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
537 request.cfg.cache.meta.putItem(request, cache_name, cache_key, entry)
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
538 return entry
3546
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
539
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
540 def edit_info(self):
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
541 """ Return timestamp/editor info for this Page object (can be an old revision).
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
542
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
543 Note: if you ask about a deleted revision, it will report timestamp and editor
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
544 for the delete action (in the edit-log, this is just a SAVE).
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
545
637
35f0f8584a57 move wikirpc.py to xmlrpc/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 635
diff changeset
546 This is used by MoinMoin/xmlrpc/__init__.py.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
547
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
548 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
549 @return: timestamp and editor information
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
550 """
3546
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
551 line = self.editlog_entry()
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
552 if line:
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
553 editordata = line.getInterwikiEditorData(self.request)
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
554 if editordata[0] == 'interwiki':
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
555 editor = "%s:%s" % editordata[1]
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
556 else:
4470
ea2aa935fbde cfg.log_remote_addr (default: True) controls whether moin logs remote's IP/hostname to edit-log and event-log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3620
diff changeset
557 editor = editordata[1] # ip or email or anon
3546
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
558 result = {
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
559 'timestamp': line.ed_time_usecs,
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
560 'editor': editor,
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
561 }
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
562 del line
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
563 else:
3550
65eac5f65a11 Page.edit_info: better return empty dict than None when no edit-log entry is found
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3549
diff changeset
564 result = {}
3546
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
565 return result
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
566
3546
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
567 def last_edit(self, request):
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
568 # XXX usage of last_edit is DEPRECATED - use edit_info()
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
569 if not self.exists(): # XXX doesn't make much sense, but still kept
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
570 return None # XXX here until we remove last_edit()
c9494979fe7a xmlrpc getPageInfoVersion fixed / Page.last_edit() fixed and renamed to edit_info(). Works correctly now for current revision and supports old revisions.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3518
diff changeset
571 return self.edit_info()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
572
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
573 def lastEditInfo(self, request=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
574 """ Return the last edit info.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
575
3547
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
576 Note: if you ask about a deleted revision, it will report timestamp and editor
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
577 for the delete action (in the edit-log, this is just a SAVE).
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
578
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
579 @param request: the request object (DEPRECATED, unused)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
580 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
581 @return: timestamp and editor information
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
582 """
3547
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
583 log = self.editlog_entry()
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
584 if log:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
585 request = self.request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
586 editor = log.getEditor(request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
587 time = wikiutil.version2timestamp(log.ed_time_usecs)
3547
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
588 time = request.user.getFormattedDateTime(time) # Use user time format
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
589 result = {'editor': editor, 'time': time}
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
590 del log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
591 else:
3547
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
592 result = {}
889b37b6441c get rid of broken Page._last_edited(), use Page.editlog_entry() from now on
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3546
diff changeset
593 return result
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
594
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
595 def isWritable(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
596 """ Can this page be changed?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
597
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
598 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
599 @return: true, if this page is writable or does not exist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
600 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
601 return os.access(self._text_filename(), os.W_OK) or not self.exists()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
602
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
603 def isUnderlayPage(self, includeDeleted=True):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
604 """ Does this page live in the underlay dir?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
605
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
606 Return true even if the data dir has a copy of this page. To
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
607 check for underlay only page, use ifUnderlayPage() and not
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
608 isStandardPage()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
609
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
610 @param includeDeleted: include deleted pages
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
611 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
612 @return: true if page lives in the underlay dir
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
613 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
614 return self.exists(domain='underlay', includeDeleted=includeDeleted)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
615
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
616 def isStandardPage(self, includeDeleted=True):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
617 """ Does this page live in the data dir?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
618
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
619 Return true even if this is a copy of an underlay page. To check
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
620 for data only page, use isStandardPage() and not isUnderlayPage().
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
621
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
622 @param includeDeleted: include deleted pages
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
623 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
624 @return: true if page lives in the data dir
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
625 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
626 return self.exists(domain='standard', includeDeleted=includeDeleted)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
627
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
628 def exists(self, rev=0, domain=None, includeDeleted=False):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
629 """ Does this page exist?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
630
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
631 This is the lower level method for checking page existence. Use
1626
189bbdd56620 ItemCache: minor code cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1624
diff changeset
632 the higher level methods isUnderlayPage and isStandardPage for
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
633 cleaner code.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
634
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
635 @param rev: revision to look for. Default: check current
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
636 @param domain: where to look for the page. Default: look in all,
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
637 available values: 'underlay', 'standard'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
638 @param includeDeleted: ignore page state, just check its pagedir
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
639 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
640 @return: true, if page exists
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
641 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
642 # Edge cases
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
643 if domain == 'underlay' and not self.request.cfg.data_underlay_dir:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
644 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
645
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
646 if includeDeleted:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
647 # Look for page directory, ignore page state
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
648 if domain is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
649 checklist = [0, 1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
650 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
651 checklist = [domain == 'underlay']
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
652 for use_underlay in checklist:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
653 pagedir = self.getPagePath(use_underlay=use_underlay, check_create=0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
654 if os.path.exists(pagedir):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
655 return True
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
656 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
657 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
658 # Look for non-deleted pages only, using get_rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
659 if not rev and self.rev:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
660 rev = self.rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
661
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
662 if domain is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
663 use_underlay = -1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
664 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
665 use_underlay = domain == 'underlay'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
666 d, d, exists = self.get_rev(use_underlay, rev)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
667 return exists
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
668
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
669 def size(self, rev=0):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
670 """ Get Page size.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
671
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
672 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
673 @return: page size, 0 for non-existent pages.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
674 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
675 if rev == self.rev: # same revision as self
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
676 if self.__body is not None:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
677 return len(self.__body)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
678
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
679 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
680 return os.path.getsize(self._text_filename(rev=rev))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
681 except EnvironmentError, e:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
682 import errno
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
683 if e.errno == errno.ENOENT:
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
684 return 0
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
685 raise
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
686
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
687 def mtime_usecs(self):
3549
56b476878a1c Page.mtime_usecs(): reuse .editlog_entry() code and cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3548
diff changeset
688 """ Get modification timestamp of this page (from edit-log, can be for an old revision).
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
689
3549
56b476878a1c Page.mtime_usecs(): reuse .editlog_entry() code and cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3548
diff changeset
690 @rtype: int
56b476878a1c Page.mtime_usecs(): reuse .editlog_entry() code and cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3548
diff changeset
691 @return: mtime of page (or 0 if page / edit-log entry does not exist)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
692 """
3549
56b476878a1c Page.mtime_usecs(): reuse .editlog_entry() code and cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3548
diff changeset
693 entry = self.editlog_entry()
56b476878a1c Page.mtime_usecs(): reuse .editlog_entry() code and cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3548
diff changeset
694 return entry and entry.ed_time_usecs or 0
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
695
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
696 def mtime_printable(self, request):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
697 """ Get printable (as per user's preferences) modification timestamp of this page.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
698
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
699 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
700 @return: formatted string with mtime of page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
701 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
702 t = self.mtime_usecs()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
703 if not t:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
704 result = "0" # TODO: i18n, "Ever", "Beginning of time"...?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
705 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
706 result = request.user.getFormattedDateTime(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
707 wikiutil.version2timestamp(t))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
708 return result
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
709
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
710 def split_title(self, force=0):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
711 """ Return a string with the page name split by spaces, if the user wants that.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
712
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
713 @param force: if != 0, then force splitting the page_name
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
714 @rtype: unicode
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
715 @return: pagename of this page, splitted into space separated words
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
716 """
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
717 request = self.request
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
718 if not force and not request.user.wikiname_add_spaces:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
719 return self.page_name
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
720
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
721 # look for the end of words and the start of a new word,
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
722 # and insert a space there
2250
07fdbda38be2 move split_regex to config (so it is compiled only once)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2223
diff changeset
723 splitted = config.split_regex.sub(r'\1 \2', self.page_name)
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
724 return splitted
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
725
3234
a739558ca3dc Page.url() default changed to relative=False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3175
diff changeset
726 def url(self, request, querystr=None, anchor=None, relative=False, **kw):
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1809
diff changeset
727 """ Return complete URL for this page, including scriptname.
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1809
diff changeset
728 The URL is NOT escaped, if you write it to HTML, use wikiutil.escape
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1809
diff changeset
729 (at least if you have a querystr, to escape the & chars).
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
730
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
731 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
732 @param querystr: the query string to add after a "?" after the url
102
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
733 (str or dict, see wikiutil.makeQueryString)
1339
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
734 @param anchor: if specified, make a link to this anchor
3234
a739558ca3dc Page.url() default changed to relative=False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3175
diff changeset
735 @param relative: create a relative link (default: False), note that this
a739558ca3dc Page.url() default changed to relative=False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3175
diff changeset
736 changed in 1.7, in 1.6, the default was True.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
737 @rtype: str
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
738 @return: complete url of this page, including scriptname
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
739 """
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1809
diff changeset
740 assert(isinstance(anchor, (type(None), str, unicode)))
1339
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
741 # Create url, excluding scriptname
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
742 url = wikiutil.quoteWikinameURL(self.page_name)
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
743 if querystr:
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
744 if isinstance(querystr, dict):
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
745 action = querystr.get('action', None)
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
746 else:
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
747 action = None # we don't support getting the action out of a str
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
748
102
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
749 querystr = wikiutil.makeQueryString(querystr)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
750
1339
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
751 # make action URLs denyable by robots.txt:
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
752 if action is not None and request.cfg.url_prefix_action is not None:
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
753 url = "%s/%s/%s" % (request.cfg.url_prefix_action, action, url)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
754 url = '%s?%s' % (url, querystr)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
755
4235
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4183
diff changeset
756 if not relative:
4242
f61dcab20a3e Reverted use of Href in Page.url (breaks querystrings)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4237
diff changeset
757 url = '%s/%s' % (request.script_root, url)
4235
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4183
diff changeset
758
1339
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
759 # Add anchor
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
760 if anchor:
4560
050428d1c044 Fix processing of anchors (fragment identifiers), see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4497
diff changeset
761 fmt = getattr(self, 'formatter', request.html_formatter)
050428d1c044 Fix processing of anchors (fragment identifiers), see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4497
diff changeset
762 if fmt:
050428d1c044 Fix processing of anchors (fragment identifiers), see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4497
diff changeset
763 anchor = fmt.sanitize_to_id(anchor)
050428d1c044 Fix processing of anchors (fragment identifiers), see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4497
diff changeset
764 url = "%s#%s" % (url, anchor)
1339
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1311
diff changeset
765
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
766 return url
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
767
1341
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
768 def link_to_raw(self, request, text, querystr=None, anchor=None, **kw):
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
769 """ core functionality of link_to, without the magic """
3235
4c0121050056 fix for previous changeset: this place really needs relative=True
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3234
diff changeset
770 url = self.url(request, querystr, anchor=anchor, relative=True) # scriptName is added by link_tag
1341
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
771 # escaping is done by link_tag -> formatter.url -> ._open()
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
772 link = wikiutil.link_tag(request, url, text,
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
773 formatter=getattr(self, 'formatter', None), **kw)
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
774 return link
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
775
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
776 def link_to(self, request, text=None, querystr=None, anchor=None, **kw):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
777 """ Return HTML markup that links to this page.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
778
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
779 See wikiutil.link_tag() for possible keyword parameters.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
780
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
781 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
782 @param text: inner text of the link - it gets automatically escaped
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
783 @param querystr: the query string to add after a "?" after the url
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
784 @param anchor: if specified, make a link to this anchor
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
785 @keyword on: opening/closing tag only
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
786 @keyword attachment_indicator: if 1, add attachment indicator after link tag
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
787 @keyword css_class: css class to use
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
788 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
789 @return: formatted link
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
790 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
791 if not text:
1776
fc75423e26a8 remove unneeded request param from page.split_title()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1756
diff changeset
792 text = self.split_title()
1341
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
793 text = wikiutil.escape(text)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
794
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
795 # Add css class for non existing page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
796 if not self.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
797 kw['css_class'] = 'nonexistent'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
798
1964
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
799 attachment_indicator = kw.get('attachment_indicator')
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
800 if attachment_indicator is None:
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
801 attachment_indicator = 0 # default is off
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
802 else:
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
803 del kw['attachment_indicator'] # avoid having this as <a> tag attribute
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
804
1341
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
805 link = self.link_to_raw(request, text, querystr, anchor, **kw)
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
806
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
807 # Create a link to attachments if any exist
1964
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
808 if attachment_indicator:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
809 from MoinMoin.action import AttachFile
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
810 link += AttachFile.getIndicator(request, self.page_name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
811
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
812 return link
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
813
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
814 def getSubscribers(self, request, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
815 """ Get all subscribers of this page.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
816
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
817 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
818 @keyword include_self: if 1, include current user (default: 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
819 @keyword return_users: if 1, return user instances (default: 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
820 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
821 @return: lists of subscribed email addresses in a dict by language key
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
822 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
823 include_self = kw.get('include_self', self.include_self)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
824 return_users = kw.get('return_users', 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
825
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
826 # extract categories of this page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
827 pageList = self.getCategories(request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
828
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
829 # add current page name for list matching
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
830 pageList.append(self.page_name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
831
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
832 if self.cfg.SecurityPolicy:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
833 UserPerms = self.cfg.SecurityPolicy
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
834 else:
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
835 from MoinMoin.security import Default as UserPerms
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
836
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
837 # get email addresses of the all wiki user which have a profile stored;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
838 # add the address only if the user has subscribed to the page and
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
839 # the user is not the current editor
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
840 userlist = user.getUserList(request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
841 subscriber_list = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
842 for uid in userlist:
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
843 if uid == request.user.id and not include_self:
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
844 continue # no self notification
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
845 subscriber = user.User(request, uid)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
846
3300
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
847 # The following tests should be ordered in order of
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
848 # decreasing computation complexity, in particular
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
849 # the permissions check may be expensive; see the bug
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
850 # MoinMoinBugs/GetSubscribersPerformanceProblem
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
851
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
852 # This is a bit wrong if return_users=1 (which implies that the caller will process
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
853 # user attributes and may, for example choose to send an SMS)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
854 # So it _should_ be "not (subscriber.email and return_users)" but that breaks at the moment.
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
855 if not subscriber.email:
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
856 continue # skip empty email addresses
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
857
3300
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
858 # skip people not subscribed
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
859 if not subscriber.isSubscribedTo(pageList):
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
860 continue
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
861
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
862 # skip people who can't read the page
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
863 if not UserPerms(subscriber).read(self.page_name):
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
864 continue
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
865
3300
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
866 # add the user to the list
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
867 lang = subscriber.language or request.cfg.language_default
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
868 if not lang in subscriber_list:
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
869 subscriber_list[lang] = []
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
870 if return_users:
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
871 subscriber_list[lang].append(subscriber)
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
872 else:
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
873 subscriber_list[lang].append(subscriber.email)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
874
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
875 return subscriber_list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
876
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
877 def parse_processing_instructions(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
878 """ Parse page text and extract processing instructions,
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
879 return a dict of PIs and the non-PI rest of the body.
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
880 """
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
881 from MoinMoin import i18n
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
882 from MoinMoin import security
2130
283530fa9c52 avoid acl KeyError for xml/xslt pages (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2057
diff changeset
883 request = self.request
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
884 pi = {} # we collect the processing instructions here
2130
283530fa9c52 avoid acl KeyError for xml/xslt pages (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2057
diff changeset
885
2223
eec3c7b6a686 make sure pi['language'] is set, even for xslt pages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2215
diff changeset
886 # default language from cfg
eec3c7b6a686 make sure pi['language'] is set, even for xslt pages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2215
diff changeset
887 pi['language'] = self.cfg.language_default or "en"
eec3c7b6a686 make sure pi['language'] is set, even for xslt pages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2215
diff changeset
888
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
889 body = self.body
2130
283530fa9c52 avoid acl KeyError for xml/xslt pages (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2057
diff changeset
890 # TODO: remove this hack once we have separate metadata and can use mimetype there
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
891 if body.startswith('<?xml'): # check for XML content
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
892 pi['lines'] = 0
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
893 pi['format'] = "xslt"
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
894 pi['formatargs'] = ''
2130
283530fa9c52 avoid acl KeyError for xml/xslt pages (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2057
diff changeset
895 pi['acl'] = security.AccessControlList(request.cfg, []) # avoid KeyError on acl check
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
896 return pi
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
897
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
898 meta = self.meta
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
899
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
900 # default is wiki markup
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
901 pi['format'] = self.cfg.default_markup or "wiki"
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
902 pi['formatargs'] = ''
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
903 pi['lines'] = len(meta)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
904 acl = []
2223
eec3c7b6a686 make sure pi['language'] is set, even for xslt pages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2215
diff changeset
905
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
906 for verb, args in meta:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
907 if verb == "format": # markup format
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
908 format, formatargs = (args + ' ').split(' ', 1)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
909 pi['format'] = format.lower()
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
910 pi['formatargs'] = formatargs.strip()
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
911
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
912 elif verb == "acl":
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
913 acl.append(args)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
914
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
915 elif verb == "language":
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
916 # Page language. Check if args is a known moin language
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
917 if args in i18n.wikiLanguages():
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
918 pi['language'] = args
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
919
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
920 elif verb == "refresh":
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
921 if self.cfg.refresh:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
922 try:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
923 mindelay, targetallowed = self.cfg.refresh
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
924 args = args.split()
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
925 if len(args) >= 1:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
926 delay = max(int(args[0]), mindelay)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
927 if len(args) >= 2:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
928 target = args[1]
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
929 else:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
930 target = self.page_name
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
931 if '://' in target:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
932 if targetallowed == 'internal':
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
933 raise ValueError
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
934 elif targetallowed == 'external':
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
935 url = target
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
936 else:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
937 url = Page(request, target).url(request)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
938 pi['refresh'] = (delay, url)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
939 except (ValueError, ):
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
940 pass
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
941
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
942 elif verb == "redirect":
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
943 pi['redirect'] = args
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
944
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
945 elif verb == "deprecated":
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
946 pi['deprecated'] = True
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
947
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
948 elif verb == "openiduser":
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
949 if request.cfg.openid_server_enable_user:
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
950 pi['openid.user'] = args
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
951
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
952 elif verb == "pragma":
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
953 try:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
954 key, val = args.split(' ', 1)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
955 except (ValueError, TypeError):
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
956 pass
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
957 else:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
958 request.setPragma(key, val)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
959
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
960 pi['acl'] = security.AccessControlList(request.cfg, acl)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
961 return pi
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
962
4959
18474c316dd7 mimetype support for Page.send_raw() and "raw" action (thanks to John Marshall for the patch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4899
diff changeset
963 def send_raw(self, content_disposition=None, mimetype=None):
1874
c4eb073a9cca refactor Save, merge save_raw into send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
964 """ Output the raw page data (action=raw).
c4eb073a9cca refactor Save, merge save_raw into send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
965 With no content_disposition, the browser usually just displays the
c4eb073a9cca refactor Save, merge save_raw into send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
966 data on the screen, with content_disposition='attachment', it will
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
967 offer a dialogue to save it to disk (used by Save action).
4959
18474c316dd7 mimetype support for Page.send_raw() and "raw" action (thanks to John Marshall for the patch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4899
diff changeset
968 Supplied mimetype overrides default text/plain.
1874
c4eb073a9cca refactor Save, merge save_raw into send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
969 """
678
48787c662e1a add 404 handling and cache headers for action=raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 664
diff changeset
970 request = self.request
4959
18474c316dd7 mimetype support for Page.send_raw() and "raw" action (thanks to John Marshall for the patch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4899
diff changeset
971 request.mimetype = mimetype or 'text/plain'
678
48787c662e1a add 404 handling and cache headers for action=raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 664
diff changeset
972 if self.exists():
943
274b021f26b1 remove some unused code from send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 941
diff changeset
973 # use the correct last-modified value from the on-disk file
274b021f26b1 remove some unused code from send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 941
diff changeset
974 # to ensure cacheability where supported. Because we are sending
274b021f26b1 remove some unused code from send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 941
diff changeset
975 # RAW (file) content, the file mtime is correct as Last-Modified header.
4183
fc20a076aad0 Accomodate for consolidation of Request/Response
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4177
diff changeset
976 request.status_code = 200
fc20a076aad0 Accomodate for consolidation of Request/Response
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4177
diff changeset
977 request.last_modified = os.path.getmtime(self._text_filename())
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
978 text = self.encodeTextMimeType(self.body)
5591
1dff6cfdcf90 http headers: for most cases, do not use .add, but .__setitem__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5390
diff changeset
979 #request.headers['Content-Length'] = len(text) # XXX WRONG! text is unicode obj, but we send utf-8!
1874
c4eb073a9cca refactor Save, merge save_raw into send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
980 if content_disposition:
2845
74c29582f7a1 send_raw: encode filename in utf-8, the same way as AttachFile code does it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2800
diff changeset
981 # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs
74c29582f7a1 send_raw: encode filename in utf-8, the same way as AttachFile code does it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2800
diff changeset
982 # There is no solution that is compatible to IE except stripping non-ascii chars
74c29582f7a1 send_raw: encode filename in utf-8, the same way as AttachFile code does it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2800
diff changeset
983 filename_enc = "%s.txt" % self.page_name.encode(config.charset)
4177
632696c3c78d Replaced calls to setHttpHeader
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4176
diff changeset
984 dispo_string = '%s; filename="%s"' % (content_disposition, filename_enc)
5591
1dff6cfdcf90 http headers: for most cases, do not use .add, but .__setitem__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5390
diff changeset
985 request.headers['Content-Disposition'] = dispo_string
678
48787c662e1a add 404 handling and cache headers for action=raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 664
diff changeset
986 else:
4183
fc20a076aad0 Accomodate for consolidation of Request/Response
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4177
diff changeset
987 request.status_code = 404
1069
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
988 text = u"Page %s not found." % self.page_name
457
f423a8496ae3 moved action=raw implementation to Page object
Thomas Waldmann <tw@waldmann-edv.de>
parents: 413
diff changeset
989
1069
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
990 request.write(text)
457
f423a8496ae3 moved action=raw implementation to Page object
Thomas Waldmann <tw@waldmann-edv.de>
parents: 413
diff changeset
991
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2930
diff changeset
992 def send_page(self, **keywords):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
993 """ Output the formatted page.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
994
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
995 TODO: "kill send_page(), quick" (since 2002 :)
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
996
1070
054a3d3d8dfe fix http headers for edit, RenamePage, DeletePage action, raise exception when http_headers is called multiple times
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1069
diff changeset
997 @keyword content_only: if 1, omit http headers, page header and footer
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
998 @keyword content_id: set the id of the enclosing div
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
999 @keyword count_hit: if 1, add an event to the log
3296
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1000 @keyword send_special: if True, this is a special page send
335
e574cc401e89 fixed MoinMoinBugs/IncorrectlyPlacedFootnote. All footnotes are now shown at the very bottom. There is a continuing numbering of all footnotes including the ones on included pages
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 286
diff changeset
1001 @keyword omit_footnotes: if True, do not send footnotes (used by include macro)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1002 """
1777
ed44b93599b5 remove unneeded request param from page.send_page()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1776
diff changeset
1003 request = self.request
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1004 _ = request.getText
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1005 request.clock.start('send_page')
1675
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1006 emit_headers = keywords.get('emit_headers', 1)
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1007 content_only = keywords.get('content_only', 0)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1008 omit_footnotes = keywords.get('omit_footnotes', 0)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1009 content_id = keywords.get('content_id', 'content')
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1010 do_cache = keywords.get('do_cache', 1)
3296
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1011 send_special = keywords.get('send_special', False)
1875
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1874
diff changeset
1012 print_mode = keywords.get('print_mode', 0)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1013 if print_mode:
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4242
diff changeset
1014 media = request.values.get('media', 'print')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1015 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1016 media = 'screen'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1017 self.hilite_re = (keywords.get('hilite_re') or
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4242
diff changeset
1018 request.values.get('highlight'))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1019
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1020 # count hit?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1021 if keywords.get('count_hit', 0):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1022 eventlog.EventLog(request).add(request, 'VIEWPAGE', {'pagename': self.page_name})
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1023
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1024 # load the text
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1025 body = self.data
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1026 pi = self.pi
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1027
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1028 if 'redirect' in pi and not (
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4242
diff changeset
1029 'action' in request.values or 'redirect' in request.values or content_only):
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1030 # redirect to another page
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1031 # note that by including "action=show", we prevent endless looping
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1032 # (see code in "request") or any cascaded redirection
4497
6beaf3e083c6 #redirect processing instruction: fix handling of anchors, simplify code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4470
diff changeset
1033 pagename, anchor = wikiutil.split_anchor(pi['redirect'])
6beaf3e083c6 #redirect processing instruction: fix handling of anchors, simplify code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4470
diff changeset
1034 redirect_url = Page(request, pagename).url(request,
6beaf3e083c6 #redirect processing instruction: fix handling of anchors, simplify code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4470
diff changeset
1035 querystr={'action': 'show', 'redirect': self.page_name, },
6beaf3e083c6 #redirect processing instruction: fix handling of anchors, simplify code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4470
diff changeset
1036 anchor=anchor)
5177
84c05e657b47 http_redirect: use code=<int> instead of status=<str> to make api in 1.8 same as in 1.9 / werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5175
diff changeset
1037 request.http_redirect(redirect_url, code=301)
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1038 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1039
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
1040 # if necessary, load the formatter
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1041 if self.default_formatter:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1042 from MoinMoin.formatter.text_html import Formatter
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1043 self.formatter = Formatter(request, store_pagelinks=1)
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
1044 elif not self.formatter:
1520
563bfe02b04f Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1428
diff changeset
1045 Formatter = wikiutil.searchAndImportPlugin(request.cfg, "formatter", self.output_mimetype)
563bfe02b04f Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1428
diff changeset
1046 self.formatter = Formatter(request)
1531
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1047
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1048 # save formatter
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1049 no_formatter = object()
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1050 old_formatter = getattr(request, "formatter", no_formatter)
622
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
1051 request.formatter = self.formatter
1531
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1052
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1053 self.formatter.setPage(self)
620
cb7deb83447c introduce mimetype arg for show action, keep format action as compat. stub
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
1054 if self.hilite_re:
3285
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
1055 try:
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
1056 self.formatter.set_highlight_re(self.hilite_re)
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
1057 except re.error, err:
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
1058 request.theme.add_msg(_('Invalid highlighting regular expression "%(regex)s": %(error)s') % {
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 3620
diff changeset
1059 'regex': wikiutil.escape(self.hilite_re),
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 3620
diff changeset
1060 'error': wikiutil.escape(str(err)),
3285
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
1061 }, "warning")
3410
81b8a5bb8711 send_page sucks. fix bug with invalid highlight REs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3394
diff changeset
1062 self.hilite_re = None
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1564
diff changeset
1063
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1064 if 'deprecated' in pi:
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1065 # deprecated page, append last backup version to current contents
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1066 # (which should be a short reason why the page is deprecated)
4755
e50adbb534d8 fixed grammar
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4746
diff changeset
1067 request.theme.add_msg(_('The backed up content of this page is deprecated and will rank lower in search results!'), "warning")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1068
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1069 revisions = self.getRevList()
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1070 if len(revisions) >= 2: # XXX shouldn't that be ever the case!? Looks like not.
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1071 oldpage = Page(request, self.page_name, rev=revisions[1])
5390
cb4eff3da604 Page.py: fixed adding of page contents (only page data added now, without metadata)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5384
diff changeset
1072 body += oldpage.get_data()
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1073 del oldpage
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1074
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1075 lang = self.pi.get('language', request.cfg.language_default)
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1076 request.setContentLanguage(lang)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1077
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
1078 # start document output
1069
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
1079 page_exists = self.exists()
1070
054a3d3d8dfe fix http headers for edit, RenamePage, DeletePage action, raise exception when http_headers is called multiple times
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1069
diff changeset
1080 if not content_only:
1675
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1081 if emit_headers:
4183
fc20a076aad0 Accomodate for consolidation of Request/Response
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4177
diff changeset
1082 request.content_type = "%s; charset=%s" % (self.output_mimetype, self.output_charset)
1675
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1083 if page_exists:
3297
d563a49e0054 give 403 status for permission denied pages rather than 200
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3296
diff changeset
1084 if not request.user.may.read(self.page_name):
4183
fc20a076aad0 Accomodate for consolidation of Request/Response
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4177
diff changeset
1085 request.status_code = 403
3297
d563a49e0054 give 403 status for permission denied pages rather than 200
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3296
diff changeset
1086 else:
4183
fc20a076aad0 Accomodate for consolidation of Request/Response
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4177
diff changeset
1087 request.status_code = 200
1675
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1088 if not request.cacheable:
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1089 # use "nocache" headers if we're using a method that is not simply "display"
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1090 request.disableHttpCaching(level=2)
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1091 elif request.user.valid:
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1092 # use nocache headers if a user is logged in (which triggers personalisation features)
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1093 request.disableHttpCaching(level=1)
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1094 else:
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
1095 # TODO: we need to know if a page generates dynamic content -
1675
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1096 # if it does, we must not use the page file mtime as last modified value
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
1097 # The following code is commented because it is incorrect for dynamic pages:
1675
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1098 #lastmod = os.path.getmtime(self._text_filename())
5591
1dff6cfdcf90 http headers: for most cases, do not use .add, but .__setitem__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5390
diff changeset
1099 #request.headers['Last-Modified'] = util.timefuncs.formathttpdate(lastmod)
1675
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1100 pass
1070
054a3d3d8dfe fix http headers for edit, RenamePage, DeletePage action, raise exception when http_headers is called multiple times
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1069
diff changeset
1101 else:
4183
fc20a076aad0 Accomodate for consolidation of Request/Response
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4177
diff changeset
1102 request.status_code = 404
1069
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
1103
3013
6238e1b2fd7f do not send any 404 content to bots (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3009
diff changeset
1104 if not page_exists and self.request.isSpiderAgent:
6238e1b2fd7f do not send any 404 content to bots (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3009
diff changeset
1105 # don't send any 404 content to bots
6238e1b2fd7f do not send any 404 content to bots (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3009
diff changeset
1106 return
6238e1b2fd7f do not send any 404 content to bots (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3009
diff changeset
1107
1675
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1108 request.write(self.formatter.startDocument(self.page_name))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1109
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1110 # send the page header
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1111 if self.default_formatter:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1112 if self.rev:
3154
c9ff5a31b5cd fix some Page object theme.msg_add() calls
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3144
diff changeset
1113 request.theme.add_msg("<strong>%s</strong><br>" % (
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1114 _('Revision %(rev)d as of %(date)s') % {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1115 'rev': self.rev,
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 3620
diff changeset
1116 'date': wikiutil.escape(self.mtime_printable(request))
3154
c9ff5a31b5cd fix some Page object theme.msg_add() calls
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3144
diff changeset
1117 }), "info")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1118
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1119 # This redirect message is very annoying.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1120 # Less annoying now without the warning sign.
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4242
diff changeset
1121 if 'redirect' in request.values:
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4242
diff changeset
1122 redir = request.values['redirect']
3154
c9ff5a31b5cd fix some Page object theme.msg_add() calls
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3144
diff changeset
1123 request.theme.add_msg('<strong>%s</strong><br>' % (
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1124 _('Redirected from page "%(page)s"') % {'page':
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2930
diff changeset
1125 wikiutil.link_tag(request, wikiutil.quoteWikinameURL(redir) + "?action=show", self.formatter.text(redir))}), "info")
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1126 if 'redirect' in pi:
3154
c9ff5a31b5cd fix some Page object theme.msg_add() calls
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3144
diff changeset
1127 request.theme.add_msg('<strong>%s</strong><br>' % (
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2930
diff changeset
1128 _('This page redirects to page "%(page)s"') % {'page': wikiutil.escape(pi['redirect'])}), "info")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1129
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1130 # Page trail
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1131 trail = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1132 if not print_mode:
1956
477760dd8487 speedup addTrail by passing existing page object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
1133 request.user.addTrail(self)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1134 trail = request.user.getTrail()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1135
1776
fc75423e26a8 remove unneeded request param from page.split_title()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1756
diff changeset
1136 title = self.split_title()
1354
26949e36ca0b move code for title_link to theme, better escape warning
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1341
diff changeset
1137
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1138 html_head = ''
3394
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1139 if request.cfg.openid_server_enabled:
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1140 openid_username = self.page_name
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1141 userid = user.getUserId(request, openid_username)
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1142
3394
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1143 if userid is None and 'openid.user' in self.pi:
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1144 openid_username = self.pi['openid.user']
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1145 userid = user.getUserId(request, openid_username)
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1146
4815
d761238f67f9 Groups2009: OpenID related code was refactored to use groups instead of dicts.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4602
diff changeset
1147 openid_group_name = request.cfg.openid_server_restricted_users_group
5384
ff8bda185098 openid server: fix TypeError
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5178
diff changeset
1148 if userid is not None and (
ff8bda185098 openid server: fix TypeError
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5178
diff changeset
1149 not openid_group_name or (
ff8bda185098 openid server: fix TypeError
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5178
diff changeset
1150 openid_group_name in request.groups and
ff8bda185098 openid server: fix TypeError
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5178
diff changeset
1151 openid_username in request.groups[openid_group_name])):
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1152 html_head = '<link rel="openid2.provider" href="%s">' % \
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1153 wikiutil.escape(request.getQualifiedURL(self.url(request,
3273
9c6900a92a64 more wikiutil.escape fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3235
diff changeset
1154 querystr={'action': 'serveopenid'})), True)
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1155 html_head += '<link rel="openid.server" href="%s">' % \
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1156 wikiutil.escape(request.getQualifiedURL(self.url(request,
3273
9c6900a92a64 more wikiutil.escape fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3235
diff changeset
1157 querystr={'action': 'serveopenid'})), True)
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1158 html_head += '<meta http-equiv="x-xrds-location" content="%s">' % \
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1159 wikiutil.escape(request.getQualifiedURL(self.url(request,
3273
9c6900a92a64 more wikiutil.escape fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3235
diff changeset
1160 querystr={'action': 'serveopenid', 'yadis': 'ep'})), True)
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1161 elif self.page_name == request.cfg.page_front_page:
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1162 html_head = '<meta http-equiv="x-xrds-location" content="%s">' % \
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1163 wikiutil.escape(request.getQualifiedURL(self.url(request,
3273
9c6900a92a64 more wikiutil.escape fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3235
diff changeset
1164 querystr={'action': 'serveopenid', 'yadis': 'idp'})), True)
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1165
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2930
diff changeset
1166 request.theme.send_title(title, page=self,
1779
224e2106ab89 call send_title with page kw arg, if available, not with pagename
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1778
diff changeset
1167 print_mode=print_mode,
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1168 media=media, pi_refresh=pi.get('refresh'),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1169 allow_doubleclick=1, trail=trail,
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1170 html_head=html_head,
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1171 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1172
3296
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1173 # special pages handling, including denying access
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1174 special = None
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1175
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1176 if not send_special:
3620
25431c5a76f9 fix editor preview not working for new pages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3610
diff changeset
1177 if not page_exists and not body:
3296
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1178 special = 'missing'
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1179 elif not request.user.may.read(self.page_name):
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1180 special = 'denied'
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1181
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1182 # if we have a special page, output it, unless
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1183 # - we should only output content (this is for say the pagelinks formatter)
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1184 # - we have a non-default formatter
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1185 if special and not content_only and self.default_formatter:
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1186 self._specialPageText(request, special) # this recursively calls send_page
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1187
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1188 # if we didn't short-cut to a special page, output this page
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1189 if not special:
1906
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1190 # start wiki content div
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1191 request.write(self.formatter.startContent(content_id))
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1192
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1193 # parse the text and send the page content
1908
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1907
diff changeset
1194 self.send_page_content(request, body,
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1907
diff changeset
1195 format=pi['format'],
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1196 format_args=pi['formatargs'],
150
3f6de4cba30b fixed MoinMoinBugs/DiffAnchorOffset
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 138
diff changeset
1197 do_cache=do_cache,
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1198 start_line=pi['lines'])
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1199
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1200 # check for pending footnotes
335
e574cc401e89 fixed MoinMoinBugs/IncorrectlyPlacedFootnote. All footnotes are now shown at the very bottom. There is a continuing numbering of all footnotes including the ones on included pages
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 286
diff changeset
1201 if getattr(request, 'footnotes', None) and not omit_footnotes:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1202 from MoinMoin.macro.FootNote import emit_footnotes
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1203 request.write(emit_footnotes(request, self.formatter))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1204
1906
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1205 # end wiki content div
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1206 request.write(self.formatter.endContent())
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1207
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1208 # end document output
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1209 if not content_only:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1210 # send the page footer
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1211 if self.default_formatter:
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 609
diff changeset
1212 request.theme.send_footer(self.page_name, print_mode=print_mode)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1213
1675
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1214 request.write(self.formatter.endDocument())
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1215
1809
03fbdd327f1f saving the pagelinks after closing html saves some ms for the user
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
1216 request.clock.stop('send_page')
03fbdd327f1f saving the pagelinks after closing html saves some ms for the user
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
1217 if not content_only and self.default_formatter:
03fbdd327f1f saving the pagelinks after closing html saves some ms for the user
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
1218 request.theme.send_closing_html()
03fbdd327f1f saving the pagelinks after closing html saves some ms for the user
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
1219
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1220 # cache the pagelinks
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1221 if do_cache and self.default_formatter and page_exists:
1639
95efbd8cfa55 caching: use pickle for pagelinks, too
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1636
diff changeset
1222 cache = caching.CacheEntry(request, self, 'pagelinks', scope='item', use_pickle=True)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1223 if cache.needsUpdate(self._text_filename()):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1224 links = self.formatter.pagelinks
1639
95efbd8cfa55 caching: use pickle for pagelinks, too
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1636
diff changeset
1225 cache.update(links)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1226
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1227 # restore old formatter (hopefully we dont throw any exception that is catched again)
1605
c4f2db04084b use 'is' for object identity checking
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1595
diff changeset
1228 if old_formatter is no_formatter:
1531
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1229 del request.formatter
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1230 else:
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1231 request.formatter = old_formatter
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1232
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1233
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1234 def getFormatterName(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1235 """ Return a formatter name as used in the caching system
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1236
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1237 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1238 @return: formatter name as used in caching
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1239 """
622
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
1240 if not hasattr(self, 'formatter') or self.formatter is None:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1241 return ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1242 module = self.formatter.__module__
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1243 return module[module.rfind('.') + 1:]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1244
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1245 def canUseCache(self, parser=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1246 """ Is caching available for this request?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1247
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1248 This make sure we can try to use the caching system for this
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1249 request, but it does not make sure that this will
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1250 succeed. Themes can use this to decide if a Refresh action
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1251 should be displayed.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1252
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1253 @param parser: the parser used to render the page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1254 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1255 @return: if this page can use caching
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1256 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1257 if (not self.rev and
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1258 not self.hilite_re and
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1259 not self.__body_modified and
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1260 self.getFormatterName() in self.cfg.caching_formats):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1261 # Everything is fine, now check the parser:
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 33
diff changeset
1262 if parser is None:
5682
ccb335181571 avoid hardly recoverable crashes if #format specification is invalid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5635
diff changeset
1263 try:
ccb335181571 avoid hardly recoverable crashes if #format specification is invalid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5635
diff changeset
1264 parser = wikiutil.searchAndImportPlugin(self.request.cfg, "parser", self.pi['format'])
ccb335181571 avoid hardly recoverable crashes if #format specification is invalid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5635
diff changeset
1265 except wikiutil.PluginMissingError:
ccb335181571 avoid hardly recoverable crashes if #format specification is invalid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5635
diff changeset
1266 return False
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1267 return getattr(parser, 'caching', False)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1268 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1269
1908
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1907
diff changeset
1270 def send_page_content(self, request, body, format='wiki', format_args='', do_cache=1, **kw):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1271 """ Output the formatted wiki page, using caching if possible
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1272
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1273 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1274 @param body: text of the wiki page
1908
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1907
diff changeset
1275 @param format: format of content, default 'wiki'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1276 @param format_args: #format arguments, used by some parsers
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1277 @param do_cache: if True, use cached content
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1278 """