annotate MoinMoin/Page.py @ 3410:81b8a5bb8711

send_page sucks. fix bug with invalid highlight REs
author Johannes Berg <johannes AT sipsolutions DOT net>
date Sat, 22 Mar 2008 13:43:21 +0100
parents 396d3434ab92
children ef612c82bdfd
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
1801
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1796
diff changeset
44 from MoinMoin.util import filesys
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
45
1126
fd05b2dc86a4 Now it even works on Python < 2.5
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1124
diff changeset
46 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
47 args = e.args
fd05b2dc86a4 Now it even works on Python < 2.5
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1124
diff changeset
48 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
49
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
50
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
51 class ItemCache:
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
52 """ 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
53
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
54 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
55 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
56 in and out.
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
57 """
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
58 def __init__(self, name):
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
59 """ Initialize ItemCache object.
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
60 @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
61 influences behaviour of refresh().
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
62 """
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
63 self.name = name
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
64 self.cache = {}
1836
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
65 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
66 # 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
67 self.requests = 0
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
68 self.hits = 0
1853
3ddf2193a16e reduced cache logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1836
diff changeset
69 self.loglevel = logging.NOTSET
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
70
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
71 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
72 """ 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
73 @param request: currently unused
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
74 @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
75 @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
76 @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
77 """
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1639
diff changeset
78 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
79 d[key] = data
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
80
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
81 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
82 """ 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
83 @param request: the request object
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
84 @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
85 @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
86 @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
87 """
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
88 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
89 try:
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
90 data = self.cache[name][key]
1626
189bbdd56620 ItemCache: minor code cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1624
diff changeset
91 self.hits += 1
189bbdd56620 ItemCache: minor code cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1624
diff changeset
92 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
93 except KeyError:
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
94 data = None
1626
189bbdd56620 ItemCache: minor code cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1624
diff changeset
95 hit_str = 'miss'
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
96 self.requests += 1
1853
3ddf2193a16e reduced cache logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1836
diff changeset
97 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
98 self.name,
1622
7d199191cb1f use new item meta data cache for acls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1621
diff changeset
99 hit_str,
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
100 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
101 name,
7d199191cb1f use new item meta data cache for acls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1621
diff changeset
102 key,
7d199191cb1f use new item meta data cache for acls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1621
diff changeset
103 ))
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
104 return data
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
105
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
106 def refresh(self, request):
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
107 """ 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
108 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
109 (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
110 @param request: the request object
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
111 """
1857
659070e5e4d3 introduce request.editlog and use it for ItemCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1853
diff changeset
112 elog = request.editlog
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):
dc0f45b10ae6 fix os.path.exists() vs. os.makedirs() race
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2845
diff changeset
495 raise err
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
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
517 # XXX TODO clean up the mess, rewrite _last_edited, last_edit, lastEditInfo for new logs,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
518 # XXX TODO do not use mtime() calls any more
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
519 def _last_edited(self, request):
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
520 # as it is implemented now, this is rather a _last_changed as it just uses
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
521 # the last log entry, which could be not only from an edit, but also from
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
522 # an attachment operation. See different semantics in .mtime().
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
523 cache_name = self.page_name
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
524 cache_key = 'lastlog'
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
525 log = request.cfg.cache.meta.getItem(request, cache_name, cache_key)
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
526 if log is None:
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
527 from MoinMoin.logfile import editlog
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 try:
2800
3d776db594ed fix wrong last_edit info
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
529 logfile = editlog.EditLog(request, rootpagename=self.page_name)
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
530 logfile.to_end()
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
531 log = logfile.previous()
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
532 except StopIteration:
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
533 log = () # don't use None!
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
534 request.cfg.cache.meta.putItem(request, cache_name, cache_key, log)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
535 return log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
536
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
537 def last_edit(self, request):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
538 """ Return the last edit.
637
35f0f8584a57 move wikirpc.py to xmlrpc/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 635
diff changeset
539 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
540
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
541 @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
542 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
543 @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
544 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
545 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
546 return None
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 result = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
549 if not self.rev:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
550 log = self._last_edited(request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
551 if log:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
552 editordata = log.getInterwikiEditorData(request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
553 editor = editordata[1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
554 if editordata[0] == 'interwiki':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
555 editor = "%s:%s" % editordata[1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
556 else: # 'ip'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
557 editor = editordata[1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
558 result = {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
559 'timestamp': log.ed_time_usecs,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
560 'editor': editor,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
561 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
562 del log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
563 if not result:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
564 version = self.mtime_usecs()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
565 result = {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
566 'timestamp': version,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
567 'editor': '?',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
568 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
569
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
570 return result
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
571
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
572 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
573 """ 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
574
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
575 @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
576 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
577 @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
578 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
579 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
580 return {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
581 if request is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
582 request = self.request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
583
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
584 # Try to get data from log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
585 log = self._last_edited(request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
586 if log:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
587 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
588 time = wikiutil.version2timestamp(log.ed_time_usecs)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
589 del log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
590 # Or from the file system
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
591 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
592 editor = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
593 time = os.path.getmtime(self._text_filename())
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 # Use user time format
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
596 time = request.user.getFormattedDateTime(time)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
597 return {'editor': editor, 'time': time}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
598
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
599 def isWritable(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
600 """ 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
601
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
602 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
603 @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
604 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
605 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
606
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
607 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
608 """ 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
609
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
610 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
611 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
612 isStandardPage()
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 @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
615 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
616 @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
617 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
618 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
619
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
620 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
621 """ 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
622
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
623 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
624 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
625
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
626 @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
627 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
628 @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
629 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
630 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
631
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
632 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
633 """ 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
634
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
635 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
636 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
637 cleaner code.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
638
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
639 @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
640 @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
641 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
642 @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
643 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
644 @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
645 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
646 # Edge cases
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
647 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
648 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
649
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
650 if includeDeleted:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
651 # 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
652 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
653 checklist = [0, 1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
654 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
655 checklist = [domain == 'underlay']
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
656 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
657 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
658 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
659 return True
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
660 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
661 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
662 # 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
663 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
664 rev = self.rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
665
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
666 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
667 use_underlay = -1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
668 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
669 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
670 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
671 return exists
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
672
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
673 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
674 """ Get Page size.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
675
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
676 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
677 @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
678 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
679 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
680 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
681 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
682
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
683 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
684 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
685 except EnvironmentError, e:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
686 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
687 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
688 return 0
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
689 raise
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
690
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
691 def mtime_usecs(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
692 """ Get 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
693
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
694 @rtype: long
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
695 @return: mtime of page (or 0 if page does not exist)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
696 """
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
697 request = self.request
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
698 cache_name = self.page_name
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
699 cache_key = 'lastpagechange'
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
700 mtime = request.cfg.cache.meta.getItem(request, cache_name, cache_key)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
701 current_wanted = (self.rev == 0) # True if we search for the current revision
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
702 if mtime is None or not current_wanted:
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
703 from MoinMoin.logfile import editlog
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
704 wanted_rev = "%08d" % self.rev
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
705 mtime = 0L
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
706 try:
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
707 logfile = editlog.EditLog(self.request, rootpagename=self.page_name)
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
708 for line in logfile.reverse():
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
709 if (current_wanted and line.rev != 99999999) or line.rev == wanted_rev:
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
710 mtime = line.ed_time_usecs
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
711 break
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
712 except StopIteration:
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
713 pass
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
714 if current_wanted:
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
715 request.cfg.cache.meta.putItem(request, cache_name, cache_key, mtime)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
716
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
717 return mtime
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
718
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
719 def mtime_printable(self, request):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
720 """ 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
721
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
722 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
723 @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
724 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
725 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
726 if not t:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
727 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
728 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
729 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
730 wikiutil.version2timestamp(t))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
731 return result
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
732
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
733 def split_title(self, force=0):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
734 """ 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
735
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
736 @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
737 @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
738 @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
739 """
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
740 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
741 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
742 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
743
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
744 # 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
745 # 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
746 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
747 return splitted
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
748
3234
a739558ca3dc Page.url() default changed to relative=False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3175
diff changeset
749 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
750 """ 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
751 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
752 (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
753
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
754 @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
755 @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
756 (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
757 @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
758 @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
759 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
760 @rtype: str
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
761 @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
762 """
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1809
diff changeset
763 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
764 # 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
765 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
766 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
767 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
768 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
769 else:
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
770 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
771
102
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
772 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
773
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
774 # 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
775 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
776 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
777 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
778
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
779 # 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
780 if 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
781 url = "%s#%s" % (url, wikiutil.url_quote_plus(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
782
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
783 if not relative:
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
784 url = '%s/%s' % (request.getScriptname(), url)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
785 return url
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
786
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
787 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
788 """ 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
789 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
790 # 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
791 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
792 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
793 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
794
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
795 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
796 """ 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
797
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
798 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
799
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
800 @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
801 @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
802 @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
803 @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
804 @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
805 @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
806 @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
807 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
808 @return: formatted link
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
809 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
810 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
811 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
812 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
813
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
814 # 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
815 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
816 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
817
1964
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
818 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
819 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
820 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
821 else:
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
822 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
823
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
824 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
825
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
826 # 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
827 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
828 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
829 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
830
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
831 return link
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
832
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
833 def getSubscribers(self, request, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
834 """ 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
835
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
836 @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
837 @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
838 @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
839 @keyword trivial: if 1, only include users who want trivial changes (default: 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
840 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
841 @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
842 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
843 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
844 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
845 trivial = kw.get('trivial', 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
846
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
847 # 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
848 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
849
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
850 # 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
851 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
852
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
853 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
854 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
855 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
856 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
857
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
858 # 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
859 # 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
860 # 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
861 # Also, if the change is trivial (send email isn't ticked) only send email to users
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
862 # who want_trivial changes (typically Admins on public sites)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
863 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
864 subscriber_list = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
865 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
866 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
867 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
868 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
869
3300
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
870 # 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
871 # 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
872 # 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
873 # MoinMoinBugs/GetSubscribersPerformanceProblem
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
874
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
875 # 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
876 # 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
877 # 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
878 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
879 continue # skip empty email addresses
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
880 if trivial and not subscriber.want_trivial:
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
881 continue # skip uninterested subscribers
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
882
3300
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
883 # skip people not subscribed
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
884 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
885 continue
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
886
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
887 # 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
888 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
889 continue
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
890
3300
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
891 # 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
892 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
893 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
894 subscriber_list[lang] = []
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
895 if return_users:
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
896 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
897 else:
f048c3edc164 reorder permission checks to last when getting subscribers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3298
diff changeset
898 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
899
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
900 return subscriber_list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
901
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
902 def parse_processing_instructions(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
903 """ Parse page text and extract processing instructions,
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
904 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
905 """
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 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
907 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
908 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
909 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
910
2223
eec3c7b6a686 make sure pi['language'] is set, even for xslt pages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2215
diff changeset
911 # 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
912 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
913
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
914 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
915 # 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
916 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
917 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
918 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
919 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
920 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
921 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
922
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 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
924
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 # 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
926 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
927 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
928 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
929 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
930
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
931 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
932 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
933 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
934 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
935 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
936
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 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
938 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
939
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 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
941 # 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
942 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
943 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
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 == "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
946 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
947 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
948 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
949 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
950 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
951 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
952 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
953 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
954 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
955 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
956 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
957 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
958 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
959 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
960 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
961 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
962 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
963 pi['refresh'] = (delay, url)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
964 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
965 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
966
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
967 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
968 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
969
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
970 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
971 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
972
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
973 elif verb == "openiduser":
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
974 if request.cfg.openid_server_enable_user:
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
975 pi['openid.user'] = args
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
976
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
977 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
978 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
979 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
980 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
981 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
982 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
983 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
984
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
985 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
986 return pi
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
987
1874
c4eb073a9cca refactor Save, merge save_raw into send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
988 def send_raw(self, content_disposition=None):
c4eb073a9cca refactor Save, merge save_raw into send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
989 """ 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
990 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
991 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
992 offer a dialogue to save it to disk (used by Save action).
1874
c4eb073a9cca refactor Save, merge save_raw into send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
993 """
678
48787c662e1a add 404 handling and cache headers for action=raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 664
diff changeset
994 request = self.request
1069
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
995 request.setHttpHeader("Content-type: text/plain; charset=%s" % config.charset)
678
48787c662e1a add 404 handling and cache headers for action=raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 664
diff changeset
996 if self.exists():
943
274b021f26b1 remove some unused code from send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 941
diff changeset
997 # 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
998 # 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
999 # RAW (file) content, the file mtime is correct as Last-Modified header.
1069
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
1000 request.setHttpHeader("Status: 200 OK")
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
1001 request.setHttpHeader("Last-Modified: %s" % util.timefuncs.formathttpdate(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
1002 text = self.encodeTextMimeType(self.body)
3009
e67e97ad578f better no content-length header than a wrong one, fixes truncated action=raw output for non-ascii pages (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
1003 #request.setHttpHeader("Content-Length: %d" % 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
1004 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
1005 # 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
1006 # 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
1007 filename_enc = "%s.txt" % self.page_name.encode(config.charset)
1874
c4eb073a9cca refactor Save, merge save_raw into send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
1008 request.setHttpHeader('Content-Disposition: %s; filename="%s"' % (
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
1009 content_disposition, filename_enc))
678
48787c662e1a add 404 handling and cache headers for action=raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 664
diff changeset
1010 else:
1069
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
1011 request.setHttpHeader('Status: 404 NOTFOUND')
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
1012 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
1013
1069
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
1014 request.emit_http_headers()
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
1015 request.write(text)
457
f423a8496ae3 moved action=raw implementation to Page object
Thomas Waldmann <tw@waldmann-edv.de>
parents: 413
diff changeset
1016
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
1017 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
1018 """ 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
1019
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1020 TODO: "kill send_page(), quick" (since 2002 :)
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1021
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
1022 @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
1023 @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
1024 @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
1025 @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
1026 @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
1027 """
1777
ed44b93599b5 remove unneeded request param from page.send_page()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1776
diff changeset
1028 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
1029 _ = request.getText
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1030 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
1031 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
1032 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
1033 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
1034 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
1035 do_cache = keywords.get('do_cache', 1)
3296
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1036 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
1037 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
1038 if print_mode:
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1858
diff changeset
1039 media = 'media' in request.form and request.form['media'][0] or 'print'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1040 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1041 media = 'screen'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1042 self.hilite_re = (keywords.get('hilite_re') or
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1043 request.form.get('highlight', [None])[0])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1044
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1045 # count hit?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1046 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
1047 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
1048
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1049 # 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
1050 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
1051 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
1052
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
1053 if 'redirect' in pi and 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
1054 'action' in request.form or 'redirect' in request.form or content_only):
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
1055 # 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
1056 # 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
1057 # (see code in "request") or any cascaded redirection
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
1058 request.http_redirect('%s/%s?action=show&redirect=%s' % (
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
1059 request.getScriptname(),
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
1060 wikiutil.quoteWikinameURL(pi['redirect']),
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
1061 wikiutil.url_quote_plus(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
1062 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1063
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
1064 # 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
1065 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
1066 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
1067 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
1068 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
1069 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
1070 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
1071
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1072 # save formatter
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1073 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
1074 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
1075 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
1076
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1077 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
1078 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
1079 try:
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
1080 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
1081 except re.error, err:
3410
81b8a5bb8711 send_page sucks. fix bug with invalid highlight REs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3394
diff changeset
1082 if 'highlight' in request.form:
81b8a5bb8711 send_page sucks. fix bug with invalid highlight REs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3394
diff changeset
1083 del request.form['highlight']
3285
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
1084 request.theme.add_msg(_('Invalid highlighting regular expression "%(regex)s": %(error)s') % {
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
1085 'regex': self.hilite_re,
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
1086 'error': str(err),
bfd3f600650b fix highlighting for search results and WantedPages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3279
diff changeset
1087 }, "warning")
3410
81b8a5bb8711 send_page sucks. fix bug with invalid highlight REs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3394
diff changeset
1088 self.hilite_re = None
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1564
diff changeset
1089
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
1090 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
1091 # 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
1092 # (which should be a short reason why the page is deprecated)
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
1093 request.theme.add_msg(_('The backed up content of this page is deprecated and will not be included 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
1094
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
1095 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
1096 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
1097 oldpage = Page(request, self.page_name, rev=revisions[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
1098 body += oldpage.get_raw_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
1099 del oldpage
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1100
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
1101 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
1102 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
1103
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
1104 # 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
1105 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
1106 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
1107 if emit_headers:
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.setHttpHeader("Content-Type: %s; charset=%s" % (self.output_mimetype, self.output_charset))
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
1109 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
1110 if not request.user.may.read(self.page_name):
d563a49e0054 give 403 status for permission denied pages rather than 200
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3296
diff changeset
1111 request.setHttpHeader('Status: 403 Permission Denied')
d563a49e0054 give 403 status for permission denied pages rather than 200
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3296
diff changeset
1112 else:
d563a49e0054 give 403 status for permission denied pages rather than 200
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3296
diff changeset
1113 request.setHttpHeader('Status: 200 OK')
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
1114 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
1115 # 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
1116 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
1117 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
1118 # 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
1119 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
1120 else:
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
1121 # 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
1122 # 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
1123 # 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
1124 #lastmod = os.path.getmtime(self._text_filename())
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
1125 #request.setHttpHeader("Last-Modified: %s" % 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
1126 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
1127 else:
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
1128 request.setHttpHeader('Status: 404 NOTFOUND')
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
1129 request.emit_http_headers()
1069
d7227430c305 fixed and cleaned up http headers usage in Page/PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1051
diff changeset
1130
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
1131 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
1132 # 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
1133 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
1134
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
1135 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
1136
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1137 # 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
1138 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
1139 if self.rev:
3154
c9ff5a31b5cd fix some Page object theme.msg_add() calls
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3144
diff changeset
1140 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
1141 _('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
1142 'rev': self.rev,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1143 'date': 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
1144 }), "info")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1145
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1146 # 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
1147 # Less annoying now without the warning sign.
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1858
diff changeset
1148 if 'redirect' in request.form:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1149 redir = request.form['redirect'][0]
3154
c9ff5a31b5cd fix some Page object theme.msg_add() calls
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3144
diff changeset
1150 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
1151 _('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
1152 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
1153 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
1154 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
1155 _('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
1156
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1157 # Page trail
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1158 trail = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1159 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
1160 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
1161 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
1162
1776
fc75423e26a8 remove unneeded request param from page.split_title()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1756
diff changeset
1163 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
1164
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1165 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
1166 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
1167 openid_username = self.page_name
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1168 userid = user.getUserId(request, openid_username)
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1169
3394
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1170 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
1171 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
1172 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
1173
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1174 if request.cfg.openid_server_restricted_users_group:
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1175 request.dicts.addgroup(request,
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1176 request.cfg.openid_server_restricted_users_group)
396d3434ab92 move some code under openid_server_enabled where it belongs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3300
diff changeset
1177
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1178 if userid is not None and not request.cfg.openid_server_restricted_users_group or \
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1179 request.dicts.has_member(request.cfg.openid_server_restricted_users_group, openid_username):
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1180 html_head = '<link rel="openid2.provider" href="%s">' % \
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1181 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
1182 querystr={'action': 'serveopenid'})), True)
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1183 html_head += '<link rel="openid.server" href="%s">' % \
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1184 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
1185 querystr={'action': 'serveopenid'})), True)
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1186 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
1187 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
1188 querystr={'action': 'serveopenid', 'yadis': 'ep'})), True)
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1189 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
1190 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
1191 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
1192 querystr={'action': 'serveopenid', 'yadis': 'idp'})), True)
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1193
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
1194 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
1195 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
1196 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
1197 allow_doubleclick=1, trail=trail,
3144
7aba52041f56 add OpenID provider code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1198 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
1199 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1200
3296
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1201 # special pages handling, including denying access
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1202 special = None
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1203
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1204 if not send_special:
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1205 if not page_exists:
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1206 special = 'missing'
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1207 elif not request.user.may.read(self.page_name):
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1208 special = 'denied'
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1209
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1210 # if we have a special page, output it, unless
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1211 # - 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
1212 # - we have a non-default formatter
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1213 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
1214 self._specialPageText(request, special) # this recursively calls send_page
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1215
fc5e23d62d56 implement FeatureRequests/AclAccessDeniedMessageIsWikiPage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3285
diff changeset
1216 # 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
1217 if not special:
1906
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1218 # start wiki content div
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1219 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
1220
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1221 # 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
1222 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
1223 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
1224 format_args=pi['formatargs'],
150
3f6de4cba30b fixed MoinMoinBugs/DiffAnchorOffset
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 138
diff changeset
1225 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
1226 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
1227
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1228 # 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
1229 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
1230 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
1231 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
1232
1906
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1233 # end wiki content div
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1234 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
1235
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1236 # end document output
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1237 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
1238 # 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
1239 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
1240 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
1241
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
1242 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
1243
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
1244 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
1245 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
1246 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
1247
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1248 # cache the pagelinks
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1249 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
1250 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
1251 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
1252 links = self.formatter.pagelinks
1639
95efbd8cfa55 caching: use pickle for pagelinks, too
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1636
diff changeset
1253 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
1254
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
1255 # 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
1256 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
1257 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
1258 else:
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1259 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
1260
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1261
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1262 def getFormatterName(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1263 """ 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
1264
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1265 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1266 @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
1267 """
622
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
1268 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
1269 return ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1270 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
1271 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
1272
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1273 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
1274 """ 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
1275
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1276 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
1277 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
1278 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
1279 should be displayed.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1280
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1281 @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
1282 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1283 @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
1284 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1285 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
1286 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
1287 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
1288 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
1289 # 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
1290 if parser is 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 wald