annotate MoinMoin/PageEditor.py @ 6106:b59ee217581c

remove MoinMoin.support.HeaderFixed assuming it is fixed in 2.7. no idea what the problem was, comments unhelpful.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 06 Sep 2016 01:52:01 +0200
parents 500f68d3e2fd
children
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,
5921
38b39fafc5dc Added feature to set optional mtime (number of seconds since the epoch) for wiki pages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5887
diff changeset
15 2007-2013 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
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
28 from MoinMoin.util import filesys, timefuncs, web
6060
6a64e0b3b330 log failed page edit attempts with the abuse logger
'Karl O. Pinc' <kop@meme.com>
parents: 6003
diff changeset
29 from MoinMoin.util.abuse import log_attempt
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)
5921
38b39fafc5dc Added feature to set optional mtime (number of seconds since the epoch) for wiki pages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5887
diff changeset
91 @keyword mtime: time for edit-log and event-log (using current time in UTC, if not given)
38b39fafc5dc Added feature to set optional mtime (number of seconds since the epoch) for wiki pages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5887
diff changeset
92 number of seconds since the epoch, see the time module
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94 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
95 self._ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
97 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
98 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
99 self.uid_override = keywords.get('uid_override', None)
5921
38b39fafc5dc Added feature to set optional mtime (number of seconds since the epoch) for wiki pages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5887
diff changeset
100 self.mtime = keywords.get('mtime')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 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
103
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
104 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
105 """ 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
106
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
107 @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
108 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
109 @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
110 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111 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
112 allow_conflicts = 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
113
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
114 # 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
115 savetext = self.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 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
118 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
119
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 # 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
121 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
122
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 # 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
124 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
125 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
126 if verynewtext:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
127 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
128 return True
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
129
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
130 # 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
131 return False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
132
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
133 def sendconfirmleaving(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
134 """ 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
135 _ = 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
136 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
137 <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
138 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
139 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
140 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
141 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
142 }
2f495a1be4c7 confirm leaving JS added to gui editor, TODO: add flgChange update JS code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 526
diff changeset
143 </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
144 ''' % _("Your changes are not saved!"))
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
145
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
146 def sendEditor(self, **kw):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
147 """ 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
148
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
149 @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
150 @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
151 @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
152 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
153 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
154 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
155 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
156 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
157 _ = self._
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
158
199
4e9b5e9610da fixed editor preview throwing away page content for new pages
Thomas Waldmann <tw@waldmann-edv.de>
parents: 194
diff changeset
159 raw_body = ''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
160 msg = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
161 conflict_msg = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
162 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
163 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
164 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
165
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
166 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
167 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
168
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
169 # 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
170 if not request.user.may.write(self.page_name):
6078
35473fe0967d line wrap at 120 chars instead of 80
'Karl O. Pinc' <kop@meme.com>
parents: 6077
diff changeset
171 log_attempt('edit/no permissions', False, request, pagename=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
172 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
173 elif not self.isWritable():
6078
35473fe0967d line wrap at 120 chars instead of 80
'Karl O. Pinc' <kop@meme.com>
parents: 6077
diff changeset
174 log_attempt('edit/immutable', False, request, pagename=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
175 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
176 elif self.rev:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
177 # 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
178 # 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
179 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
180 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
181 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
182 # 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
183 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
184 if not ok:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
185 # 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
186 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
187 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
188 ) + "<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
189 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
190 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
191 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
192 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
193 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
194 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
195 raise
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
196
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
197 # 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
198 if msg:
2967
a310264ad186 Added a few add_msg calls (by Federico Lorenzi).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2966
diff changeset
199 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
200 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
201 return
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
202
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
203 # 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
204 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
205
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
206 # 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
207 use_draft = None
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
217 # 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
218 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
219 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
220 # 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
221 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
222 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
223 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
224 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
225 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
226 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
227 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
228 # 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
229 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
230 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
231
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
232 # send header stuff
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
233 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
234 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
235 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
236 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
237 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
238
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
239 # get request parameters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
240 try:
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4235
diff changeset
241 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
242 except StandardError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
243 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
244 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
245 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
246
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
247 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
248 # 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
249 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
250 # 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
251 if rev:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
252 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
253 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
254 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
255 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
256 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
257 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
258 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
259 if conflict_msg:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
260 # 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
261 preview = None
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
262
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
263 elif self.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
264 # 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
265 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
266 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
267 # page creation
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
268 rev = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
269
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
270 # 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
271 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
272
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
273 # 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
274 # 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
275 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
276 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
277 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
278 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
279 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
280 # 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
281 # 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
282 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
283 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
284 # 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
285 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
286 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
287 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
288 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
289 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
290 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
291 else:
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 4701
diff changeset
292 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
293 else:
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 4701
diff changeset
294 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
295
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
296 # 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
297 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
298 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
299
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
300 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
301 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
302 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
303 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
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
312 # 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
313 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
314 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
315 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
316 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
317 request.theme.add_msg(status, "dialog")
3034
d0d9fbc0f0ee PEP8 whitespace fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2983
diff changeset
318
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 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
320 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
321 page=self,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
322 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
323 _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
324 '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
325 '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
326 '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
327 '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
328 '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
329 }) or '',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
330 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
331 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
332 )
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
333
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
334 request.write(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
335
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
336 # 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
337 if not raw_body:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
338 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
339
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
340 # 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
341 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
342 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
343 ))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
344
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
345 # 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
346 # 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
347 # 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
348 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
349
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
350 request.write(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
351
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
352 # 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
353 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
354
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
355 # 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
356 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
357
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
358 # 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
359 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
360 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
361 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
362
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
363 # 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
364 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
365
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
366 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
367 cancel_button_text = _('Cancel')
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
368
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
369 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
370 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
371 """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
372 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
373 '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
374 '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
375 '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
376 }, '</em></p>')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
377
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
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 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
380 <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
381 <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
382 ''' % (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
383
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
384 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
385 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
386 <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
387 ''' % (_('GUI Mode'), ))
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
388
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
389 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
390 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
391 <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
392 <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
393 <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
394 ''' % (_('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
395
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
396 request.write('''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
397 %s
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
398 <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
399 <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
400 ''' % (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
401
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
402 # 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
403 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
404 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
405 <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
406 <!--
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
407 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
408 {
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
409 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
410 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
411 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
412 }
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
413
3168
0b0b756908c1 fix using unique IDs for 'trivial change' checkboxes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3122
diff changeset
414 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
415 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
416 //-->
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
417 </script> ''' % {
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4235
diff changeset
418 '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
419 '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
420 })
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
421
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
422 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
423 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
424
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
425 # 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
426 self.sendconfirmleaving()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
427
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
428 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
429
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
430 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
431 # 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
432 # 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
433 # 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
434 # 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
435 # 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
436 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
437 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
438
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
439 request.write(
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
440 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
441 <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
442 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
443 %(text)s\
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
444 </textarea>''' % {
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
445 'lang': lang,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
446 '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
447 'rows': text_rows,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
448 '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
449 })
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
450
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>")
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
452 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
453 ' <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
454 ' 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
455 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
456 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
457
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
458 # 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
459 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
460 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
461 cat_pages.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
462 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
463 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
464 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
465 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
466 '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
467 })
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
468
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
469 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
470 request.write('''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
471 &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
472
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
473 <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
474 <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
475
b545446562a0 fix for MoinMoinBugs/TrivialChangeEasyAccess (thanks to Ninnu) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3034
diff changeset
476 ''' % {
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4235
diff changeset
477 '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
478 'label': _("Trivial change"),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
479 })
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
480
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
481 request.write('''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
482 &nbsp;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
483 <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
484 <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
485 ''' % {
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4235
diff changeset
486 '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
487 '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
488 })
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 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
490
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
491 badwords_re = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
492 if preview is not None:
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
493 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
494 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
495 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
496 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
497 request.write("</form>")
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
498
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
499 # 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
500 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
501 try:
ccb335181571 avoid hardly recoverable crashes if #format specification is invalid
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5494
diff changeset
502 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
503 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
504 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
505 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
506 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
507 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
508 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
509 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
510
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
511 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
512 if staytop:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
513 content_id = 'previewbelow'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
514 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
515 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
516 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
517
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
518 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
519 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
520 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
521
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
522 def sendCancel(self, newtext, rev):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
523 """ User clicked on Cancel button.
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
524 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
525
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
526 @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
527 @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
528 """
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
529 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
530 _ = self._
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
531 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
532 self.lock.release()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
533
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
534 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
535 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
536 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
537 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
538 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
539 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
540 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
541
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
542 def copyPage(self, newpagename, comment=u''):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
543 """ 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
544
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
545 @param comment: Comment given by user
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
546 @rtype: unicode
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
547 @return: success flag, error message
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
548 """
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
549 request = self.request
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
550 _ = self._
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
551
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
552 if not newpagename:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
553 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
554
1896
1de612a8c553 PageEditor: CopyPage bug fixed check write rights
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1895
diff changeset
555 if not self.request.user.may.write(newpagename):
6078
35473fe0967d line wrap at 120 chars instead of 80
'Karl O. Pinc' <kop@meme.com>
parents: 6077
diff changeset
556 log_attempt('copy/no permissions', False, request, pagename=self.page_name)
1896
1de612a8c553 PageEditor: CopyPage bug fixed check write rights
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1895
diff changeset
557 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
558
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
559 newpage = PageEditor(request, newpagename)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
560
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
561 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
562
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
563 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
564
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
565 # 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
566 if newpage.exists(includeDeleted=1):
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
567 return False, pageexists_error
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 # Get old page text
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
570 savetext = self.get_raw_body()
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
571
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
572 oldpath = self.getPagePath(check_create=0)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
573 newpath = newpage.getPagePath(check_create=0)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
574
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
575 # Copy page
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
576 # 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
577 try:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
578 filesys.copytree(oldpath, newpath)
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
579 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
580 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
581 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
582 self._write_file(savetext, "SAVENEW", comment)
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
583
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
584 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
585 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
586
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
587 return True, None
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
588 except OSError, err:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
589 # 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
590 # 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
591 if newpage.exists(includeDeleted=1):
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
592 return False, pageexists_error
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
593 else:
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
594 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
595
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
596 def renamePage(self, newpagename, comment=u''):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
597 """ 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
598 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
599
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
600 @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
601 @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
602 @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
603 """
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
604 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
605 _ = self._
1845
6ccc22836dd1 PageEditor.renamePage: added acl raise condition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1844
diff changeset
606
1849
ff8a6ed6d7aa revert changeset 1846:ca2c9a7f06c6
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1846
diff changeset
607 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
608 and request.user.may.write(newpagename)):
6078
35473fe0967d line wrap at 120 chars instead of 80
'Karl O. Pinc' <kop@meme.com>
parents: 6077
diff changeset
609 log_attempt('rename/no permissions', False, request, pagename=self.page_name)
1845
6ccc22836dd1 PageEditor.renamePage: added acl raise condition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1844
diff changeset
610 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
611 raise self.AccessDenied(msg)
1845
6ccc22836dd1 PageEditor.renamePage: added acl raise condition
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1844
diff changeset
612
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
613 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
614 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
615
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
616 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
617
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 542
diff changeset
618 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
619
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
620 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
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 # 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
623 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
624 return False, pageexists_error
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
625
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
626 # 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
627 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
628
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 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
630 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
631
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 # 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
633
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 # 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
635 # 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
636 # 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
637 # 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
638 # 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
639 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
640 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
641 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
642 # 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
643 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
644 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
645 # 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
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 = '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
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()
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
650
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
651 # 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
652 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
653 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
654 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
655 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
656 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
657
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
658 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
659 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
660
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
661 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
662 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
663 # 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
664 # 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
665 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
666 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
667 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
668 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
669
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
670
3353
8e615ef236e2 allow saving a comment when reverting
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3305
diff changeset
671 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
672 """ Reverts page to the given revision
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
673
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
674 @param revision: revision to revert to
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
675 @type revision: int
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
676
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
677 """
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
678 _ = self.request.getText
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
679
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
680 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
681 # 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
682 # 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
683 raise self.RevertError('not allowed')
2698
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
684 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
685 # see above
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3353
diff changeset
686 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
687 else:
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
688 revstr = '%08d' % revision
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
689 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
690 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
691
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
692 # Remove cache entry (if exists)
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
693 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
694 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
695 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
696 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
697
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
698 # Notify observers
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
699 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
700 send_event(e)
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
701
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
702 return msg
0a6f74a01646 Fix revert action and xmlrpc call.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2595
diff changeset
703
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
704 def deletePage(self, comment=None):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
705 """ 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
706 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
707
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
708 @param comment: Comment given by user
148
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
709 @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
710 @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
711 """
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
712 request = self.request
148
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
713 _ = 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
714 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
715 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
716 and request.user.may.delete(self.page_name)):
6078
35473fe0967d line wrap at 120 chars instead of 80
'Karl O. Pinc' <kop@meme.com>
parents: 6077
diff changeset
717 log_attempt('delete/no permissions', False, request, pagename=self.page_name)
1334
a4efeab7a10f Added security check to PageEditor.deletePage.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1317
diff changeset
718 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
719 raise self.AccessDenied(msg)
1334
a4efeab7a10f Added security check to PageEditor.deletePage.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1317
diff changeset
720
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
721 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
722 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
723 msg = msg.replace(
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
724 _("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
725 _('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
726
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
727 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
728 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
729
148
4a64816584ae fixed MoinMoinBugs/MailStatusOnDeletePage
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
730 except self.SaveError, message:
1844
58ebb64243cc added TODO for error handling in PageEditor
tw@server.firma.waldmann-edv.de
parents: 1832
diff changeset
731 # 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
732 # 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
733 success = False
5887
b397401dda7f fix typos, correct is: 'occurred'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5717
diff changeset
734 msg = "SaveError has occurred 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
735
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
736 # delete pagelinks
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
737 arena = self
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
738 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
739 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
740 cache.remove()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
741
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
742 # clean the cache
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
743 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
744 arena = self
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
745 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
746 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
747 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
748 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
749
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
750 def _get_local_timestamp(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
751 """ 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
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 @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
754 """
a170df39355f @SIG@ etc. generate local time stamps now, no difference visible on page view.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 876
diff changeset
755
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 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
757 # 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
758 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
759 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
760
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 # 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
762 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
763 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
764 # 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
765 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
766 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
767 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
768 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
769
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
770 # 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
771 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
772 # 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
773 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
774
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
775 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
776
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
777 def _expand_variables(self, text):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
778 """ 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
779
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
780 @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
781 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
782 @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
783 """
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1792
diff changeset
784 # 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
785 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
786 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
787 u = request.user
3930
db3edaef0ba1 some wording corrected
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3920
diff changeset
788 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
789 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
790 variables = {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
791 '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
792 '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
793 '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
794 '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
795 '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
796 'USERNAME': signature,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
797 '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
798 'SIG': "-- %s <<DateTime(%s)>>" % (signature, now),
3930
db3edaef0ba1 some wording corrected
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3920
diff changeset
799 '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
800 }
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
801
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
802 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
803 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
804 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
805 # 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
806 # 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
807 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
808 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
809 variables.update(request.dicts[userDictPage])
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
810
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
811 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
812 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
813 return text
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
814
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
815 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
816 """ Normalize text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
817
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
818 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
819 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
820
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
821 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
822 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
823 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
824
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
825 @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
826 @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
827 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
828 @return: normalized text
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
829 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
830 if text:
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
831 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
832 # 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
833 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
834 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
835 # 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
836 # 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
837 # 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
838 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
839 # '' 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
840 lines.append(u'')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
841
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
842 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
843 return text
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 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
846 """ 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
847
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
848 @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
849 (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
850 @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
851 @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
852 """
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
853 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
854 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
855 return None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
856
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
857 arena = 'drafts'
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
858 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
859 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
860 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
861 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
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 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
864 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
865 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
866 try:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
867 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
868 except:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
869 pass
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
870 else:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
871 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
872 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
873 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
874
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
875 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
876 """ 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
877
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
878 @rtype: unicode
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
879 @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
880 """
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
881 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
882 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
883 return None
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
884
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
885 arena = 'drafts'
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
886 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
887 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
888 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
889 try:
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
890 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
891 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
892 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
893 return None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
894
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
895 def copy_underlay_page(self):
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
896 # 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
897 """ 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
898 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
899 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
900 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
901 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
902 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
903 # 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
904 # 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
905 # 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
906 except:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
907 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
908 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
909 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
910 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
911
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
912 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
913 """ 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
914
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
915 @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
916 @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
917 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
918 @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
919 """
1695
9ae9f564380e fix backtrace on editor preview, refactor code to use 'request', not 'self.request'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
920 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
921 _ = 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
922 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
923
6003
575660fc7a5a fix "moin import wikipage" timestamp confusion
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5921
diff changeset
924 if self.mtime is None:
575660fc7a5a fix "moin import wikipage" timestamp confusion
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5921
diff changeset
925 mtime_usecs = None
575660fc7a5a fix "moin import wikipage" timestamp confusion
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5921
diff changeset
926 else:
575660fc7a5a fix "moin import wikipage" timestamp confusion
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5921
diff changeset
927 mtime_usecs = wikiutil.timestamp2version(self.mtime)
575660fc7a5a fix "moin import wikipage" timestamp confusion
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5921
diff changeset
928
1850
3d38db210672 action CopyPage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1849
diff changeset
929 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
930
1162
3e2b4beb65ed Moved conflict state detection again into another function.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1157
diff changeset
931 # remember conflict state
3e2b4beb65ed Moved conflict state detection again into another function.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1157
diff changeset
932 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
933
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
934 # 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
935 # underlay directory copy!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
936 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
937
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
938 revdir = os.path.join(pagedir, 'revisions')
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
939 cfn = os.path.join(pagedir, 'current')
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
940 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
941 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
942
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
943 # !!! 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
944
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
945 # 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
946 # underlay copy log!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
947 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
948 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
949 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
950 # 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
951 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
952
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
953 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
954 os.mkdir(pagedir)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
955 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
956 os.mkdir(revdir)
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
957 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
958 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
959 f.close()
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
960
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
961 got_lock = False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
962 retry = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
963
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
964 try:
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
965 while not got_lock and retry < 100:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
966 retry += 1
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
967 try:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
968 filesys.rename(cfn, clfn)
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
969 got_lock = True
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
970 except OSError, err:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
971 got_lock = False
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
972 if err.errno == 2: # there was no 'current' file
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
973 time.sleep(0.1)
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
974 else:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
975 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
976
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
977 if not got_lock:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
978 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
979
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
980 # increment rev number of current(-locked) page
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
981 f = file(clfn)
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
982 revstr = f.read()
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
983 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
984 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
985 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
986 except ValueError, err:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
987 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
988
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
989 if not was_deprecated:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
990 if self.do_revision_backup or rev == 0:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
991 rev += 1
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
992 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
993 # 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
994 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
995 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
996 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
997 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
998 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
999 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
1000 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
1001 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
1002 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
1003 # 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
1004 if err.errno == errno.ENOSPC:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1005 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
1006 else:
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1007 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
1008 # 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
1009 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
1010 filesys.rename(cltfn, clfn)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1011
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1012 if not deleted:
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1013 # save to page file
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1014 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
1015 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
1016 # 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
1017 f.write(self.encodeTextMimeType(text))
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1018 f.close()
6003
575660fc7a5a fix "moin import wikipage" timestamp confusion
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5921
diff changeset
1019 if mtime_usecs is None:
575660fc7a5a fix "moin import wikipage" timestamp confusion
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5921
diff changeset
1020 mtime_usecs = wikiutil.timestamp2version(os.path.getmtime(pagefile))
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1021 # set in-memory content
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1022 self.set_raw_body(text)
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1023 else:
6003
575660fc7a5a fix "moin import wikipage" timestamp confusion
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5921
diff changeset
1024 if mtime_usecs is None:
575660fc7a5a fix "moin import wikipage" timestamp confusion
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5921
diff changeset
1025 mtime_usecs = wikiutil.timestamp2version(time.time())
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1026 # set in-memory content
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1027 self.set_raw_body(None)
6003
575660fc7a5a fix "moin import wikipage" timestamp confusion
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5921
diff changeset
1028
1619
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1029 # reset page object
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1030 self.reset()
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1031
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1032 # write the editlog entry
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1033 # 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
1034 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
1035 # 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
1036 # 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
1037 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
1038 if not was_deprecated and self.do_revision_backup:
a103f4d38ce5 cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1581
diff changeset
1039 # 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
1040 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
1041 finally:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1042 if got_lock:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1043 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
1044
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1045 # 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
1046 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
1047 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
1048
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1049 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
1050
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1051 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
1052 """ 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
1053
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1054 @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
1055 @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
1056 @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
1057 @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
1058 @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
1059 @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
1060 @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
1061 @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
1062 @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
1063 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1064 @return: error msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1065 """
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 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
1067 _ = self._
1640
6478c7744221 new per page drafts functionality, replaces old /MoinEditorBackup method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1619
diff changeset
1068 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
1069 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
1070 deleted = kw.get('deleted', False)
2333
88c539512520 s/page_edit/notify
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2330
diff changeset
1071 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
1072
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1073 #!!! 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
1074 #!!! 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
1075
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1076 # 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
1077 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
1078 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
1079
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1080 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
1081 if not request.user.may.save(self, newtext, rev, **kw):
6078
35473fe0967d line wrap at 120 chars instead of 80
'Karl O. Pinc' <kop@meme.com>
parents: 6077
diff changeset
1082 log_attempt('save/no permissions', False, request, pagename=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
1083 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
1084 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
1085 elif not self.isWritable():
6078
35473fe0967d line wrap at 120 chars instead of 80
'Karl O. Pinc' <kop@meme.com>
parents: 6077
diff changeset
1086 log_attempt('save/immutable', False, request, pagename=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
1087 msg = _('Page is immutable!')
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1088 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
1089 elif not newtext:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1090 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
1091 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
1092 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
1093 # 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
1094 other = False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1095 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
1096 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
1097 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
1098 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
1099 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
1100 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
1101 other = True
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1102 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
1103 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
1104 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
1105 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
1106 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
1107 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
1108 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
1109 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
1110 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
1111
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
1112 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
1113 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
1114
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1115 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
1116 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
1117 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
1118 self.lock.release()
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5687
diff changeset
1119 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
1120 else:
747
e178ada80ead moved wikiacl.py to security/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
1121 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
1122 # 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
1123 # 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
1124 # 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
1125 # 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
1126 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
1127 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
1128 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
1129 action != "SAVE/REVERT"):
6078
35473fe0967d line wrap at 120 chars instead of 80
'Karl O. Pinc' <kop@meme.com>
parents: 6077
diff changeset
1130 log_attempt('acl change/no permissions', False, request, pagename=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
1131 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
1132 raise self.NoAdmin(msg)
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1133
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
1134 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
1135 results = send_event(presave)
2399
245181ec9fe2 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2396
diff changeset
1136
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
1137 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
1138 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
1139 # 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
1140 # 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
1141 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
1142
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
1143 # 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
1144 if not msg:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1145 # set success msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1146 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
1147
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2189
diff changeset
1148 # 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
1149 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
1150 action = 'SAVENEW'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1151 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
1152 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
1153 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
1154 # write the page file
1716
9a3290aeff36 fixed cached inconsistency caused by DeletePage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1713
diff changeset
1155 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
1156 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
1157
2333
88c539512520 s/page_edit/notify
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2330
diff changeset
1158 if notify:
2330
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1159 # send notifications
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1160 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
1161
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1162 if trivial:
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1163 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
1164 else:
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2406
diff changeset
1165 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
1166 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
1167
2330
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1168 recipients = set()
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1169 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
1170 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
1171 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
1172
2330
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1173 if recipients:
38f4f0311a98 Attempt to remove situations when unnecessary PageChangedEvent is sent.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
1174 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
1175 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
1176
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
1177 # 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
1178 # 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
1179 # 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
1180 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
1181
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1182 # 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
1183 # !!! 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
1184 # 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
1185 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
1186
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1187 return msg
1577
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1188
c2457afd322d cosmetic changes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1573
diff changeset
1189
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1190 class PageLock:
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1191 """ 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
1192 # 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
1193 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
1194 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1195 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1196 self.pageobj = pageobj
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1197 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
1198 request = pageobj.request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1199 self.request = request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1200 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
1201 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
1202
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1203 # 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
1204 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
1205 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
1206
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1207 # 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
1208 self.locktype = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1209 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
1210
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1211 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
1212 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
1213 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
1214 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
1215 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
1216 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1217 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
1218 except ValueError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1219 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1220
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1221
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1222 def acquire(self):
1961
4e528d291fc0 Page*.py: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1956
diff changeset
1223 """ 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
1224
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1225 @rtype: tuple
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1226 @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
1227 * 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
1228 * 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
1229 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1230 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
1231 # 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
1232 return 1, ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1233
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1234 _ = self._
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1235 #!!! 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
1236 self._readLockFile()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1237 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
1238 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
1239 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
1240 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
1241
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1242 # 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
1243 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
1244 # 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
1245 self._writeLockFile()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1246
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1247 msg = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1248 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
1249 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
1250 msg.append(_(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1251 "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
1252 " 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
1253 ) % {'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
1254
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1255 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
1256 msg.append(_(
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1257 "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
1258 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
1259 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1260 msg.append(_(
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3042
diff changeset
1261 "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
1262 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
1263 msg.append(_(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1264 "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
1265 ))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1266 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
1267 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1268 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
1269 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
1270 # 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
1271 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
1272 result = 0, _(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1273 "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
1274 " 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
1275 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
1276 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1277 # warn user about existing lock
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents: