annotate MoinMoin/PageEditor.py @ 5829:a744f573fe30

advancedsearch: fix problem with non-ascii chars breaking up words for OR and NOT terms
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 04 Feb 2012 16:52:24 +0100
parents 715479a7d692
children b397401dda7f
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
3920
de8ffca86cc9 PageEditor: EMAIL var uses sendmail.encodeSpamSafeEmail
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3917
diff changeset
27 from MoinMoin.mail.sendmail import encodeSpamSafeEmail
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
28 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
29 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
30 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
31 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
32 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
33
1140
3155f908de85 Refactored conflict markers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1069
diff changeset
34 # used for merging
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
35 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
36 "\n---- /!\\ '''Edit conflict - your version:''' ----\n",
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
37 "\n---- /!\\ '''End of edit conflict''' ----\n")
1140
3155f908de85 Refactored conflict markers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1069
diff changeset
38
3155f908de85 Refactored conflict markers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1069
diff changeset
39
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
40 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
41 ### 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
42 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
44 # 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
45 _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
46 %(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
47 <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
48 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
49 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
50 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
51 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
52 addLoadEvent(countdown)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 </script>
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 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 ### PageEditor - Edit pages
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
60 class PageEditor(Page):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
61 """ 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
62
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63 # exceptions for .saveText()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64 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
65 pass
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
66 class RevertError(SaveError):
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
67 pass
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
68 class AccessDenied(SaveError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
69 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
70 class Immutable(AccessDenied):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
71 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
72 class NoAdmin(AccessDenied):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
73 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
74 class EmptyPage(SaveError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
75 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
76 class Unchanged(SaveError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
77 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
78 class EditConflict(SaveError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
79 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80 class CouldNotLock(SaveError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
81 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
82
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
83 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
84 """ Create page editor object.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
85
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86 @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
87 @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
88 @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
89 @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
90 @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
91 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
92 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
93 self._ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
95 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
96 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
97 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
98
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
99 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
100
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101 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
102 """ 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
103
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
104 @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
105 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
106 @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
107 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108 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
109 allow_conflicts = 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
110
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111 # 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
112 savetext = self.get_raw_body()
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
113
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
114 # 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
115 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
116
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117 # 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
118 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
119
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 # 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
121 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
122 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
123 if verynewtext:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 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
125 return True
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
126
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
127 # 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
128 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
129
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
130 def sendconfirmleaving(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
131 """ 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
132 _ = 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
133 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
134 <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
135 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
136 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
137 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
138 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
139 }
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 </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
141 ''' % _("Your changes are not saved!"))
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
142
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
143 def sendEditor(self, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
144 """ 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
145
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
146 @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
147 @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
148 @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
149 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
150 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
151 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
152 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
153 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
154 _ = self._
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
155
199
4e9b5e9610da fixed editor preview throwing away page content for new pages
Thomas Waldmann <tw@waldmann-edv.de>
parents: 194
diff changeset
156 raw_body = ''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
157 msg = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
158 conflict_msg = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
159 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
160 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
161 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
162
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
163 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
164 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
165
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
166 # 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
167 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
168 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
169 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
170 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
171 elif self.rev:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
172 # 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
173 # 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
174 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
175 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
176 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
177 # 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
178 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
179 if not ok:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
180 # 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
181 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
182 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
183 ) + "<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
184 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
185 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
186 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
187 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
188 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
189 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
190 raise
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
191
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
192 # 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
193 if msg:
2967
a310264ad186 Added a few add_msg calls (by Federico Lorenzi).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2966
diff changeset
194 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
195 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
196 return
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
197
4444
b757ecd984fb Fix headers already sent exception in GUI editor code when using e.g. edit LOCKing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3727
diff changeset
198 # Emit http_headers after checks (send_page)
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
199 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
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:
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4235
diff changeset
204 wanted_draft_timestamp = int(form.get('draft_ts', '0'))
1640
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
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4235
diff changeset
216 rev = int(form['draft_rev'])
1640
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:
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4235
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()
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4326
diff changeset
278 elif 'template' in request.values:
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.
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4326
diff changeset
280 template_page = wikiutil.unquoteWikiname(request.values['template'])
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 4701
diff changeset
281 template_page_escaped = wikiutil.escape(template_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
282 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
283 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
284 if raw_body:
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 4701
diff changeset
285 request.theme.add_msg(_("[Content of new page loaded from %s]") % (template_page_escaped, ), 'info')
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
286 else:
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 4701
diff changeset
287 request.theme.add_msg(_("[Template %s not found]") % (template_page_escaped, ), 'warning')
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
288 else:
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 4701
diff changeset
289 request.theme.add_msg(_("[You may not read %s]") % (template_page_escaped, ), 'error')
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
290
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
291 # 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
292 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
293 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
294
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
295 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
296 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
297 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
298 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
299 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
300 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
301 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
302 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
303 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
304 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
305 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
306
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
307 # 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
308 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
309 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
310 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
311 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
312 request.theme.add_msg(status, "dialog")
3034
d0d9fbc0f0ee PEP8 whitespace fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2983
diff changeset
313
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
314 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
315 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
316 page=self,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
317 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
318 _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
319 '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
320 '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
321 '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
322 '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
323 '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
324 }) or '',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
325 editor_mode=1,
5646
e45e3ae9e540 scrolling the text editor to the double clicked line
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5584
diff changeset
326 allow_doubleclick=1,
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
327 )
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
328
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
329 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
330
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
331 # 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
332 if not raw_body:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
333 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
334
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
335 # send form
4235
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4210
diff changeset
336 request.write('<form id="editor" method="post" action="%s#preview" onSubmit="flgChange = false;">' % (
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4210
diff changeset
337 request.href(self.page_name)
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4210
diff changeset
338 ))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
339
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
340 # 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
341 # 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
342 # 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
343 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
344
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
345 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
346
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
347 # 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
348 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
349
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
350 # 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
351 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
352
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
353 # Save backto in a hidden input
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4326
diff changeset
354 backto = request.values.get('backto')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
355 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
356 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
357
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
358 # 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
359 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
360
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
361 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
362 cancel_button_text = _('Cancel')
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
363
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
364 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
365 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
366 """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
367 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
368 '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
369 '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
370 '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
371 }, '</em></p>')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
372
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
373
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
374 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
375 <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
376 <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
377 ''' % (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
378
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
379 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
380 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
381 <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
382 ''' % (_('GUI Mode'), ))
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
383
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
384 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
385 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
386 <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
387 <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
388 <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
389 ''' % (_('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
390
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
391 request.write('''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
392 %s
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
393 <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
394 <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
395 ''' % (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
396
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
397 # 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
398 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
399 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
400 <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
401 <!--
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 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
403 {
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 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
405 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
406 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
407 }
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
408
3168
0b0b756908c1 fix using unique IDs for 'trivial change' checkboxes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3122
diff changeset
409 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
410 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
411 //-->
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 </script> ''' % {
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4235
diff changeset
413 'checked': ('', 'checked')[form.get('trivial', '0') == '1'],
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
414 '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
415 })
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
416
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
417 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
418 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
419
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
420 # 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
421 self.sendconfirmleaving()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
422
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
423 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
424
5584
dc574a6d2516 text editor: if edit_rows==0 (user profile or config), dynamically size the text editor height
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5495
diff changeset
425 if not text_rows:
dc574a6d2516 text editor: if edit_rows==0 (user profile or config), dynamically size the text editor height
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5495
diff changeset
426 # if no specific value is given for editor height, but 0, we
dc574a6d2516 text editor: if edit_rows==0 (user profile or config), dynamically size the text editor height
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5495
diff changeset
427 # compute the rows from the raw_body line count plus some
dc574a6d2516 text editor: if edit_rows==0 (user profile or config), dynamically size the text editor height
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5495
diff changeset
428 # extra rows for adding new text in the editor. Maybe this helps
dc574a6d2516 text editor: if edit_rows==0 (user profile or config), dynamically size the text editor height
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5495
diff changeset
429 # with the "double slider" usability issue, esp. for devices like
dc574a6d2516 text editor: if edit_rows==0 (user profile or config), dynamically size the text editor height
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5495
diff changeset
430 # the iphone where you can't operate both sliders.
dc574a6d2516 text editor: if edit_rows==0 (user profile or config), dynamically size the text editor height
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5495
diff changeset
431 current_rows = len(raw_body.split('\n'))
dc574a6d2516 text editor: if edit_rows==0 (user profile or config), dynamically size the text editor height
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5495
diff changeset
432 text_rows = max(10, int(current_rows * 1.5))
dc574a6d2516 text editor: if edit_rows==0 (user profile or config), dynamically size the text editor height
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5495
diff changeset
433
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
434 request.write(
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
435 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
436 <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
437 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
438 %(text)s\
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
439 </textarea>''' % {
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
440 'lang': lang,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
441 '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
442 'rows': text_rows,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
443 '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
444 })
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
445
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
446 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
447 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
448 ' <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
449 ' 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
450 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
451 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
452
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
453 # 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
454 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
455 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
456 cat_pages.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
457 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
458 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
459 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
460 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
461 '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
462 })
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
463
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
464 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
465 request.write('''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
466 &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
467
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
468 <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
469 <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
470
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
471 ''' % {
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4235
diff changeset
472 'checked': ('', 'checked')[form.get('trivial', '0') == '1'],
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
473 'label': _("Trivial change"),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
474 })
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
475
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
476 request.write('''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
477 &nbsp;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
478 <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
479 <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
480 ''' % {
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4235
diff changeset
481 'checked': ('', 'checked')[form.get('rstrip', '0') == '1'],
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
482 '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
483 })
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
484 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
485
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
486 badwords_re = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
487 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
488 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
489 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
490 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
491 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
492 request.write("</form>")
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
493
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
494 # 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
495 markup = self.pi['format'] or request.cfg.default_markup
5682
ccb335181571 avoid hardly recoverable crashes if #format specification is invalid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5494
diff changeset
496 try:
ccb335181571 avoid hardly recoverable crashes if #format specification is invalid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5494
diff changeset
497 parser = wikiutil.searchAndImportPlugin(self.request.cfg, "parser", markup)
ccb335181571 avoid hardly recoverable crashes if #format specification is invalid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5494
diff changeset
498 except wikiutil.PluginMissingError:
ccb335181571 avoid hardly recoverable crashes if #format specification is invalid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5494
diff changeset
499 parser = wikiutil.searchAndImportPlugin(self.request.cfg, "parser", "plain")
3784
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3727
diff changeset
500 quickhelp = getattr(parser, 'quickhelp', None)
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
501 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
502 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
503 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
504 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
505
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
506 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
507 if staytop:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
508 content_id = 'previewbelow'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
509 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
510 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
511 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
512
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
513 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
514 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
515 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
516
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
517 def sendCancel(self, newtext, rev):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
518 """ User clicked on Cancel button.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
519 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
520
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
521 @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
522 @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
523 """
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
524 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
525 _ = self._
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
526 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
527 self.lock.release()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
528
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4326
diff changeset
529 backto = request.values.get('backto')
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
530 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
531 pg = Page(request, backto)
5311
a1215ba14417 PageEditor: remove relative=False arg to p.url() because it is default
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4899
diff changeset
532 request.http_redirect(pg.url(request))
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
533 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
534 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
535 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
536
3727
fd63e84632df fix tests failing due to rename by making the comment default u'' rather than None
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3721
diff changeset
537 def copyPage(self, newpagename, comment=u''):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
538 """ 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
539
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
540 @param comment: Comment given by user
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
541 @rtype: unicode
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
542 @return: success flag, error message
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
543 """
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
544 request = self.request
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
545 _ = self._
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
546
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
547 if not newpagename:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
548 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
549
1896
1de612a8c553 PageEditor: CopyPage bug fixed check write rights
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1895
diff changeset
550 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
551 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
552
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
553 newpage = PageEditor(request, newpagename)
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 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
556
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
557 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
558
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
559 # 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
560 if newpage.exists(includeDeleted=1):
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
561 return False, pageexists_error
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
562
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
563 # Get old page text
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
564 savetext = self.get_raw_body()
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
565
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
566 oldpath = self.getPagePath(check_create=0)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
567 newpath = newpage.getPagePath(check_create=0)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
568
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
569 # Copy page
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
570 # 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
571 try:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
572 filesys.copytree(oldpath, newpath)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
573 self.error = None
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
574 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
575 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
576 self._write_file(savetext, "SAVENEW", comment)
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
577
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
578 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
579 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
580
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
581 return True, None
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
582 except OSError, err:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
583 # 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
584 # 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
585 if newpage.exists(includeDeleted=1):
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
586 return False, pageexists_error
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
587 else:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
588 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
589
3727
fd63e84632df fix tests failing due to rename by making the comment default u'' rather than None
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3721
diff changeset
590 def renamePage(self, newpagename, comment=u''):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
591 """ 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
592 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
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 @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
595 @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
596 @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
597 """
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
598 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
599 _ = self._
1845
6ccc22836dd1 PageEditor.renamePage: added acl raise condition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1844
diff changeset
600
1849
ff8a6ed6d7aa revert changeset 1846:ca2c9a7f06c6
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1846
diff changeset
601 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
602 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
603 msg = _('You are not allowed to rename this page!')
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
604 raise self.AccessDenied(msg)
1845
6ccc22836dd1 PageEditor.renamePage: added acl raise condition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1844
diff changeset
605
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
606 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
607 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
608
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
609 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
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
611 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
612
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
613 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
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 # 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
616 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
617 return False, pageexists_error
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
618
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
619 # 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
620 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
621
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 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
623 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
624
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
625 # 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
626
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
627 # 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
628 # 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
629 # 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
630 # 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
631 # 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
632 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
633 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
634 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
635 # 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
636 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
637 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
638 # 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
639 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
640 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
641 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
642 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
643
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
644 # 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
645 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
646 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
647 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
648 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
649 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
650
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
651 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
652 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
653
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
654 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
655 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
656 # 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
657 # 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
658 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
659 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
660 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
661 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
662
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
663
3353
8e615ef236e2 allow saving a comment when reverting
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3305
diff changeset
664 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
665 """ Reverts page to the given revision
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
666
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
667 @param revision: revision to revert to
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
668 @type revision: int
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
669
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
670 """
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
671 _ = self.request.getText
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 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
674 # 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
675 # 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
676 raise self.RevertError('not allowed')
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
677 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
678 # see above
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3353
diff changeset
679 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
680 else:
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
681 revstr = '%08d' % revision
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
682 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
683 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
684
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
685 # Remove cache entry (if exists)
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
686 pg = Page(self.request, self.page_name)
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4326
diff changeset
687 key = self.request.form.get('key', 'text_html') # XXX see cleanup code in deletePage
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
688 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
689 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
690
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
691 # Notify observers
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
692 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
693 send_event(e)
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
694
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
695 return msg
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
696
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
697 def deletePage(self, comment=None):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
698 """ 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
699 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
700
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
701 @param comment: Comment given by user
148
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
702 @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
703 @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
704 """
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
705 request = self.request
148
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
706 _ = 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
707 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
708 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
709 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
710 msg = _('You are not allowed to delete this page!')
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
711 raise self.AccessDenied(msg)
1334
a4efeab7a10f Added security check to PageEditor.deletePage.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1317
diff changeset
712
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
713 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
714 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
715 msg = msg.replace(
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
716 _("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
717 _('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
718
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
719 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
720 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
721
148
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
722 except self.SaveError, message:
1844
58ebb64243cc added TODO for error handling in PageEditor
tw@server.firma.waldmann-edv.de
parents: 1832
diff changeset
723 # 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
724 # 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
725 success = False
383
1c86e97448fa DeletePage: fix uninitialized msg attribute in case of SaveError exception
Thomas Waldmann <tw@waldmann-edv.de>
parents: 199
diff changeset
726 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
727
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
728 # delete pagelinks
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
729 arena = self
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
730 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
731 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
732 cache.remove()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
733
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
734 # clean the cache
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
735 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
736 arena = self
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
737 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
738 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
739 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
740 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
741
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
742 def _get_local_timestamp(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
743 """ 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
744
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 @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
746 """
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
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 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
749 # 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
750 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
751 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
752
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 # 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
754 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
755 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
756 # 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
757 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
758 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
759 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
760 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
761
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
762 # 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
763 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
764 # 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
765 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
766
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
767 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
768
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
769 def _expand_variables(self, text):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
770 """ 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
771
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
772 @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
773 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
774 @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
775 """
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1792
diff changeset
776 # 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
777 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
778 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
779 u = request.user
3930
db3edaef0ba1 some wording corrected
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3920
diff changeset
780 obfuscated_email_address = encodeSpamSafeEmail(u.email)
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
781 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
782 variables = {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
783 'PAGE': self.page_name,
5391
587747855ee0 PageEditor.py: added @TIMESTAMP@ variable for adding raw time stamp.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5311
diff changeset
784 'TIMESTAMP': now,
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
785 '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
786 '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
787 '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
788 'USERNAME': signature,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
789 '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
790 'SIG': "-- %s <<DateTime(%s)>>" % (signature, now),
3930
db3edaef0ba1 some wording corrected
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3920
diff changeset
791 'EMAIL': "<<MailTo(%s)>>" % (obfuscated_email_address)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
792 }
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
793
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
794 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
795 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
796 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
797 # 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
798 # 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
799 userDictPage = u.name + "/MyDict"
4792
7a826f946da3 Groups2009: wikidicts were refactored. request.dict provides access only to WikiDicts.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4786
diff changeset
800 if userDictPage in request.dicts:
7a826f946da3 Groups2009: wikidicts were refactored. request.dict provides access only to WikiDicts.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4786
diff changeset
801 variables.update(request.dicts[userDictPage])
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
802
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
803 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
804 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
805 return 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 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
808 """ Normalize text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
809
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
810 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
811 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
812
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
813 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
814 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
815 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
816
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
817 @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
818 @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
819 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
820 @return: normalized text
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
821 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
822 if text:
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
823 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
824 # 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
825 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
826 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
827 # 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
828 # 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
829 # 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
830 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
831 # '' 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
832 lines.append(u'')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
833
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
834 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
835 return text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
836
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
837 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
838 """ 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
839
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
840 @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
841 (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
842 @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
843 @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
844 """
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
845 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
846 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
847 return None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
848
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
849 arena = 'drafts'
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
850 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
851 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
852 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
853 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
854 else:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
855 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
856 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
857 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
858 try:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
859 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
860 except:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
861 pass
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
862 else:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
863 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
864 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
865 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
866
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
867 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
868 """ 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
869
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
870 @rtype: unicode
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
871 @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
872 """
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
873 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
874 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
875 return None
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
876
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
877 arena = 'drafts'
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
878 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
879 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
880 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
881 try:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
882 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
883 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
884 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
885 return None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
886
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
887 def copy_underlay_page(self):
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
888 # 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
889 """ 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
890 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
891 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
892 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
893 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
894 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
895 # 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
896 # 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
897 # 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
898 except:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
899 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
900 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
901 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
902 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
903
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
904 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
905 """ 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
906
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
907 @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
908 @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
909 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
910 @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
911 """
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
912 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
913 _ = 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
914 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
915
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
916 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
917
1162
3e2b4beb65ed Moved conflict state detection again into another function.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1157
diff changeset
918 # remember conflict state
3e2b4beb65ed Moved conflict state detection again into another function.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1157
diff changeset
919 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
920
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
921 # 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
922 # underlay directory copy!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
923 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
924
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
925 revdir = os.path.join(pagedir, 'revisions')
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
926 cfn = os.path.join(pagedir, 'current')
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
927 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
928 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
929
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
930 # !!! 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
931
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
932 # 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
933 # underlay copy log!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
934 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
935 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
936 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
937 # 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
938 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
939
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
940 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
941 os.mkdir(pagedir)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
942 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
943 os.mkdir(revdir)
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
944 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
945 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
946 f.close()
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
947
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
948 got_lock = False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
949 retry = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
950
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
951 try:
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
952 while not got_lock and retry < 100:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
953 retry += 1
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
954 try:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
955 filesys.rename(cfn, clfn)
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
956 got_lock = True
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
957 except OSError, err:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
958 got_lock = False
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
959 if err.errno == 2: # there was no 'current' file
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
960 time.sleep(0.1)
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
961 else:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
962 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
963
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
964 if not got_lock:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
965 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
966
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
967 # increment rev number of current(-locked) page
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
968 f = file(clfn)
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
969 revstr = f.read()
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
970 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
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 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
973 except ValueError, err:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
974 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)
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
975
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
976 if not was_deprecated:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
977 if self.do_revision_backup or rev == 0:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
978 rev += 1
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
979 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
980 # 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
981 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
982 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
983 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
984 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
985 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
986 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
987 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
988 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
989 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
990 # 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
991 if err.errno == errno.ENOSPC:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
992 raise self.SaveError(_("Cannot save page %s, no storage space left.") % self.page_name)
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
993 else:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
994 raise self.SaveError(_("An I/O error occurred while saving page %s (errno=%d)") % (self.page_name, err.errno))
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
995 # 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
996 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
997 filesys.rename(cltfn, clfn)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
998
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
999 if not deleted:
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1000 # save to page file
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1001 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
1002 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
1003 # 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
1004 f.write(self.encodeTextMimeType(text))
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1005 f.close()
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1006 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
1007 # set in-memory content
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1008 self.set_raw_body(text)
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1009 else:
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1010 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
1011 # set in-memory content
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1012 self.set_raw_body(None)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1013
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1014 # reset page object
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1015 self.reset()
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1016
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1017 # write the editlog entry
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1018 # 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
1019 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
1020 # 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
1021 # 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
1022 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
1023 if not was_deprecated and self.do_revision_backup:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1024 # 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
1025 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
1026 finally:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1027 if got_lock:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1028 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
1029
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1030 # 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
1031 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
1032 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
1033
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1034 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
1035
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1036 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
1037 """ 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
1038
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1039 @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
1040 @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
1041 @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
1042 @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
1043 @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
1044 @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
1045 @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
1046 @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
1047 @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
1048 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1049 @return: error msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1050 """
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 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
1052 _ = self._
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
1053 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
1054 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
1055 deleted = kw.get('deleted', False)
2333
88c539512520 s/page_edit/notify
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2330
diff changeset
1056 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
1057
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1058 #!!! 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
1059 #!!! 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
1060
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1061 # 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
1062 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
1063 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
1064
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1065 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
1066 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
1067 msg = _('You are not allowed to edit this page!')
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1068 raise self.AccessDenied(msg)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1069 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
1070 msg = _('Page is immutable!')
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1071 raise self.Immutable(msg)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1072 elif not newtext:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1073 msg = _('You cannot save empty pages.')
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1074 raise self.EmptyPage(msg)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1075 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
1076 # 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
1077 other = False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1078 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
1079 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
1080 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
1081 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
1082 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
1083 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
1084 other = True
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1085 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
1086 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
1087 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
1088 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
1089 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
1090 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
1091 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
1092 msg = _("You already edited this page! Please do not use the back button.")
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1093 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
1094
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
1095 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
1096 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
1097
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1098 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
1099 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
1100 msg = _('You did not change the page content, not saved!')
4701
d8049de69c4f release edit lock if someone saves an unchanged page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4444
diff changeset
1101 self.lock.release()
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1102 raise self.Unchanged(msg)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1103 else:
747
e178ada80ead moved wikiacl.py to security/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
1104 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
1105 # 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
1106 # 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
1107 # 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
1108 # 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
1109 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
1110 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
1111 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
1112 action != "SAVE/REVERT"):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1113 msg = _("You can't change ACLs on this page since you have no admin rights on it!")
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1114 raise self.NoAdmin(msg)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1115
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
1116 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
1117 results = send_event(presave)
2399
245181ec9fe2 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2396
diff changeset
1118
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
1119 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
1120 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
1121 # 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
1122 # 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
1123 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
1124
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1125 # 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
1126 if not msg:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1127 # set success msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1128 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
1129
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
1130 # 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
1131 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
1132 action = 'SAVENEW'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1133 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
1134 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
1135 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
1136 # write the page file
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1137 mtime_usecs, rev = self._write_file(newtext, action, comment, extra, deleted=deleted)
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
1138 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
1139
2333
88c539512520 s/page_edit/notify
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2330
diff changeset
1140 if notify:
2330
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1141 # send notifications
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1142 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
1143
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1144 if trivial:
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1145 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
1146 else:
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1147 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
1148 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
1149
2330
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1150 recipients = set()
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1151 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
1152 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
1153 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
1154
2330
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1155 if recipients:
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1156 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
1157 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
1158
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
1159 # 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
1160 # 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
1161 # 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
1162 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
1163
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1164 # 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
1165 # !!! 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
1166 # 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
1167 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
1168
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1169 return msg
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1170
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1171
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1172 class PageLock:
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1173 """ 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
1174 # 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
1175 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
1176 """
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 self.pageobj = pageobj
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1179 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
1180 request = pageobj.request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1181 self.request = request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1182 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
1183 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
1184
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1185 # 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
1186 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
1187 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
1188
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1189 # 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
1190 self.locktype = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1191 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
1192
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1193 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
1194 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
1195 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
1196 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
1197 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
1198 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1199 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
1200 except ValueError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1201 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1202
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1203
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1204 def acquire(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1205 """ 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
1206
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1207 @rtype: tuple
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1208 @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
1209 * 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
1210 * 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
1211 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1212 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
1213 # 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
1214 return 1, ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1215
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1216 _ = self._
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1217 #!!! 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
1218 self._readLockFile()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1219 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
1220 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
1221 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
1222 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
1223
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1224 # 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
1225 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
1226 # 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
1227 self._writeLockFile()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1228
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1229 msg = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1230 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
1231 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
1232 msg.append(_(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1233 "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
1234 " 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
1235 ) % {'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
1236
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1237 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
1238 msg.append(_(
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1239 "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
1240 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
1241 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1242 msg.append(_(
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1243 "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
1244 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
1245 msg.append(_(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1246 "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
1247 ))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1248 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
1249 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1250 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
1251 if self.locktype == 'lock':
5717
715479a7d692 fix timestamp in edit lock message to show the time when edit-locking ends
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5711
diff changeset
1252 # lock out user
715479a7d692 fix timestamp in edit lock message to show the time when edit-locking ends
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5711
diff changeset
1253 timestamp_until = self.request.user.getFormattedDateTime(self.timestamp+secs_valid)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1254 result = 0, _(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1255 "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
1256 " i.e. for %(mins_valid)d minute(s).",
5717
715479a7d692 fix timestamp in edit lock message to show the time when edit-locking ends
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5711
diff changeset
1257 wiki=True) % {'owner': owner, 'timestamp': timestamp_until, '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
1258 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1259 # warn user about existing lock
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1260 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
1261 """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
1262 '''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
1263 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
1264 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
1265 '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
1266
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1267 return result
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1268
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1269
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1270 def release(self, force=0):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1271 """ 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
1272
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1273 @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
1274 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1275 if self.locktype:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1276 # 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
1277 #!!! 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
1278 self._readLockFile()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1279 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
1280 self._deleteLockFile()
77665d8e2254 tag of nonpublic@localhost--archive/moin--ent