annotate MoinMoin/Page.py @ 3085:fdb68a8f92da

fix wrong pagename when creating new pages on Mac OS X (ported from 1.6)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 00:28:53 +0100
parents 6238e1b2fd7f
children a48929a5036c
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>,
1778
465b0086c410 cleanup comments, some minor refactorings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
31 2005-2007 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
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
37 import os, re, codecs, logging
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
38
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
39 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
40 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
41 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
42
1126
fd05b2dc86a4 Now it even works on Python < 2.5
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1124
diff changeset
43 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
44 args = e.args
fd05b2dc86a4 Now it even works on Python < 2.5
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1124
diff changeset
45 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
46
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
47
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
48 class ItemCache:
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
49 """ 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
50
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
51 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
52 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
53 in and out.
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
54 """
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
55 def __init__(self, name):
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
56 """ Initialize ItemCache object.
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
57 @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
58 influences behaviour of refresh().
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
59 """
1624
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
60 self.name = name
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
61 self.cache = {}
1836
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
62 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
63 # 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
64 self.requests = 0
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
65 self.hits = 0
1853
3ddf2193a16e reduced cache logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1836
diff changeset
66 self.loglevel = logging.NOTSET
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
67
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
68 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
69 """ 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
70 @param request: currently unused
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
71 @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
72 @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
73 @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
74 """
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1639
diff changeset
75 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
76 d[key] = data
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
77
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
78 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
79 """ 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
80 @param request: the request object
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
81 @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
82 @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
83 @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
84 """
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
85 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
86 try:
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
87 data = self.cache[name][key]
1626
189bbdd56620 ItemCache: minor code cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1624
diff changeset
88 self.hits += 1
189bbdd56620 ItemCache: minor code cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1624
diff changeset
89 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
90 except KeyError:
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
91 data = None
1626
189bbdd56620 ItemCache: minor code cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1624
diff changeset
92 hit_str = 'miss'
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
93 self.requests += 1
1853
3ddf2193a16e reduced cache logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1836
diff changeset
94 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
95 self.name,
1622
7d199191cb1f use new item meta data cache for acls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1621
diff changeset
96 hit_str,
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
97 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
98 name,
7d199191cb1f use new item meta data cache for acls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1621
diff changeset
99 key,
7d199191cb1f use new item meta data cache for acls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1621
diff changeset
100 ))
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
101 return data
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
102
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
103 def refresh(self, request):
1632
f89736ab2c8e ItemCache: CHANGES entry, epydoc comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1631
diff changeset
104 """ 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
105 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
106 (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
107 @param request: the request object
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
108 """
1857
659070e5e4d3 introduce request.editlog and use it for ItemCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1853
diff changeset
109 elog = request.editlog
1836
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
110 old_pos = self.log_pos
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
111 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
112 if items:
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
113 if self.name == 'meta':
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
114 for item in items:
1853
3ddf2193a16e reduced cache logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1836
diff changeset
115 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
116 try:
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
117 del self.cache[item]
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
118 except:
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
119 pass
0b0b94e1680f cache pagelist using new cache mechanism
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1623
diff changeset
120 elif self.name == 'pagelists':
1853
3ddf2193a16e reduced cache logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1836
diff changeset
121 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
122 self.cache = {}
1836
42fb37416fe8 fix race condition for ItemCache.news
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1830
diff changeset
123 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
124 # avoids threading race conditions
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
125
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
126
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
127 class Page(object):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
128 """ 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
129 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
130 """
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
131 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
132 """ 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
133
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
134 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
135 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
136 efficient.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
137
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
138 @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
139 @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
140 @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
141 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
142 @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
143 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
144 self.request = request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
145 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
146 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
147 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
148 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
149
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 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 else:
622
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
161 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
162 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
163 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
164
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
165 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
166
1627
82e8a6a2eb1b ItemCache usage: fix handling of Missing[Home]Page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1626
diff changeset
167 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
168 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
169
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
170 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
171 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
172 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
173 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
174 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
175
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
176 self.reset()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
177
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
178 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
179 """ Reset page state """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
180 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
181 # 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
182 # 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
183
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
184 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
185 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
186
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
187 # 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
188 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
189 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
190 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
191 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
192 underlaypath = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
193
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
194 # 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
195
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
196 # 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
197 # 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
198 self._underlay = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
199
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
200 # 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
201 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
202
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
203 # 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
204
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
205 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
206 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
207 # 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
208 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
209 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
210 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
211 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
212 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
213 # 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
214 # 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
215 # 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
216 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
217 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
218 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
219
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 # 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
221 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
222 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
223 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
224 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
225 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
226 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
227 return self.__body
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
228
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
229 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
230 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
231 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
232 self.__data = None
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
233 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
234
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
235 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
236 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
237 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
238 return self.__meta
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
239 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
240
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
242 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
243 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
244 return self.__data
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
245 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
246
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
248 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
249 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
250 return self.__pi
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
251 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
252
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
253 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
254 """ 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
255
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 @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
257 @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
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 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
260
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
262 """ 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
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 @rtype: unicode
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
265 @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
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 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
268
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
270 """ 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
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 @rtype: str
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
273 @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
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 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
276
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
278 """ 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
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 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
281
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 @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
283 @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
284 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
285 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
286 """
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
288 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
289
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
290 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
291 """ 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
292 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
293 @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
294 @return: int currentrev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
295 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
296 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
297 try:
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1618
diff changeset
298 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
299 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
300 revfile.close()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
301 rev = int(revstr)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
302 except:
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
303 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
304 return rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
305
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
306 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
307 """ 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
308
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
309 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
310
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
311 @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
312 @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
313 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
314 @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
315 int realrevint,
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
316 bool exists)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
317 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
318 if rev == 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
319 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
320
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
321 revstr = '%08d' % rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
322 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
323 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
324 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
325 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
326 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
327 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
328 exists = False
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
329 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
330
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
331 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
332 """ 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
333
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
334 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
335 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
336 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
337 See MoinMoinBugs/MacHfsPlusCaseInsensitive
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
338
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
339 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
340 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
341 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
342
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
343 Problems to fix later:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
344
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
345 - ["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
346 considered as backlink.
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 @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
349 """
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
350 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
351 # 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
352 # 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
353 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
354 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
355 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
356 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
357
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
358 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
359 """ 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
360
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
361 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
362
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
363 @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
364 @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
365 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
366 @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
367 int realrevint,
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
368 bool exists)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
369 """
1621
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
370 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
371 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
372 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
373 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
374 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
375 else: # 1
cce18ece4ce7 use itemname and key for item meta data cache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1620
diff changeset
376 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
377
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
378 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
379 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
380 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
381 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
382 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
383 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
384 # 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
385 #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
386 return cache_data
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
387
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
388 # 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
389 if use_underlay == -1:
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
390 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
391 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
392 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
393
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
394 # 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
395 if rev == 0:
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
396 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
397 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
398 realrev = rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
399
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
400 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
401 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
402 # 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
403 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
404
1620
a86f20280204 implement and use ItemMetaDataCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
405 return data
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
406
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
407 def current_rev(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
408 """ Return number of current revision.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
409
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
410 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
411
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
412 @return: int revision
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
413 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
414 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
415 return rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
416
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
417 def get_real_rev(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
418 """ 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
419 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
420
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
421 @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
422 @rtype: int
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 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
425 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
426 return self.rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
427
1698
35ebda626b4b getPageBasePath: add default value for use_underlay and improve docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1693
diff changeset
428 def getPageBasePath(self, use_underlay=-1):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
429 """ 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
430 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
431
1698
35ebda626b4b getPageBasePath: add default value for use_underlay and improve docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1693
diff changeset
432 @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
433 -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
434 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
435 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
436 @rtype: string
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
437 @return: int underlay,
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
438 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
439 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
440 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
441 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
442 use_underlay = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
443
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
444 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
445 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
446 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
447 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
448 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
449 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
450 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
451 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
452 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
453 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
454 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
455 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
456 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
457 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
458
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
459 return underlay, path
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
460
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
461 def getPageStatus(self, *args, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
462 """ 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
463 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
464
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
465 @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
466 @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
467 -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
468 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
469 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
470 @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
471 (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
472 (default true)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
473 @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
474 @rtype: string
354
4eddf2f2c513 Merged doc string optimisations from MoinMoin:RichardDarst/DocPatches
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 335
diff changeset
475 @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
476 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
477 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
478 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
479 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
480 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
481 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
482 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
483 if check_create:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
484 if isfile:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
485 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
486 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
487 dirname = fullpath
2930
dc0f45b10ae6 fix os.path.exists() vs. os.makedirs() race
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2845
diff changeset
488 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
489 os.makedirs(dirname)
2930
dc0f45b10ae6 fix os.path.exists() vs. os.makedirs() race
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2845
diff changeset
490 except OSError, err:
dc0f45b10ae6 fix os.path.exists() vs. os.makedirs() race
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2845
diff changeset
491 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
492 raise err
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
493 return underlay, fullpath
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
494
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
495 def getPagePath(self, *args, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
496 """ 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
497 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
498
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
499 def _text_filename(self, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
500 """ 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
501
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
502 @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
503 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
504 @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
505 """
1627
82e8a6a2eb1b ItemCache usage: fix handling of Missing[Home]Page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1626
diff changeset
506 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
507 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
508 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
509 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
510 rev = self.rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
511 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
512 return fname
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
513
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
514 # 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
515 # 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
516 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
517 # 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
518 # 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
519 # 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
520 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
521 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
522 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
523 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
524 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
525 try:
2800
3d776db594ed fix wrong last_edit info
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
526 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
527 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
528 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
529 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
530 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
531 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
532 return log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
533
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
534 def last_edit(self, request):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
535 """ 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
536 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
537
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
538 @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
539 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
540 @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
541 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
542 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
543 return None
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 result = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
546 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
547 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
548 if log:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
549 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
550 editor = editordata[1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
551 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
552 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
553 else: # 'ip'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
554 editor = editordata[1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
555 result = {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
556 '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
557 'editor': editor,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
558 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
559 del log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
560 if not result:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
561 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
562 result = {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
563 'timestamp': version,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
564 'editor': '?',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
565 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
566
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
567 return result
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 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
570 """ 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
571
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
572 @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
573 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
574 @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
575 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
576 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
577 return {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
578 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
579 request = self.request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
580
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
581 # 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
582 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
583 if log:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
584 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
585 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
586 del log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
587 # 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
588 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
589 editor = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
590 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
591
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
592 # 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
593 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
594 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
595
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
596 def isWritable(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
597 """ 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
598
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
599 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
600 @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
601 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
602 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
603
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
604 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
605 """ 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
606
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
607 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
608 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
609 isStandardPage()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
610
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
611 @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
612 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
613 @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
614 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
615 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
616
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
617 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
618 """ 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
619
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
620 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
621 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
622
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
623 @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
624 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
625 @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
626 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
627 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
628
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
629 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
630 """ 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
631
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
632 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
633 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
634 cleaner code.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
635
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
636 @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
637 @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
638 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
639 @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
640 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
641 @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
642 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
643 # Edge cases
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
644 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
645 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
646
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
647 if includeDeleted:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
648 # 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
649 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
650 checklist = [0, 1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
651 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
652 checklist = [domain == 'underlay']
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
653 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
654 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
655 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
656 return True
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
657 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
658 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
659 # 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
660 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
661 rev = self.rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
662
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
663 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
664 use_underlay = -1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
665 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
666 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
667 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
668 return exists
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
669
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
670 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
671 """ Get Page size.
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 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
674 @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
675 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
676 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
677 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
678 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
679
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
680 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
681 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
682 except EnvironmentError, e:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
683 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
684 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
685 return 0
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
686 raise
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
687
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
688 def mtime_usecs(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
689 """ 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
690
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
691 @rtype: long
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
692 @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
693 """
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
694 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
695 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
696 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
697 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
698 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
699 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
700 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
701 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
702 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
703 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
704 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
705 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
706 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
707 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
708 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
709 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
710 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
711 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
712 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
713
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
714 return mtime
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
715
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
716 def mtime_printable(self, request):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
717 """ 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
718
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
719 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
720 @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
721 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
722 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
723 if not t:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
724 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
725 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
726 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
727 wikiutil.version2timestamp(t))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
728 return result
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
729
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
730 def split_title(self, force=0):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
731 """ 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
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 @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
734 @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
735 @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
736 """
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
738 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
739 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
740
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
741 # 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
742 # 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
743 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
744 return splitted
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
745
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1809
diff changeset
746 def url(self, request, querystr=None, anchor=None, relative=True, **kw):
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1809
diff changeset
747 """ 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
748 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
749 (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
750
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
751 @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
752 @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
753 (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
754 @param anchor: if specified, make a link to this anchor
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
755 @rtype: str
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
756 @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
757 """
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1809
diff changeset
758 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
759 # 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
760 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
761 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
762 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
763 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
764 else:
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
765 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
766
102
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
767 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
768
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
769 # 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
770 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
771 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
772 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
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 # 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
775 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
776 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
777
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
778 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
779 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
780 return url
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
781
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
782 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
783 """ core functionality of link_to, without the magic """
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1809
diff changeset
784 url = self.url(request, querystr, anchor=anchor)
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
785 # 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
786 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
787 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
788 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
789
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
790 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
791 """ 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
792
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
793 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
794
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
795 @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
796 @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
797 @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
798 @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
799 @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
800 @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
801 @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
802 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
803 @return: formatted link
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
804 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
805 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
806 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
807 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
808
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
809 # 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
810 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
811 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
812
1964
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
813 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
814 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
815 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
816 else:
911fe470bfae WordIndex/TitleIndex: fix invalid <a> tag attribute
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1961
diff changeset
817 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
818
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
819 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
820
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
821 # 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
822 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
823 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
824 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
825
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
826 return link
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
827
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
828 def getSubscribers(self, request, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
829 """ 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
830
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
831 @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
832 @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
833 @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
834 @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
835 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
836 @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
837 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
838 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
839 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
840 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
841
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
842 # 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
843 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
844
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
845 # 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
846 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
847
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
848 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
849 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
850 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
851 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
852
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
853 # 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
854 # 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
855 # 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
856 # 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
857 # 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
858 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
859 subscriber_list = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
860 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
861 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
862 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
863 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
864
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
865 # 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
866 # 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
867 # 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
868 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
869 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
870 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
871 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
872
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
873 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
874 continue
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
875
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
876 if subscriber.isSubscribedTo(pageList):
609
a188f23ba223 use cfg.language_default not 'en' for subscription mails
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 551
diff changeset
877 lang = subscriber.language or request.cfg.language_default
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
878 if not lang in subscriber_list:
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
879 subscriber_list[lang] = []
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
880 if return_users:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
881 subscriber_list[lang].append(subscriber)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
882 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
883 subscriber_list[lang].append(subscriber.email)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
884
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
885 return subscriber_list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
886
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
887 def parse_processing_instructions(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
888 """ Parse page text and extract processing instructions,
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
889 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
890 """
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
891 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
892 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
893 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
894 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
895
2223
eec3c7b6a686 make sure pi['language'] is set, even for xslt pages
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2215
diff changeset
896 # 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
897 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
898
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
899 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
900 # 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
901 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
902 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
903 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
904 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
905 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
906 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
907
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
908 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
909
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
910 # 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
911 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
912 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
913 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
914 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
915
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 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
917 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
918 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
919 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
920 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
921
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
923 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
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 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
926 # 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
927 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
928 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
929
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
930 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
931 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
932 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
933 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
934 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
935 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
936 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
937 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
938 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
939 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
940 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
941 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
942 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
943 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
944 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
945 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
946 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
947 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
948 pi['refresh'] = (delay, url)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
949 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
950 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
951
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
952 elif verb == "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
953 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
954
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
956 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
957
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
959 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
960 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
961 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
962 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
963 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
964 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
965
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
967 return pi
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
968
1874
c4eb073a9cca refactor Save, merge save_raw into send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
969 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
970 """ 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
971 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
972 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
973 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
974 """
678
48787c662e1a add 404 handling and cache headers for action=raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 664
diff changeset
975 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
976 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
977 if self.exists():
943
274b021f26b1 remove some unused code from send_raw
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 941
diff changeset
978 # 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
979 # 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
980 # 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
981 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
982 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
983 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
984 #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
985 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
986 # 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
987 # 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
988 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
989 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
990 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
991 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
992 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
993 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
994
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.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
996 request.write(text)
457
f423a8496ae3 moved action=raw implementation to Page object
Thomas Waldmann <tw@waldmann-edv.de>
parents: 413
diff changeset
997
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
998 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
999 """ 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
1000
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1001 TODO: "kill send_page(), quick" (since 2002 :)
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1002
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
1003 @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
1004 @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
1005 @keyword count_hit: if 1, add an event to the log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1006 @keyword send_missing_page: if 1, assume that page to be sent is MissingPage
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
1007 @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
1008 """
1777
ed44b93599b5 remove unneeded request param from page.send_page()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1776
diff changeset
1009 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
1010 _ = request.getText
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1011 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
1012 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
1013 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
1014 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
1015 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
1016 do_cache = keywords.get('do_cache', 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
1017 send_missing_page = keywords.get('send_missing_page', 0)
1875
5afb427026ea refactor print_mode, fix/simplify content action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1874
diff changeset
1018 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
1019 if print_mode:
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1858
diff changeset
1020 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
1021 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1022 media = 'screen'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1023 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
1024 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
1025
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1026 # count hit?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1027 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
1028 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
1029
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1030 # 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
1031 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
1032 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
1033
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed 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 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
1035 '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
1036 # 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
1037 # 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
1038 # (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
1039 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
1040 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
1041 wikiutil.quoteWikinameURL(pi['redirect']),
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
1042 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
1043 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1044
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
1045 # 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
1046 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
1047 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
1048 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
1049 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
1050 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
1051 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
1052
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1053 # save formatter
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1054 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
1055 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
1056 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
1057
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1058 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
1059 if self.hilite_re:
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
1060 self.formatter.set_highlight_re(self.hilite_re)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1564
diff changeset
1061
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 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
1063 # 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
1064 # (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
1065 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
1066
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
1067 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
1068 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
1069 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
1070 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
1071 del oldpage
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1072
1880
b07b4c102d3d began refactoring send_page(): processing instruction extraction, getting meta/data part of page only, fixed related problems with language detection. Removed lots of duplicate or unused code.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1875
diff changeset
1073 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
1074 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
1075
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2250
diff changeset
1076 # 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
1077 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
1078 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
1079 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
1080 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
1081 if page_exists:
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
1082 request.setHttpHeader('Status: 200 OK')
b8d488de4b69 send_page: use emit_headers=0 to suppress emitting of http headers (merged from docbook branch)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1646
diff changeset
1083 if 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
1084 # 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
1085 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
1086 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
1087 # 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
1088 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
1089 else:
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
1090 # 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
1091 # 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
1092 # 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
1093 #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
1094 #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
1095 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
1096 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
1097 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
1098 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
1099
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
1100 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
1101 # 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
1102 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
1103
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
1104 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
1105
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1106 # 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
1107 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
1108 if self.rev:
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
1109 request.theme.add_msg("<strong>%s</strong><br>%s" % (
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1110 _('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
1111 'rev': self.rev,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1112 'date': self.mtime_printable(request)
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
1113 }, "info"))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1114
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1115 # 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
1116 # 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
1117 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
1118 redir = request.form['redirect'][0]
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
1119 request.theme.add_msg('<strong>%s</strong><br>%s' % (
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1120 _('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
1121 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
1122 if 'redirect' in pi:
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
1123 request.theme.add_msg('<strong>%s</strong><br>%s' % (
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
1124 _('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
1125
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1126 # Page trail
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1127 trail = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1128 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
1129 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
1130 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
1131
1776
fc75423e26a8 remove unneeded request param from page.split_title()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1756
diff changeset
1132 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
1133
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
1134 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
1135 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
1136 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
1137 allow_doubleclick=1, trail=trail,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1138 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1139
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1140 # new page?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1141 if not page_exists and (not content_only or (content_only
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1142 and send_missing_page)):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1143 if self.default_formatter and not content_only:
1906
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1144 self._emptyPageText(request) # this recursively calls send_page
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1145 elif content_only and send_missing_page:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1146 # We should send MissingPage but it is not there
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1147 import warnings
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1148 warnings.warn("Error - The page MissingPage or MissingHomePage could not be found."
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1149 " Check your underlay directory setting.")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1150 url = '%s?action=edit' % wikiutil.quoteWikinameURL(self.page_name)
1778
465b0086c410 cleanup comments, some minor refactorings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
1151 request.write(wikiutil.link_tag(request, url, text=_("Create New Page"),
869
0152984f76ee use rel nofollow for action links
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 825
diff changeset
1152 formatter=self.formatter, rel='nofollow'))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1153 elif not request.user.may.read(self.page_name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1154 request.write("<strong>%s</strong><br>" % _("You are not allowed to view this page."))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1155 else:
1906
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1156 # start wiki content div
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1157 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
1158
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1159 # 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
1160 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
1161 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
1162 format_args=pi['formatargs'],
150
3f6de4cba30b fixed MoinMoinBugs/DiffAnchorOffset
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 138
diff changeset
1163 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
1164 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
1165
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1166 # 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
1167 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
1168 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
1169 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
1170
1906
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1171 # end wiki content div
4c424f7b5d55 fix double content div for MissingPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1885
diff changeset
1172 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
1173
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1174 # end document output
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1175 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
1176 # 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
1177 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
1178 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
1179
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
1180 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
1181
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
1182 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
1183 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
1184 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
1185
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1186 # cache the pagelinks
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1187 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
1188 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
1189 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
1190 links = self.formatter.pagelinks
1639
95efbd8cfa55 caching: use pickle for pagelinks, too
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1636
diff changeset
1191 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
1192
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
1193 # 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
1194 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
1195 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
1196 else:
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1197 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
1198
b369a5c3f3e2 Restore the formatter in send_page, fixes 'empty' search results.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1520
diff changeset
1199
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1200 def getFormatterName(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1201 """ 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
1202
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1203 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1204 @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
1205 """
622
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 620
diff changeset
1206 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
1207 return ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1208 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
1209 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
1210
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1211 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
1212 """ 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
1213
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1214 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
1215 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
1216 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
1217 should be displayed.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1218
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1219 @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
1220 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1221 @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
1222 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1223 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
1224 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
1225 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
1226 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
1227 # 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
1228 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 waldmann-edv DOT de>
parents: 1875
diff changeset
1229 parser = wikiutil.searchAndImportPlugin(self.request.cfg, "parser", self.pi['format'])
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1230 return getattr(parser, 'caching', False)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1231 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1232
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
1233 def send_page_content(self, request, body, format='wiki', format_args='', do_cache=1, **kw):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1234 """ Output the formatted wiki page, using caching if possible
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1235
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1236 @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
1237 @param body: text of the wiki page
1908
8bd4b581cc60 make converter pluggable, dynamically load correct converter, move loading of parser to send_page_content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1907
diff changeset
1238 @param format: format of content, default 'wiki'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1239 @param format_args: #format arguments, used by some parsers
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1240 @param do_cache: if True, use cached content
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1241 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1242 request.clock.start('send_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
1243 # Load the parser
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
1244 Parser = wikiutil.searchAndImportPlugin(request.cfg, "parser", format)
150
3f6de4cba30b fixed MoinMoinBugs/DiffAnchorOffset
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 138
diff changeset
1245 parser = Parser(body, request, format_args=format_args, **kw)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1246
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1247 if not (do_cache and self.canUseCache(Parser)):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1248 self.format(parser)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1249 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1250 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1251 code = self.loadCache(request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1252 self.execute(request, parser, code)
1124
0719653ce4fb Do not break on plugin exceptions in Page
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1070
diff changeset
1253 except Exception, e:
1126
fd05b2dc86a4 Now it even works on Python < 2.5
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1124
diff changeset
1254 if not is_cache_exception(e):
1045
4725c8ac809a Fixed Python 2.5 incompatibility issues (avoid str exceptions), made the bytecode more resistant for people using data directoriees with different MoinMoin versions.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 997
diff changeset
1255 raise
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1256 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1257 code = self.makeCache(request, parser)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1258 self.execute(request, parser, code)
1124
0719653ce4fb Do not break on plugin exceptions in Page
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1070
diff changeset
1259 except Exception, e:
1126
fd05b2dc86a4 Now it even works on Python < 2.5
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1124
diff changeset
1260 if not is_cache_exception(e):
1045
4725c8ac809a Fixed Python 2.5 incompatibility issues (avoid str exceptions), made the bytecode more resistant for people using data directoriees with different MoinMoin versions.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 997
diff changeset
1261 raise
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1262 request.log('page cache failed after creation')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1263 self.format(parser)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1564
diff changeset
1264
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1265 request.clock.stop('send_page_content')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1266
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1267 def format(self, parser):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1268 """ Format and write page content without caching """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1269 parser.format(self.formatter)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1270
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1271 def execute(self, request, parser, code):
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1564
diff changeset
1272 """ Write page content by executing cache code """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1273 formatter = self.formatter
1146
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1274 request.clock.start("Page.execute")
1051
ac85f3b79216 Bugfix, convert the exception yielded by exec.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1045
diff changeset
1275 try:
1146
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1276 from MoinMoin.macro import Macro
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1564
diff changeset
1277 macro_obj = Macro(parser)
1146
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1278 # Fix __file__ when running from a zip package
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1279 import MoinMoin
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1280 if hasattr(MoinMoin, '__loader__'):
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1281 __file__ = os.path.join(MoinMoin.__loader__.archive, 'dummy')
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1282 try:
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1283 exec code
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1284 except "CacheNeedsUpdate": # convert the exception
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1285 raise Exception("CacheNeedsUpdate")
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1286 finally:
40059e38427a Ensure that the timer is called in Page.execute.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1145
diff changeset
1287 request.clock.stop("Page.execute")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1288
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1289 def loadCache(self, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1290 """ Return page content cache or raises 'CacheNeedsUpdate' """
682
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 678
diff changeset
1291 cache = caching.CacheEntry(request, self, self.getFormatterName(), scope='item')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1292 attachmentsPath = self.getPagePath('attachments', check_create=0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1293 if cache.needsUpdate(self._text_filename(), attachmentsPath):
1045
4725c8ac809a Fixed Python 2.5 incompatibility issues (avoid str exceptions), made the bytecode more resistant for people using data directoriees with different MoinMoin versions.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 997
diff changeset
1294 raise Exception('CacheNeedsUpdate')
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1564
diff changeset
1295
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1296 import marshal
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1297 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1298 return marshal.loads(cache.content())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1299 except (EOFError, ValueError, TypeError):