annotate MoinMoin/PageEditor.py @ 3721:497c47e00539

revert 384135a7bb0a ("PageEditor.renamePage: bugfix added missing comment var") The comment isn't really missing, it may be empty if the user didn't provide one and in that case if you want to know what it was renamed from you have to look at the 'extra' field in the edit log, RecentChanges does that and displays "#01 Renamed from 'test'." or similar.
author Johannes Berg <johannes AT sipsolutions DOT net>
date Wed, 18 Jun 2008 15:13:37 +0200
parents 78f1b1c0affb
children fd63e84632df
rev   line source
1851
d4274455706a PageEditor.CopyPage log entry for pages which could not be saved by PageEditor.saveText
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1850
diff changeset
1 # -*- coding: iso-8859-1 -*-
0
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 - PageEditor class
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
4
1909
be140a589f11 improved some module docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1896
diff changeset
5 PageEditor is used for r/w access to a wiki page (edit, rename, delete operations).
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
6
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
7 TODO:
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
8 * See comments in Page.py, most apply here, too.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
9 * The editor code should be modularized so we will be able to use it for any
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
10 text/* mimetype data with some special features enabled depending on the
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
11 mimetype (e.g. enable wiki markup help when editing wiki mimetype).
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
12
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
13 @copyright: 2000-2004 by Juergen Hermann <jh@web.de>,
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1909
diff changeset
14 2005-2007 by MoinMoin:ThomasWaldmann,
1993
93877b7d87b9 fixing copyright headers:unified my name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1961
diff changeset
15 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
16 @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
17 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
18
1792
c907c2942372 Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
19 import os, time, codecs, errno
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20
2336
10be78f1fa97 Merge main.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2333 2286
diff changeset
21
3175
2a3a6cb34e45 pylint findings: fix some harmless stuff
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3168
diff changeset
22 from MoinMoin import caching, config, wikiutil, error
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
23 from MoinMoin.Page import Page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
24 from MoinMoin.widget import html
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
25 from MoinMoin.widget.dialog import Status
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
26 from MoinMoin.logfile import editlog, eventlog
2595
5e7b45489430 moved python2.3/2.4 compatibility code to MoinMoin.support.python_compatibility (thanks to Heinrich Wendel)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2469
diff changeset
27 from MoinMoin.support.python_compatibility import set
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
28 from MoinMoin.util import filesys, timefuncs, web
3175
2a3a6cb34e45 pylint findings: fix some harmless stuff
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3168
diff changeset
29 from MoinMoin.events import PageDeletedEvent, PageRenamedEvent, PageCopiedEvent, PageRevertedEvent
2396
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
30 from MoinMoin.events import PagePreSaveEvent, Abort, send_event
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2189
diff changeset
31 import MoinMoin.events.notification as notification
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
32
1140
3155f908de85 Refactored conflict markers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1069
diff changeset
33 # used for merging
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
34 conflict_markers = ("\n---- /!\\ '''Edit conflict - other version:''' ----\n",
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
35 "\n---- /!\\ '''Edit conflict - your version:''' ----\n",
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
36 "\n---- /!\\ '''End of edit conflict''' ----\n")
1140
3155f908de85 Refactored conflict markers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1069
diff changeset
37
3155f908de85 Refactored conflict markers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1069
diff changeset
38
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
39 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
40 ### Javascript code for editor page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
41 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43 # we avoid the "--" operator to make this XHTML happy!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
44 _countdown_js = """
194
722b8f648630 Use addLoadEvent instead of window.onload=..., move countdown JS to external file
Thomas Waldmann <tw@waldmann-edv.de>
parents: 191
diff changeset
45 %(countdown_script)s
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 <script type="text/javascript">
194
722b8f648630 Use addLoadEvent instead of window.onload=..., move countdown JS to external file
Thomas Waldmann <tw@waldmann-edv.de>
parents: 191
diff changeset
47 var countdown_timeout_min = %(lock_timeout)s
722b8f648630 Use addLoadEvent instead of window.onload=..., move countdown JS to external file
Thomas Waldmann <tw@waldmann-edv.de>
parents: 191
diff changeset
48 var countdown_lock_expire = "%(lock_expire)s"
722b8f648630 Use addLoadEvent instead of window.onload=..., move countdown JS to external file
Thomas Waldmann <tw@waldmann-edv.de>
parents: 191
diff changeset
49 var countdown_lock_mins = "%(lock_mins)s"
722b8f648630 Use addLoadEvent instead of window.onload=..., move countdown JS to external file
Thomas Waldmann <tw@waldmann-edv.de>
parents: 191
diff changeset
50 var countdown_lock_secs = "%(lock_secs)s"
722b8f648630 Use addLoadEvent instead of window.onload=..., move countdown JS to external file
Thomas Waldmann <tw@waldmann-edv.de>
parents: 191
diff changeset
51 addLoadEvent(countdown)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
52 </script>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57 ### PageEditor - Edit pages
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59 class PageEditor(Page):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
60 """ Editor for a wiki page. """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
62 # exceptions for .saveText()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63 class SaveError(error.Error):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64 pass
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
65 class RevertError(SaveError):
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
66 pass
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
67 class AccessDenied(SaveError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
68 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
69 class Immutable(AccessDenied):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
70 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
71 class NoAdmin(AccessDenied):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
72 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
73 class EmptyPage(SaveError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
74 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
75 class Unchanged(SaveError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
76 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
77 class EditConflict(SaveError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
78 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
79 class CouldNotLock(SaveError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
81
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
82 def __init__(self, request, page_name, **keywords):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
83 """ Create page editor object.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
84
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85 @param page_name: name of the page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86 @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
87 @keyword do_revision_backup: if 0, suppress making a page backup per revision
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
88 @keyword do_editor_backup: if 0, suppress saving of draft copies
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
89 @keyword uid_override: override user id and name (default None)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
90 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
91 Page.__init__(self, request, page_name, **keywords)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
92 self._ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94 self.do_revision_backup = keywords.get('do_revision_backup', 1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
95 self.do_editor_backup = keywords.get('do_editor_backup', 1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96 self.uid_override = keywords.get('uid_override', None)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
97
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
98 self.lock = PageLock(self)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
99
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100 def mergeEditConflict(self, origrev):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101 """ Try to merge current page version with new version the user tried to save
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103 @param origrev: the original revision the user was editing
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
104 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
105 @return: merge success status
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
106 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
107 from MoinMoin.util import diff3
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108 allow_conflicts = 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
109
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
110 # Get current editor text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111 savetext = self.get_raw_body()
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
112
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
113 # The original text from the revision the user was editing
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
114 original_text = Page(self.request, self.page_name, rev=origrev).get_raw_body()
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
115
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116 # The current revision someone else saved
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117 saved_text = Page(self.request, self.page_name).get_raw_body()
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
118
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119 # And try to merge all into one with edit conflict separators
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 verynewtext = diff3.text_merge(original_text, saved_text, savetext,
1140
3155f908de85 Refactored conflict markers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1069
diff changeset
121 allow_conflicts, *conflict_markers)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122 if verynewtext:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 self.set_raw_body(verynewtext)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 return True
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
125
779
9834dda36973 Added conflict icon in RecentChanges, refactored conflict handling in the code. Translators, esp. german translators!, there seems to be an outdated string. You will see it on the editing conflict.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 682
diff changeset
126 # this should never happen, except for empty pages
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
127 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
128
542
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
129 def sendconfirmleaving(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
130 """ Prevents moving away from the page without saving it. """
542
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
131 _ = self._
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
132 self.request.write(u'''\
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
133 <script type="text/javascript">
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
134 var flgChange = false;
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
135 function confirmleaving() {
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
136 if ( flgChange )
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
137 return "%s";
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
138 }
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
139 </script>
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
140 ''' % _("Your changes are not saved!"))
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
141
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
142 def sendEditor(self, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
143 """ Send the editor form page.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
144
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
145 @keyword preview: if given, show this text in preview mode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
146 @keyword staytop: don't go to #preview
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
147 @keyword comment: comment field (when preview is true)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
148 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
149 from MoinMoin import i18n
3629
bf72cc397f76 fix some ImportError handlers: SpellCheck is builtin. Don't hide import errors in wikiserverconfig.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
150 from MoinMoin.action import SpellCheck
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
151 request = self.request
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
152 form = request.form
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
153 _ = self._
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
154
199
4e9b5e9610da fixed editor preview throwing away page content for new pages
Thomas Waldmann <tw@waldmann-edv.de>
parents: 194
diff changeset
155 raw_body = ''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
156 msg = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
157 conflict_msg = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
158 edit_lock_message = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
159 preview = kw.get('preview', None)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
160 staytop = kw.get('staytop', 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
161
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
162 from MoinMoin.formatter.text_html import Formatter
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
163 request.formatter = Formatter(request, store_pagelinks=1)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
164
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
165 # check edit permissions
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
166 if not request.user.may.write(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
167 msg = _('You are not allowed to edit this page.')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
168 elif not self.isWritable():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
169 msg = _('Page is immutable!')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
170 elif self.rev:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
171 # Trying to edit an old version, this is not possible via
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
172 # the web interface, but catch it just in case...
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
173 msg = _('Cannot edit old revisions!')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
174 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
175 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
176 # try to acquire edit lock
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
177 ok, edit_lock_message = self.lock.acquire()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
178 if not ok:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
179 # failed to get the lock
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
180 if preview is not None:
36
eb3b18ffb28b fixed some english strings, better converter debugging msgs, move lineno anchors to formatter
Thomas Waldmann <tw@waldmann-edv.de>
parents: 33
diff changeset
181 edit_lock_message = _('The lock you held timed out. Be prepared for editing conflicts!'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
182 ) + "<br>" + edit_lock_message
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
183 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
184 msg = edit_lock_message
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
185 except OSError, err:
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: 1919
diff changeset
186 if err.errno == errno.ENAMETOOLONG:
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: 1919
diff changeset
187 msg = _("Page name is too long, try shorter 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: 1919
diff changeset
188 else:
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: 1919
diff changeset
189 raise
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
190
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
191 # Did one of the prechecks fail?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
192 if msg:
2967
a310264ad186 Added a few add_msg calls (by Federico Lorenzi).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2966
diff changeset
193 request.theme.add_msg(msg, "error")
a310264ad186 Added a few add_msg calls (by Federico Lorenzi).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2966
diff changeset
194 self.send_page()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
195 return
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
196
2707
2d93b9a28ea3 PageEditor.sendEditor: bug fix of emitting http_headers twice if edit_locking is set to 'lock x'
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2698
diff changeset
197 # Emmit http_headers after checks (send_page)
2d93b9a28ea3 PageEditor.sendEditor: bug fix of emitting http_headers twice if edit_locking is set to 'lock x'
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2698
diff changeset
198 request.disableHttpCaching(level=2)
2d93b9a28ea3 PageEditor.sendEditor: bug fix of emitting http_headers twice if edit_locking is set to 'lock x'
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2698
diff changeset
199 request.emit_http_headers()
2d93b9a28ea3 PageEditor.sendEditor: bug fix of emitting http_headers twice if edit_locking is set to 'lock x'
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2698
diff changeset
200
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
201 # check if we want to load a draft
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
202 use_draft = None
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
203 if 'button_load_draft' in form:
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
204 wanted_draft_timestamp = int(form.get('draft_ts', ['0'])[0])
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
205 if wanted_draft_timestamp:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
206 draft = self._load_draft()
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
207 if draft is not None:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
208 draft_timestamp, draft_rev, draft_text = draft
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
209 if draft_timestamp == wanted_draft_timestamp:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
210 use_draft = draft_text
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
211
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
212 # Check for draft / normal / preview submit
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
213 if use_draft is not None:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
214 title = _('Draft of "%(pagename)s"')
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
215 # Propagate original revision
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
216 rev = int(form['draft_rev'][0])
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
217 self.set_raw_body(use_draft, modified=1)
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
218 preview = use_draft
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
219 elif preview is None:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
220 title = _('Edit "%(pagename)s"')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
221 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
222 title = _('Preview of "%(pagename)s"')
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
223 # Propagate original revision
1682
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1640
diff changeset
224 rev = request.rev
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
225 self.set_raw_body(preview, modified=1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
226
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
227 # send header stuff
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
228 lock_timeout = self.lock.timeout / 60
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
229 lock_page = wikiutil.escape(self.page_name, quote=1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
230 lock_expire = _("Your edit lock on %(lock_page)s has expired!") % {'lock_page': lock_page}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
231 lock_mins = _("Your edit lock on %(lock_page)s will expire in # minutes.") % {'lock_page': lock_page}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
232 lock_secs = _("Your edit lock on %(lock_page)s will expire in # seconds.") % {'lock_page': lock_page}
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
233
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
234 # get request parameters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
235 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
236 text_rows = int(form['rows'][0])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
237 except StandardError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
238 text_rows = self.cfg.edit_rows
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
239 if request.user.valid:
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
240 text_rows = int(request.user.edit_rows)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
241
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
242 if preview is not None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
243 # Check for editing conflicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
244 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
245 # page does not exist, are we creating it?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
246 if rev:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
247 conflict_msg = _('Someone else deleted this page while you were editing!')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
248 elif rev != self.current_rev():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
249 conflict_msg = _('Someone else changed this page while you were editing!')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
250 if self.mergeEditConflict(rev):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
251 conflict_msg = _("""Someone else saved this page while you were editing!
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
252 Please review the page and save then. Do not save this page as it is!""")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
253 rev = self.current_rev()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
254 if conflict_msg:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
255 # We don't show preview when in conflict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
256 preview = None
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
257
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
258 elif self.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
259 # revision of existing page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
260 rev = self.current_rev()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
261 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
262 # page creation
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
263 rev = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
264
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
265 # Page editing is done using user language
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
266 request.setContentLanguage(request.lang)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
267
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
268 # Get the text body for the editor field.
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
269 # TODO: what about deleted pages? show the text of the last revision or use the template?
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
270 if preview is not None:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
271 raw_body = self.get_raw_body()
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
272 if use_draft:
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: 2877
diff changeset
273 request.theme.add_msg(_("[Content loaded from draft]"), 'info')
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
274 elif self.exists():
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
275 # If the page exists, we get the text from the page.
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
276 # TODO: maybe warn if template argument was ignored because the page exists?
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
277 raw_body = self.get_raw_body()
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
278 elif 'template' in form:
3490
af3460a4cb79 fix some typos in messages / comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3356
diff changeset
279 # If the page does not exist, we try to get the content from the template parameter.
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
280 template_page = wikiutil.unquoteWikiname(form['template'][0])
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
281 if request.user.may.read(template_page):
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
282 raw_body = Page(request, template_page).get_raw_body()
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
283 if raw_body:
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: 2877
diff changeset
284 request.theme.add_msg(_("[Content of new page loaded from %s]") % (template_page, ), 'info')
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
285 else:
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: 2877
diff changeset
286 request.theme.add_msg(_("[Template %s not found]") % (template_page, ), 'warning')
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
287 else:
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: 2877
diff changeset
288 request.theme.add_msg(_("[You may not read %s]") % (template_page, ), 'error')
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
289
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
290 # Make backup on previews - but not for new empty pages
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
291 if not use_draft and preview and raw_body:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
292 self._save_draft(raw_body, rev)
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
293
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
294 draft_message = None
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
295 loadable_draft = False
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
296 if preview is None:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
297 draft = self._load_draft()
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
298 if draft is not None:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
299 draft_timestamp, draft_rev, draft_text = draft
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
300 if draft_text != raw_body:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
301 loadable_draft = True
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
302 page_rev = rev
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
303 draft_timestamp_str = request.user.getFormattedDateTime(draft_timestamp)
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
304 draft_message = _(u"'''<<BR>>Your draft based on revision %(draft_rev)d (saved %(draft_timestamp_str)s) can be loaded instead of the current revision %(page_rev)d by using the load draft button - in case you lost your last edit somehow without saving it.''' A draft gets saved for you when you do a preview, cancel an edit or unsuccessfully save.", wiki=True) % locals()
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
305
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
306 # Setup status message
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
307 status = [kw.get('msg', ''), conflict_msg, edit_lock_message, draft_message]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
308 status = [msg for msg in status if msg]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
309 status = ' '.join(status)
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
310 status = Status(request, content=status)
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: 2877
diff changeset
311 request.theme.add_msg(status, "dialog")
3034
d0d9fbc0f0ee PEP8 whitespace fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2983
diff changeset
312
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
313 request.theme.send_title(
1776
fc75423e26a8 remove unneeded request param from page.split_title()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1716
diff changeset
314 title % {'pagename': self.split_title(), },
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
315 page=self,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
316 html_head=self.lock.locktype and (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
317 _countdown_js % {
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
318 'countdown_script': request.theme.externalScript('countdown'),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
319 'lock_timeout': lock_timeout,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
320 'lock_expire': lock_expire,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
321 'lock_mins': lock_mins,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
322 'lock_secs': lock_secs,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
323 }) or '',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
324 editor_mode=1,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
325 )
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
326
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
327 request.write(request.formatter.startContent("content"))
191
e5ca7fa46f2e fixed Page(Graphical)Editor so that template param doesnt destroy existing pages
Thomas Waldmann <tw@waldmann-edv.de>
parents: 148
diff changeset
328
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
329 # Generate default content for new pages
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
330 if not raw_body:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
331 raw_body = _('Describe %s here.') % (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
332
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
333 # send form
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
334 request.write('<form id="editor" method="post" action="%s/%s#preview" onSubmit="flgChange = false;">' % (
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
335 request.getScriptname(),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
336 wikiutil.quoteWikinameURL(self.page_name),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
337 ))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
338
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
339 # yet another weird workaround for broken IE6 (it expands the text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
340 # editor area to the right after you begin to type...). IE sucks...
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
341 # http://fplanque.net/2003/Articles/iecsstextarea/
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
342 request.write('<fieldset style="border:none;padding:0;">')
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
343
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
344 request.write(unicode(html.INPUT(type="hidden", name="action", value="edit")))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
345
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
346 # Send revision of the page our edit is based on
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
347 request.write('<input type="hidden" name="rev" value="%d">' % (rev, ))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
348
1573
1453513eaa7e use tickets for editing, cfg.edit_ticketing, make tickets more safe, invalidate old tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1565
diff changeset
349 # Create and send a ticket, so we can check the POST
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
350 request.write('<input type="hidden" name="ticket" value="%s">' % wikiutil.createTicket(request))
1573
1453513eaa7e use tickets for editing, cfg.edit_ticketing, make tickets more safe, invalidate old tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1565
diff changeset
351
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
352 # Save backto in a hidden input
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
353 backto = form.get('backto', [None])[0]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
354 if backto:
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
355 request.write(unicode(html.INPUT(type="hidden", name="backto", value=backto)))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
356
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
357 # button bar
3629
bf72cc397f76 fix some ImportError handlers: SpellCheck is builtin. Don't hide import errors in wikiserverconfig.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
358 button_spellcheck = '<input class="button" type="submit" name="button_spellcheck" value="%s" onClick="flgChange = false;">' % _('Check Spelling')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
359
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
360 save_button_text = _('Save Changes')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
361 cancel_button_text = _('Cancel')
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
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 if self.cfg.page_license_enabled:
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
364 request.write('<p><em>', _(
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
365 """By hitting '''%(save_button_text)s''' you put your changes under the %(license_link)s.
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
366 If you don't want that, hit '''%(cancel_button_text)s''' to cancel your changes.""", wiki=True) % {
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
367 'save_button_text': save_button_text,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
368 'cancel_button_text': cancel_button_text,
3269
398ab9187a50 getText calls: fix some percent=... args
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3175
diff changeset
369 'license_link': wikiutil.getLocalizedPage(request, self.cfg.page_license_page).link_to(request),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
370 }, '</em></p>')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
371
518
e779addaf39a partial fix for the gui switch button problem (at least it is not then when forced text is active)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
372
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
373 request.write('''
127
df23ca172546 warn using onBeforeUnload when trying to trash unsaved content, text editor only, todo: gui editor
Thomas Waldmann <tw@waldmann-edv.de>
parents: 126
diff changeset
374 <input class="button" type="submit" name="button_save" value="%s" onClick="flgChange = false;">
df23ca172546 warn using onBeforeUnload when trying to trash unsaved content, text editor only, todo: gui editor
Thomas Waldmann <tw@waldmann-edv.de>
parents: 126
diff changeset
375 <input class="button" type="submit" name="button_preview" value="%s" onClick="flgChange = false;">
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
376 ''' % (save_button_text, _('Preview'), ))
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
377
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
378 if not (request.cfg.editor_force and request.cfg.editor_default == 'text'):
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
379 request.write('''
518
e779addaf39a partial fix for the gui switch button problem (at least it is not then when forced text is active)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
380 <input id="switch2gui" style="display: none;" class="button" type="submit" name="button_switch" value="%s">
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
381 ''' % (_('GUI Mode'), ))
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
382
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
383 if loadable_draft:
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
384 request.write('''
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
385 <input class="button" type="submit" name="button_load_draft" value="%s" onClick="flgChange = false;">
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
386 <input type="hidden" name="draft_ts" value="%d">
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
387 <input type="hidden" name="draft_rev" value="%d">
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
388 ''' % (_('Load Draft'), draft_timestamp, draft_rev))
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
389
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
390 request.write('''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
391 %s
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
392 <input class="button" type="submit" name="button_cancel" value="%s">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
393 <input type="hidden" name="editor" value="text">
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
394 ''' % (button_spellcheck, cancel_button_text, ))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
395
3035
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
396 # Trivial Change-checkbox to the top of the page, shows up only if user has JavaScript enabled. It's "linked" with the bottom's box (checking one checks both)
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
397 if self.cfg.mail_enabled:
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
398 request.write('''
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
399 <script type="text/javascript">
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
400 <!--
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
401 function toggle_trivial(CheckedBox)
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
402 {
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
403 TrivialBoxes = document.getElementsByName("trivial");
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
404 for (var i = 0; i < TrivialBoxes.length; i++)
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
405 TrivialBoxes[i].checked = CheckedBox.checked;
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
406 }
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
407
3168
0b0b756908c1 fix using unique IDs for 'trivial change' checkboxes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3122
diff changeset
408 document.write('<input type="checkbox" name="trivial" id="chktrivialtop" value="1" %(checked)s onclick="toggle_trivial(this)">');
0b0b756908c1 fix using unique IDs for 'trivial change' checkboxes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3122
diff changeset
409 document.write('<label for="chktrivialtop">%(label)s</label>');
3035
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
410 //-->
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
411 </script> ''' % {
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
412 'checked': ('', 'checked')[form.get('trivial', ['0'])[0] == '1'],
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
413 'label': _("Trivial change"),
3035
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
414 })
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
415
2983
7b0aadb97d01 new antispam stuff: textchas (text CAPTCHAs), cleanup AttachFile handler (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2967
diff changeset
416 from MoinMoin.security.textcha import TextCha
7b0aadb97d01 new antispam stuff: textchas (text CAPTCHAs), cleanup AttachFile handler (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2967
diff changeset
417 request.write(TextCha(request).render())
7b0aadb97d01 new antispam stuff: textchas (text CAPTCHAs), cleanup AttachFile handler (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2967
diff changeset
418
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
419 # Add textarea with 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: 1870
diff changeset
420 self.sendconfirmleaving()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
421
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: 1870
diff changeset
422 lang = self.pi.get('language', request.cfg.language_default)
127
df23ca172546 warn using onBeforeUnload when trying to trash unsaved content, text editor only, todo: gui editor
Thomas Waldmann <tw@waldmann-edv.de>
parents: 126
diff changeset
423
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
424 request.write(
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
425 u'''\
2708
5092edd82058 bug fix for non css browsers like w3m: for input fields set size of textarea and text to cols="80"
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2707
diff changeset
426 <textarea id="editor-textarea" name="savetext" lang="%(lang)s" dir="%(dir)s" rows="%(rows)d" cols="80"
127
df23ca172546 warn using onBeforeUnload when trying to trash unsaved content, text editor only, todo: gui editor
Thomas Waldmann <tw@waldmann-edv.de>
parents: 126
diff changeset
427 onChange="flgChange = true;" onKeyPress="flgChange = true;">\
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
428 %(text)s\
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
429 </textarea>''' % {
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
430 'lang': lang,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
431 'dir': i18n.getDirection(lang),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
432 'rows': text_rows,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
433 'text': wikiutil.escape(raw_body)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
434 })
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
435
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
436 request.write("<p>")
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
437 request.write(_("Comment:"),
2708
5092edd82058 bug fix for non css browsers like w3m: for input fields set size of textarea and text to cols="80"
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2707
diff changeset
438 ' <input id="editor-comment" type="text" name="comment" value="%s" size="80" maxlength="200"'
127
df23ca172546 warn using onBeforeUnload when trying to trash unsaved content, text editor only, todo: gui editor
Thomas Waldmann <tw@waldmann-edv.de>
parents: 126
diff changeset
439 ' onChange="flgChange = true;" onKeyPress="flgChange = true;">' % (
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
440 wikiutil.escape(kw.get('comment', ''), 1), ))
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
441 request.write("</p>")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
442
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
443 # Category selection
3573
124d0ef138aa change page_*_regex processing, see docs/CHANGES (fixes Xapian category search for non-english)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3560
diff changeset
444 filterfn = self.cfg.cache.page_category_regexact.search
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: 1919
diff changeset
445 cat_pages = request.rootpage.getPageList(filter=filterfn)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
446 cat_pages.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
447 cat_pages = [wikiutil.pagelinkmarkup(p) for p in cat_pages]
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
448 cat_pages.insert(0, ('', _('<No addition>')))
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
449 request.write("<p>")
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
450 request.write(_('Add to: %(category)s') % {
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
451 'category': unicode(web.makeSelection('category', cat_pages)),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
452 })
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
453
18
316340dd9a7f remove subscribe icon in classic when no mail is enabled. fix check for sendmail.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
454 if self.cfg.mail_enabled:
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
455 request.write('''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
456 &nbsp;
3035
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
457
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
458 <input type="checkbox" name="trivial" id="chktrivial" value="1" %(checked)s onclick="toggle_trivial(this)">
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
459 <label for="chktrivial">%(label)s</label>
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
460
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
461 ''' % {
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
462 'checked': ('', 'checked')[form.get('trivial', ['0'])[0] == '1'],
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
463 'label': _("Trivial change"),
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
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
466 request.write('''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
467 &nbsp;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
468 <input type="checkbox" name="rstrip" id="chkrstrip" value="1" %(checked)s>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
469 <label for="chkrstrip">%(label)s</label>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
470 ''' % {
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
471 'checked': ('', 'checked')[form.get('rstrip', ['0'])[0] == '1'],
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
472 'label': _('Remove trailing whitespace from each line')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
473 })
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
474 request.write("</p>")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
475
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
476 badwords_re = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
477 if preview is not None:
3629
bf72cc397f76 fix some ImportError handlers: SpellCheck is builtin. Don't hide import errors in wikiserverconfig.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
478 if 'button_spellcheck' in form or 'button_newwords' in form:
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
479 badwords, badwords_re, msg = SpellCheck.checkSpelling(self, request, own_form=0)
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
480 request.write("<p>%s</p>" % msg)
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
481 request.write('</fieldset>')
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
482 request.write("</form>")
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
483
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
484 # QuickHelp originally by Georg Mischler <schorsch@lightingwiki.com>
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: 1870
diff changeset
485 markup = self.pi['format'] or request.cfg.default_markup
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
486 quickhelp = request.cfg.editor_quickhelp.get(markup, "")
526
d0dba03190b6 cfg.editor_quickhelp to make quickhelp work correctly and configurably for default markup at least
Thomas Waldmann <tw@waldmann-edv.de>
parents: 518
diff changeset
487 if quickhelp:
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
488 request.write(request.formatter.div(1, id="editor-help"))
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
489 request.write(_(quickhelp, wiki=True))
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
490 request.write(request.formatter.div(0))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
491
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
492 if preview is not None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
493 if staytop:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
494 content_id = 'previewbelow'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
495 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
496 content_id = 'preview'
1777
ed44b93599b5 remove unneeded request param from page.send_page()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1776
diff changeset
497 self.send_page(content_id=content_id, content_only=1, hilite_re=badwords_re)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
498
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
499 request.write(request.formatter.endContent())
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
500 request.theme.send_footer(self.page_name)
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
501 request.theme.send_closing_html()
617
cf420addd95c removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
502
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
503 def sendCancel(self, newtext, rev):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
504 """ User clicked on Cancel button.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
505 If edit locking is active, delete the current lock file.
1916
d41e6ef31c0e PageEditor.copyPage: write access checked on old page instead of the copied one
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1909
diff changeset
506
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
507 @param newtext: the edited text (which has been cancelled)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
508 @param rev: not used!?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
509 """
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
510 request = self.request
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
511 _ = self._
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
512 self._save_draft(newtext, rev) # shall we really save a draft on CANCEL?
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
513 self.lock.release()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
514
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
515 backto = request.form.get('backto', [None])[0]
3303
b6681bd81cdb use a proper redirect for backto so that the URL isn't bogus
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3269
diff changeset
516 if backto:
b6681bd81cdb use a proper redirect for backto so that the URL isn't bogus
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3269
diff changeset
517 pg = Page(request, backto)
b6681bd81cdb use a proper redirect for backto so that the URL isn't bogus
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3269
diff changeset
518 request.http_redirect(pg.url(request, relative=False))
b6681bd81cdb use a proper redirect for backto so that the URL isn't bogus
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3269
diff changeset
519 else:
b6681bd81cdb use a proper redirect for backto so that the URL isn't bogus
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3269
diff changeset
520 request.theme.add_msg(_('Edit was cancelled.'), "error")
3305
dc56d314cc92 fix my redirect backto commit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3303
diff changeset
521 self.send_page()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
522
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
523 def copyPage(self, newpagename, comment=None):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
524 """ Copy the current version of the page (keeping the backups, logs and attachments).
1916
d41e6ef31c0e PageEditor.copyPage: write access checked on old page instead of the copied one
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1909
diff changeset
525
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
526 @param comment: Comment given by user
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
527 @rtype: unicode
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
528 @return: success flag, error message
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
529 """
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
530 request = self.request
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
531 _ = self._
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
532
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
533 if not newpagename:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
534 return False, _("You can't copy to an empty pagename.")
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
535
1896
1de612a8c553 PageEditor: CopyPage bug fixed check write rights
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1895
diff changeset
536 if not self.request.user.may.write(newpagename):
1de612a8c553 PageEditor: CopyPage bug fixed check write rights
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1895
diff changeset
537 return False, _('You are not allowed to copy this page!')
1916
d41e6ef31c0e PageEditor.copyPage: write access checked on old page instead of the copied one
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1909
diff changeset
538
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
539 newpage = PageEditor(request, newpagename)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
540
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
541 pageexists_error = _("""'''A page with the name {{{'%s'}}} already exists.'''
2830
c4ab7c81146d Fixed XSS issue in RenamePage/DeletePage action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2754
diff changeset
542
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
543 Try a different name.""", wiki=True) % (wikiutil.escape(newpagename), )
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
544
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
545 # Check whether a page with the new name already exists
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
546 if newpage.exists(includeDeleted=1):
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
547 return False, pageexists_error
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
548
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
549 # Get old page text
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
550 savetext = self.get_raw_body()
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
551
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
552 oldpath = self.getPagePath(check_create=0)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
553 newpath = newpage.getPagePath(check_create=0)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
554
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
555 # Copy page
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
556 # NOTE: might fail if another process created newpagename just
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
557 try:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
558 filesys.copytree(oldpath, newpath)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
559 self.error = None
1851
d4274455706a PageEditor.CopyPage log entry for pages which could not be saved by PageEditor.saveText
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1850
diff changeset
560 if not comment:
d4274455706a PageEditor.CopyPage log entry for pages which could not be saved by PageEditor.saveText
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1850
diff changeset
561 comment = u"## page was copied from %s" % self.page_name
3042
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3035
diff changeset
562 savetext = u"## page was copied from %s\n%s" % (self.page_name, savetext)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3035
diff changeset
563 Page.__init__(self, request, newpagename)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3035
diff changeset
564 self._write_file(savetext, "SAVENEW", comment)
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
565
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
566 event = PageCopiedEvent(request, newpage, self, comment)
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
567 send_event(event)
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
568
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
569 return True, None
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
570 except OSError, err:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
571 # Try to understand what happened. Maybe its better to check
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
572 # the error code, but I just reused the available code above...
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
573 if newpage.exists(includeDeleted=1):
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
574 return False, pageexists_error
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
575 else:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
576 return False, _('Could not copy page because of file system error: %s.') % unicode(err)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
577
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
578 def renamePage(self, newpagename, comment=None):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
579 """ Rename the current version of the page (making a backup before deletion
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
580 and keeping the backups, logs and attachments).
1916
d41e6ef31c0e PageEditor.copyPage: write access checked on old page instead of the copied one
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1909
diff changeset
581
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
582 @param comment: Comment given by user
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
583 @rtype: unicode
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
584 @return: success flag, error message
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
585 """
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
586 request = self.request
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
587 _ = self._
1845
6ccc22836dd1 PageEditor.renamePage: added acl raise condition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1844
diff changeset
588
1849
ff8a6ed6d7aa revert changeset 1846:ca2c9a7f06c6
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1846
diff changeset
589 if not (request.user.may.delete(self.page_name)
ff8a6ed6d7aa revert changeset 1846:ca2c9a7f06c6
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1846
diff changeset
590 and request.user.may.write(newpagename)):
1845
6ccc22836dd1 PageEditor.renamePage: added acl raise condition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1844
diff changeset
591 msg = _('You are not allowed to rename this page!')
6ccc22836dd1 PageEditor.renamePage: added acl raise condition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1844
diff changeset
592 raise self.AccessDenied, msg
6ccc22836dd1 PageEditor.renamePage: added acl raise condition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1844
diff changeset
593
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
594 if not newpagename:
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
595 return False, _("You can't rename to an empty pagename.")
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
596
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
597 newpage = PageEditor(request, newpagename)
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
598
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
599 pageexists_error = _("""'''A page with the name {{{'%s'}}} already exists.'''
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
600
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
601 Try a different name.""", wiki=True) % (wikiutil.escape(newpagename), )
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
602
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
603 # Check whether a page with the new name already exists
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
604 if newpage.exists(includeDeleted=1):
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
605 return False, pageexists_error
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
606
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
607 # Get old page text
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
608 savetext = self.get_raw_body()
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
609
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
610 oldpath = self.getPagePath(check_create=0)
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
611 newpath = newpage.getPagePath(check_create=0)
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
612
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
613 # Rename page
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
614
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
615 # NOTE: might fail if another process created newpagename just
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
616 # NOW, while you read this comment. Rename is atomic for files -
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
617 # but for directories, rename will fail if the directory
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
618 # exists. We should have global edit-lock to avoid this.
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
619 # See http://docs.python.org/lib/os-file-dir.html
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
620 try:
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
621 os.rename(oldpath, newpath)
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
622 self.error = None
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
623 # Save page text with a comment about the old name
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
624 savetext = u"## page was renamed from %s\n%s" % (self.page_name, savetext)
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
625 newpage.saveText(savetext, 0, comment=comment, extra=self.page_name, action='SAVE/RENAME', notify=False)
1828
09e81597c7ce PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1816
diff changeset
626 # delete pagelinks
1894
5ae7a098f6e4 RenamePage bugfix: clean caches of the new page (there is nothing at the old place anyway)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1880
diff changeset
627 arena = newpage
1828
09e81597c7ce PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1816
diff changeset
628 key = 'pagelinks'
09e81597c7ce PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1816
diff changeset
629 cache = caching.CacheEntry(request, arena, key, scope='item')
09e81597c7ce PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1816
diff changeset
630 cache.remove()
09e81597c7ce PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1816
diff changeset
631
09e81597c7ce PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1816
diff changeset
632 # clean the cache
09e81597c7ce PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1816
diff changeset
633 for formatter_name in self.cfg.caching_formats:
1894
5ae7a098f6e4 RenamePage bugfix: clean caches of the new page (there is nothing at the old place anyway)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1880
diff changeset
634 arena = newpage
1828
09e81597c7ce PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1816
diff changeset
635 key = formatter_name
09e81597c7ce PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1816
diff changeset
636 cache = caching.CacheEntry(request, arena, key, scope='item')
09e81597c7ce PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1816
diff changeset
637 cache.remove()
1478
53e9c1db5ace support for page/attachment removal and renaming (preliminary commit to show activity, needs more testing)
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1473
diff changeset
638
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
639 event = PageRenamedEvent(request, newpage, self, comment)
2329
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
640 send_event(event)
1478
53e9c1db5ace support for page/attachment removal and renaming (preliminary commit to show activity, needs more testing)
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1473
diff changeset
641
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
642 return True, None
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
643 except OSError, err:
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
644 # Try to understand what happened. Maybe its better to check
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
645 # the error code, but I just reused the available code above...
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
646 if newpage.exists(includeDeleted=1):
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
647 return False, pageexists_error
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
648 else:
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
649 return False, _('Could not rename page because of file system error: %s.') % unicode(err)
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
650
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
651
3353
8e615ef236e2 allow saving a comment when reverting
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3305
diff changeset
652 def revertPage(self, revision, comment=u''):
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
653 """ Reverts page to the given revision
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
654
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
655 @param revision: revision to revert to
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
656 @type revision: int
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
657
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
658 """
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
659 _ = self.request.getText
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
660
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
661 if not self.request.user.may.revert(self.page_name):
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3353
diff changeset
662 # no real message necessary, cannot happen if
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3353
diff changeset
663 # user doesn't try to exploit us
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3353
diff changeset
664 raise self.RevertError('not allowed')
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
665 elif revision is None:
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3353
diff changeset
666 # see above
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3353
diff changeset
667 raise self.RevertError('cannot revert to current rev')
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
668 else:
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
669 revstr = '%08d' % revision
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
670 pg = Page(self.request, self.page_name, rev=revision)
3353
8e615ef236e2 allow saving a comment when reverting
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3305
diff changeset
671 msg = self.saveText(pg.get_raw_body(), 0, extra=revstr, action="SAVE/REVERT", notify=False, comment=comment)
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
672
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
673 # Remove cache entry (if exists)
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
674 pg = Page(self.request, self.page_name)
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
675 key = self.request.form.get('key', ['text_html'])[0]
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
676 caching.CacheEntry(self.request, pg, key, scope='item').remove()
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
677 caching.CacheEntry(self.request, pg, "pagelinks", scope='item').remove()
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
678
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
679 # Notify observers
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
680 e = PageRevertedEvent(self.request, self.page_name, revision, revstr)
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
681 send_event(e)
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
682
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
683 return msg
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
684
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
685 def deletePage(self, comment=None):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
686 """ Delete the current version of the page (making a backup before deletion
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
687 and keeping the backups, logs and attachments).
1916
d41e6ef31c0e PageEditor.copyPage: write access checked on old page instead of the copied one
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1909
diff changeset
688
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
689 @param comment: Comment given by user
148
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
690 @rtype: unicode
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
691 @return: success flag, error message
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
692 """
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
693 request = self.request
148
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
694 _ = self._
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
695 success = True
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
696 if not (request.user.may.write(self.page_name)
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
697 and request.user.may.delete(self.page_name)):
1334
a4efeab7a10f Added security check to PageEditor.deletePage.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1317
diff changeset
698 msg = _('You are not allowed to delete this page!')
a4efeab7a10f Added security check to PageEditor.deletePage.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1317
diff changeset
699 raise self.AccessDenied, msg
a4efeab7a10f Added security check to PageEditor.deletePage.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1317
diff changeset
700
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
701 try:
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
702 msg = self.saveText(u"deleted\n", 0, comment=comment or u'', deleted=True, notify=False)
148
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
703 msg = msg.replace(
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
704 _("Thank you for your changes. Your attention to detail is appreciated."),
2830
c4ab7c81146d Fixed XSS issue in RenamePage/DeletePage action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2754
diff changeset
705 _('Page "%s" was successfully deleted!') % (wikiutil.escape(self.page_name), ))
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
706
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
707 event = PageDeletedEvent(request, self, comment)
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
708 send_event(event)
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
709
148
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
710 except self.SaveError, message:
1844
58ebb64243cc added TODO for error handling in PageEditor
tw@server.firma.waldmann-edv.de
parents: 1832
diff changeset
711 # XXX do not only catch base class SaveError here, but
58ebb64243cc added TODO for error handling in PageEditor
tw@server.firma.waldmann-edv.de
parents: 1832
diff changeset
712 # also the derived classes, so we can give better err msgs
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
713 success = False
383
1c86e97448fa DeletePage: fix uninitialized msg attribute in case of SaveError exception
Thomas Waldmann <tw@waldmann-edv.de>
parents: 199
diff changeset
714 msg = "SaveError has occured in PageEditor.deletePage. We need locking there."
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
715
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
716 # delete pagelinks
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
717 arena = self
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
718 key = 'pagelinks'
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
719 cache = caching.CacheEntry(request, arena, key, scope='item')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
720 cache.remove()
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 # clean the cache
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
723 for formatter_name 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
724 arena = self
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
725 key = formatter_name
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
726 cache = caching.CacheEntry(request, arena, key, scope='item')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
727 cache.remove()
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
728 return success, msg
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
729
883
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
730 def _get_local_timestamp(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
731 """ Returns the string that can be used by the TIME substitution.
883
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
732
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
733 @return: str with a timestamp in it
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
734 """
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
735
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
736 now = time.time()
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
737 # default: UTC
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
738 zone = "Z"
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: 1919
diff changeset
739 u = self.request.user
883
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
740
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
741 # setup the timezone
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: 1919
diff changeset
742 if u.valid and u.tz_offset:
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: 1919
diff changeset
743 tz = u.tz_offset
883
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
744 # round to minutes
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
745 tz -= tz % 60
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
746 minutes = tz / 60
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
747 hours = minutes / 60
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
748 minutes -= hours * 60
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
749
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
750 # construct the offset
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
751 zone = "%+0.2d%02d" % (hours, minutes)
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
752 # correct the time by the offset we've found
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
753 now += tz
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
754
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
755 return time.strftime("%Y-%m-%dT%H:%M:%S", timefuncs.tmtuple(now)) + zone
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
756
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
757 def _expand_variables(self, text):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
758 """ Expand @VARIABLE@ in `text`and return the expanded text.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
759
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
760 @param text: current text of wikipage
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
761 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
762 @return: new text of wikipage, variables replaced
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
763 """
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1792
diff changeset
764 # TODO: Allow addition of variables via wikiconfig or a global wiki dict.
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
765 request = self.request
883
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
766 now = self._get_local_timestamp()
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: 1919
diff changeset
767 u = request.user
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: 1919
diff changeset
768 signature = u.signature()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
769 variables = {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
770 'PAGE': self.page_name,
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
771 'TIME': "<<DateTime(%s)>>" % now,
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
772 'DATE': "<<Date(%s)>>" % now,
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: 1919
diff changeset
773 'ME': u.name,
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
774 'USERNAME': signature,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
775 'USER': "-- %s" % signature,
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
776 'SIG': "-- %s <<DateTime(%s)>>" % (signature, now),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
777 }
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
778
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: 1919
diff changeset
779 if u.valid and u.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: 1919
diff changeset
780 if u.email:
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
781 variables['MAILTO'] = "<<MailTo(%s)>>" % u.email
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
782 # Users can define their own variables via
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
783 # UserHomepage/MyDict, which override the default variables.
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: 1919
diff changeset
784 userDictPage = u.name + "/MyDict"
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
785 if request.dicts.has_dict(userDictPage):
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
786 variables.update(request.dicts.dict(userDictPage))
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
787
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
788 for name in variables:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
789 text = text.replace('@%s@' % name, variables[name])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
790 return text
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
791
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
792 def normalizeText(self, text, **kw):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
793 """ Normalize text
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 Make sure text uses '\n' line endings, and has a trailing
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
796 newline. Strip whitespace on end of lines if needed.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
797
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
798 You should normalize any text you enter into a page, for
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
799 example, when getting new text from the editor, or when setting
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
800 new text manually.
1916
d41e6ef31c0e PageEditor.copyPage: write access checked on old page instead of the copied one
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1909
diff changeset
801
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
802 @param text: text to normalize (unicode)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
803 @keyword stripspaces: if 1, strip spaces from text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
804 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
805 @return: normalized text
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
806 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
807 if text:
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
808 lines = text.splitlines()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
809 # Strip trailing spaces if needed
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
810 if kw.get('stripspaces', 0):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
811 lines = [line.rstrip() for line in lines]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
812 # Add final newline if not present, better for diffs (does
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
813 # not include former last line when just adding text to
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
814 # bottom; idea by CliffordAdams)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
815 if not lines[-1] == u'':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
816 # '' will make newline after join
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
817 lines.append(u'')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
818
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
819 text = u'\n'.join(lines)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
820 return text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
821
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
822 def _save_draft(self, text, rev, **kw):
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
823 """ Save an editor backup to the drafts cache arena.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
824
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
825 @param text: draft text of the page
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
826 (if None, the draft gets removed from the cache)
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
827 @param rev: the revision of the page this draft is based on
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 476
diff changeset
828 @param kw: no keyword args used currently
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
829 """
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
830 request = self.request
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
831 if not request.user.valid or not self.do_editor_backup:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
832 return None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
833
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
834 arena = 'drafts'
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
835 key = request.user.id
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
836 cache = caching.CacheEntry(request, arena, key, scope='wiki', use_pickle=True)
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
837 if cache.exists():
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
838 cache_data = cache.content()
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
839 else:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
840 cache_data = {}
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
841 pagename = self.page_name
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
842 if text is None:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
843 try:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
844 del cache_data[pagename]
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
845 except:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
846 pass
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
847 else:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
848 timestamp = int(time.time())
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
849 cache_data[pagename] = (timestamp, rev, text)
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
850 cache.update(cache_data)
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
851
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
852 def _load_draft(self):
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
853 """ Get a draft from the drafts cache arena.
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
854
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
855 @rtype: unicode
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
856 @return: draft text or None
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
857 """
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
858 request = self.request
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
859 if not request.user.valid:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
860 return None
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
861
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
862 arena = 'drafts'
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
863 key = request.user.id
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
864 cache = caching.CacheEntry(request, arena, key, scope='wiki', 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
865 pagename = self.page_name
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
866 try:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
867 cache_data = cache.content()
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
868 return cache_data.get(pagename)
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
869 except caching.CacheError:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
870 return None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
871
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
872 def copy_underlay_page(self):
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
873 # renamed from copypage to avoid conflicts with copyPage
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
874 """ Copy a page from underlay directory to page directory """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
875 src = self.getPagePath(use_underlay=1, check_create=0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
876 dst = self.getPagePath(use_underlay=0, check_create=0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
877 if src and dst and src != dst and os.path.exists(src):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
878 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
879 os.rmdir(dst) # simply remove empty dst dirs
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
880 # XXX in fact, we should better remove anything we regard as an
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
881 # empty page, maybe also if there is also an edit-lock or
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
882 # empty cache. revisions subdir...
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
883 except:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
884 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
885 if not os.path.exists(dst):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
886 filesys.copytree(src, dst)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
887 self.reset() # reinit stuff
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
888
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
889 def _write_file(self, text, action='SAVE', comment=u'', extra=u'', deleted=False):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
890 """ Write the text to the page file (and make a backup of old page).
1916
d41e6ef31c0e PageEditor.copyPage: write access checked on old page instead of the copied one
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1909
diff changeset
891
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
892 @param text: text to save for this page
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
893 @param deleted: if True, then don't write page content (used by deletePage)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
894 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
895 @return: mtime_usec of new page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
896 """
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
897 request = self.request
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
898 _ = 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: 1870
diff changeset
899 was_deprecated = self.pi.get('deprecated', False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
900
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
901 self.copy_underlay_page()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
902
1162
3e2b4beb65ed Moved conflict state detection again into another function.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1157
diff changeset
903 # remember conflict state
3e2b4beb65ed Moved conflict state detection again into another function.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1157
diff changeset
904 self.setConflict(wikiutil.containsConflictMarker(text))
3e2b4beb65ed Moved conflict state detection again into another function.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1157
diff changeset
905
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
906 # Write always on the standard directory, never change the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
907 # underlay directory copy!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
908 pagedir = self.getPagePath(use_underlay=0, check_create=0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
909
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
910 revdir = os.path.join(pagedir, 'revisions')
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
911 cfn = os.path.join(pagedir, 'current')
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
912 clfn = os.path.join(pagedir, 'current-locked')
2841
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
913 cltfn = os.path.join(pagedir, 'current-locked.tmp')
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
914
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
915 # !!! these log objects MUST be created outside the locked area !!!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
916
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
917 # The local log should be the standard edit log, not the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
918 # underlay copy log!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
919 pagelog = self.getPagePath('edit-log', use_underlay=0, isfile=1)
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
920 llog = editlog.EditLog(request, filename=pagelog,
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
921 uid_override=self.uid_override)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
922 # Open the global log
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
923 glog = editlog.EditLog(request, uid_override=self.uid_override)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
924
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
925 if not os.path.exists(pagedir): # new page, create and init pagedir
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
926 os.mkdir(pagedir)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
927 if not os.path.exists(revdir):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
928 os.mkdir(revdir)
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
929 f = file(cfn, 'w')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
930 f.write('%08d\n' % 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
931 f.close()
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
932
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
933 got_lock = False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
934 retry = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
935
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
936 try:
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
937 while not got_lock and retry < 100:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
938 retry += 1
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
939 try:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
940 filesys.rename(cfn, clfn)
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
941 got_lock = True
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
942 except OSError, err:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
943 got_lock = False
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
944 if err.errno == 2: # there was no 'current' file
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
945 time.sleep(0.1)
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
946 else:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
947 raise self.CouldNotLock, _("Page could not get locked. Unexpected error (errno=%d).") % err.errno
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
948
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
949 if not got_lock:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
950 raise self.CouldNotLock, _("Page could not get locked. Missing 'current' file?")
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
951
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
952 # increment rev number of current(-locked) page
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
953 f = file(clfn)
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
954 revstr = f.read()
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
955 f.close()
2841
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
956 try:
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
957 rev = int(revstr)
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
958 except ValueError, err:
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
959 raise self.SaveError, _("Unable to determine current page revision from the 'current' file. The page %s is damaged and cannot be edited right now.") % self.page_name
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
960
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
961 if not was_deprecated:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
962 if self.do_revision_backup or rev == 0:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
963 rev += 1
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
964 revstr = '%08d' % rev
2841
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
965 # write the current page rev to a temporary file
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
966 try:
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
967 f = file(cltfn, 'w')
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
968 f.write(revstr+'\n')
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
969 f.close()
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
970 except IOError, err:
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
971 try:
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
972 os.remove(cltfn)
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
973 except:
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
974 pass # we don't care for errors in the os.remove
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
975 # throw a nicer exception
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
976 if err.errno == errno.ENOSPC:
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
977 raise self.SaveError, _("Cannot save page %s, no storage space left.") % self.page_name
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
978 else:
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
979 raise self.SaveError, _("An I/O error occurred while saving page %s (errno=%d)") % (self.page_name, err.errno)
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
980 # atomically put it in place (except on windows)
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
981 else:
93be75db2051 handle out-of-space errors in PageEditor and caching, avoid 'current' corruption (thanks to TheAnarcat)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2830
diff changeset
982 filesys.rename(cltfn, clfn)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
983
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
984 if not deleted:
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
985 # save to page file
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
986 pagefile = os.path.join(revdir, revstr)
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
987 f = codecs.open(pagefile, 'wb', config.charset)
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
988 # Write the file using text/* mime type
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
989 f.write(self.encodeTextMimeType(text))
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
990 f.close()
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
991 mtime_usecs = wikiutil.timestamp2version(os.path.getmtime(pagefile))
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
992 # set in-memory content
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
993 self.set_raw_body(text)
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
994 else:
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
995 mtime_usecs = wikiutil.timestamp2version(time.time())
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
996 # set in-memory content
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
997 self.set_raw_body(None)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
998
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
999 # reset page object
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1000 self.reset()
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1001
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1002 # write the editlog entry
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1003 # for now simply make 2 logs, better would be some multilog stuff maybe
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1004 if self.do_revision_backup:
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
1005 # do not globally log edits with no revision backup
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1006 # if somebody edits a deprecated page, log it in global log, but not local log
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1007 glog.add(request, mtime_usecs, rev, action, self.page_name, None, extra, comment)
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1008 if not was_deprecated and self.do_revision_backup:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1009 # if we did not create a new revision number, do not locally log it
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1010 llog.add(request, mtime_usecs, rev, action, self.page_name, None, extra, comment)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1011 finally:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1012 if got_lock:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1013 filesys.rename(clfn, cfn)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1014
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1015 # add event log entry
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1016 elog = eventlog.EventLog(request)
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1017 elog.add(request, 'SAVEPAGE', {'pagename': self.page_name}, 1, mtime_usecs)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1018
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1019 return mtime_usecs, rev
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1020
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1021 def saveText(self, newtext, rev, **kw):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1022 """ Save new text for a page.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1023
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1024 @param newtext: text to save for this page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1025 @param rev: revision of the page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1026 @keyword trivial: trivial edit (default: 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1027 @keyword extra: extra info field (e.g. for SAVE/REVERT with revno)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1028 @keyword comment: comment field (when preview is true)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1029 @keyword action: action for editlog (default: SAVE)
1478
53e9c1db5ace support for page/attachment removal and renaming (preliminary commit to show activity, needs more testing)
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1473
diff changeset
1030 @keyword index: needs indexing, not already handled (default: 1)
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1031 @keyword deleted: if True, then don't save page content (used by DeletePage, default: False)
2333
88c539512520 s/page_edit/notify
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2330
diff changeset
1032 @keyword notify: if False (default: True), don't send a PageChangedEvent
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1033 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1034 @return: error msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1035 """
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1036 request = self.request
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1037 _ = self._
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
1038 self._save_draft(newtext, rev, **kw)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1039 action = kw.get('action', 'SAVE')
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1040 deleted = kw.get('deleted', False)
2333
88c539512520 s/page_edit/notify
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2330
diff changeset
1041 notify = kw.get('notify', True)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1042
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1043 #!!! need to check if we still retain the lock here
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1044 #!!! rev check is not enough since internal operations use "0"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1045
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1046 # expand variables, unless it's a template or form page
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1047 if not wikiutil.isTemplatePage(request, 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
1048 newtext = self._expand_variables(newtext)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1049
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1050 msg = ""
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1051 if not request.user.may.save(self, newtext, rev, **kw):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1052 msg = _('You are not allowed to edit this page!')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1053 raise self.AccessDenied, msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1054 elif not self.isWritable():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1055 msg = _('Page is immutable!')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1056 raise self.Immutable, msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1057 elif not newtext:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1058 msg = _('You cannot save empty pages.')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1059 raise self.EmptyPage, msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1060 elif rev != 0 and rev != self.current_rev():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1061 # check if we already saved that page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1062 other = False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1063 pagelog = self.getPagePath('edit-log', use_underlay=0, isfile=1)
1565
6eae21f5f3f9 fix UnboundLocalError (port to 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1556
diff changeset
1064 next_line = None
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1065 for line in editlog.EditLog(request, pagelog).reverse():
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1066 if int(line.rev) == int(rev):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1067 break
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1068 if not line.is_from_current_user(request):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1069 other = True
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1070 next_line = line
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1071 if next_line and next_line.is_from_current_user(request):
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1072 saved_page = Page(request, self.page_name, rev=int(next_line.rev))
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1073 if newtext == saved_page.get_raw_body():
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1074 msg = _("You already saved this page!")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1075 return msg
779
9834dda36973 Added conflict icon in RecentChanges, refactored conflict handling in the code. Translators, esp. german translators!, there seems to be an outdated string. You will see it on the editing conflict.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 682
diff changeset
1076 else:
9834dda36973 Added conflict icon in RecentChanges, refactored conflict handling in the code. Translators, esp. german translators!, there seems to be an outdated string. You will see it on the editing conflict.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 682
diff changeset
1077 msg = _("You already edited this page! Please do not use the back button.")
9834dda36973 Added conflict icon in RecentChanges, refactored conflict handling in the code. Translators, esp. german translators!, there seems to be an outdated string. You will see it on the editing conflict.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 682
diff changeset
1078 raise self.EditConflict, msg
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1079
785
f3c1ea6ef86e Refactored conflict messages, removed link to diff because it is not necessary for a 3-way merge.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 779
diff changeset
1080 msg = _("""Someone else saved this page while you were editing!
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1081 Please review the page and save then. Do not save this page as it is!""")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1082
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1083 raise self.EditConflict, msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1084 elif newtext == self.get_raw_body():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1085 msg = _('You did not change the page content, not saved!')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1086 raise self.Unchanged, msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1087 else:
747
e178ada80ead moved wikiacl.py to security/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
1088 from MoinMoin.security import parseACL
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1089 # Get current ACL and compare to new ACL from newtext. If
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1090 # they are not the sames, the user must have admin
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1091 # rights. This is a good place to update acl cache - instead
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1092 # of wating for next request.
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1093 acl = self.getACL(request)
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1094 if (not request.user.may.admin(self.page_name) and
2189
a37491dbb605 Correctly check the ACL lists in the PageEditor for the admin check instead of the wrapping objects, reordered some comments and doc strings, return None instead of 0 in may if applicable. Should be ported to 1.7.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2109
diff changeset
1095 parseACL(request, newtext).acl != acl.acl and
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1096 action != "SAVE/REVERT"):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1097 msg = _("You can't change ACLs on this page since you have no admin rights on it!")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1098 raise self.NoAdmin, msg
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1099
2396
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1100 presave = PagePreSaveEvent(request, self, newtext)
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1101 results = send_event(presave)
2399
245181ec9fe2 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2396
diff changeset
1102
2396
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1103 for result in results:
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1104 if isinstance(result, Abort):
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1105 # XXX: this should return a list of messages to the sorrounding context
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1106 # XXX: rather than dumbly concatenate them. Fix in the future.
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1107 msg = msg + result.reason
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1108
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1109 # save only if no error occurred (msg is empty) and no abort has been requested
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1110 if not msg:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1111 # set success msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1112 msg = _("Thank you for your changes. Your attention to detail is appreciated.")
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1113
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
1114 # determine action for edit log
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1115 if action == 'SAVE' and not self.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1116 action = 'SAVENEW'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1117 comment = kw.get('comment', u'')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1118 extra = kw.get('extra', u'')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1119 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
1120 # write the page file
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1121 mtime_usecs, rev = self._write_file(newtext, action, comment, extra, deleted=deleted)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1122 self.clean_acl_cache()
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
1123 self._save_draft(None, None) # everything fine, kill the draft for this page
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1124
2333
88c539512520 s/page_edit/notify
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2330
diff changeset
1125 if notify:
2330
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1126 # send notifications
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1127 from MoinMoin import events
2469
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1128
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1129 if trivial:
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1130 e = events.TrivialPageChangedEvent(self.request, self, comment)
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1131 else:
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1132 e = events.PageChangedEvent(self.request, self, comment)
2330
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1133 results = events.send_event(e)
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2189
diff changeset
1134
2330
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1135 recipients = set()
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1136 for result in results:
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1137 if isinstance(result, notification.Success):
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1138 recipients.update(result.recipients)
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2189
diff changeset
1139
2330
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1140 if recipients:
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1141 info = _("Notifications sent to:")
3717
78f1b1c0affb PageEditor: fixed msg displaying the notified people - use a breakable list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3629
diff changeset
1142 msg = msg + "<p>%s %s</p>" % (info, ", ".join(recipients))
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1143
1925
b198c7372ba8 update the page trail after successfully saving a page, needed for NewPage macro because it does not send the newly created page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
1144 # Update page trail with the page we just saved.
b198c7372ba8 update the page trail after successfully saving a page, needed for NewPage macro because it does not send the newly created page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
1145 # This is needed for NewPage macro with backto because it does not
b198c7372ba8 update the page trail after successfully saving a page, needed for NewPage macro because it does not send the newly created page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
1146 # send the page we just saved.
1956
477760dd8487 speedup addTrail by passing existing page object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1925
diff changeset
1147 request.user.addTrail(self)
1925
b198c7372ba8 update the page trail after successfully saving a page, needed for NewPage macro because it does not send the newly created page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
1148
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1149 # remove lock (forcibly if we were allowed to break it by the UI)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1150 # !!! this is a little fishy, since the lock owner might not notice
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1151 # we broke his lock ==> but revision checking during preview will
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1152 self.lock.release(force=not msg) # XXX does "not msg" make any sense?
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1153
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1154 return msg
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1155
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1156
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1157 class PageLock:
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1158 """ PageLock - Lock pages """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1159 # TODO: race conditions throughout, need to lock file during queries & update
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1160 def __init__(self, pageobj):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1161 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1162 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1163 self.pageobj = pageobj
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1164 self.page_name = pageobj.page_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1165 request = pageobj.request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1166 self.request = request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1167 self._ = self.request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1168 self.cfg = self.request.cfg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1169
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1170 # current time and user for later checks
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1171 self.now = int(time.time())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1172 self.uid = request.user.valid and request.user.id or request.remote_addr
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 # get details of the locking preference, i.e. warning or lock, and timeout
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1175 self.locktype = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1176 self.timeout = 10 * 60 # default timeout in minutes
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1177
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1178 if self.cfg.edit_locking:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1179 lockinfo = self.cfg.edit_locking.split()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1180 if 1 <= len(lockinfo) <= 2:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1181 self.locktype = lockinfo[0].lower()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1182 if len(lockinfo) > 1:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1183 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1184 self.timeout = int(lockinfo[1]) * 60
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1185 except ValueError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1186 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1187
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1188
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1189 def acquire(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1190 """ Begin an edit lock depending on the mode chosen in the config.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1191
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1192 @rtype: tuple
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1193 @return: tuple is returned containing 2 values:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1194 * a bool indicating successful acquiry
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1195 * a string giving a reason for failure or an informational msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1196 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1197 if not self.locktype:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1198 # we are not using edit locking, so always succeed
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1199 return 1, ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1200
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1201 _ = self._
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1202 #!!! race conditions, need to lock file during queries & update
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1203 self._readLockFile()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1204 bumptime = self.request.user.getFormattedDateTime(self.now + self.timeout)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1205 timestamp = self.request.user.getFormattedDateTime(self.timestamp)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1206 owner = self.owner_html
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1207 secs_valid = self.timestamp + self.timeout - self.now
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1208
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1209 # do we own the lock, or is it stale?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1210 if self.owner is None or self.uid == self.owner or secs_valid < 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1211 # create or bump the lock
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1212 self._writeLockFile()
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 msg = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1215 if self.owner is not None and -10800 < secs_valid < 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1216 mins_ago = secs_valid / -60
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1217 msg.append(_(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1218 "The lock of %(owner)s timed out %(mins_ago)d minute(s) ago,"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1219 " and you were granted the lock for this page."
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1220 ) % {'owner': owner, 'mins_ago': mins_ago})
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1221
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1222 if self.locktype == 'lock':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1223 msg.append(_(
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1224 "Other users will be ''blocked'' from editing this page until %(bumptime)s.",
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1225 wiki=True) % {'bumptime': bumptime})
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1226 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1227 msg.append(_(
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1228 "Other users will be ''warned'' until %(bumptime)s that you are editing this page.",
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1229 wiki=True) % {'bumptime': bumptime})
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1230 msg.append(_(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1231 "Use the Preview button to extend the locking period."
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1232 ))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1233 result = 1, '\n'.join(msg)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1234 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1235 mins_valid = (secs_valid+59) / 60
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1236 if self.locktype == 'lock':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1237 # lout out user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1238 result = 0, _(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1239 "This page is currently ''locked'' for editing by %(owner)s until %(timestamp)s,"
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1240 " i.e. for %(mins_valid)d minute(s).",
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1241 wiki=True) % {'owner': owner, 'timestamp': timestamp, 'mins_valid': mins_valid}
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1242 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1243 # warn user about existing lock
33
55ff4feb0f59 src cosmetics: remove TODOs, CVS stuff
Thomas Waldmann <tw@waldmann-edv.de>
parents: 18
diff changeset
1244
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1245 result = 1, _(
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
1246 """This page was opened for editing or last previewed at %(timestamp)s by %(owner)s.<<BR>>
33
55ff4feb0f59 src cosmetics: remove TODOs, CVS stuff
Thomas Waldmann <tw@waldmann-edv.de>
parents: 18
diff changeset
1247 '''You should ''refrain from editing'' this page for at least another %(mins_valid)d minute(s),
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
1248 to avoid editing conflicts.'''<<BR>>
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1249 To leave the editor, press the Cancel button.""", wiki=True) % {
33
55ff4feb0f59 src cosmetics: remove TODOs, CVS stuff
Thomas Waldmann <tw@waldmann-edv.de>
parents: 18
diff changeset
1250 'timestamp': timestamp, 'owner': owner, 'mins_valid': mins_valid}
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1251
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1252 return result
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1253
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1254
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1255 def release(self, force=0):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1256 """ Release lock, if we own it.
1916
d41e6ef31c0e PageEditor.copyPage: write access checked on old page instead of the copied one
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1909
diff changeset
1257
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1258 @param force: if 1, unconditionally release the lock.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1259 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1260 if self.locktype:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1261 # check that we own the lock in order to delete it
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1262 #!!! race conditions, need to lock file during queries & update
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1263 self._readLockFile()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1264 if force or self.uid == self.owner:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1265 self._deleteLockFile()
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
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1268 def _filename(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1269 """ Get path and filename for edit-lock file. """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1270 return self.pageobj.getPagePath('edit-lock', isfile=1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1271
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1272
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1273 def _readLockFile(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1274 """ Load lock info if not yet loaded. """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1275 _ = self._
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1276 self.owner = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1277 self.owner_html = wikiutil.escape(_("<unknown>"))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1278 self.timestamp = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1279
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1280 if self.locktype:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1281 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1282 entry = editlog.EditLog(self.request, filename=self._filename()).next()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1283 except StopIteration:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1284 entry = None
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1285
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1286 if entry:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1287 self.owner = entry.userid or entry.addr
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1288 self.owner_html = entry.getEditor(self.request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1289 self.timestamp = wikiutil.version2timestamp(entry.ed_time_usecs)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1290