annotate MoinMoin/action/Despam.py @ 1068:ecece5db5288

use emit_http_headers
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 27 Jul 2006 01:18:14 +0200
parents cbbde07e00c4
children f4558797325a
rev   line source
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
2 """
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
3 MoinMoin - Despam action
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
4
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
5 Mass revert changes done by some specific author / bot.
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
6
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
7 @copyright: 2005 by ???, Thomas Waldmann
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
8 @license: GNU GPL, see COPYING for details.
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
9 """
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
10
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 14
diff changeset
11 import time
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
12
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
13 from MoinMoin.logfile import editlog
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
14 from MoinMoin.util.dataset import TupleDataset, Column
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
15 from MoinMoin.widget.browser import DataBrowserWidget
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
16 from MoinMoin import wikiutil, Page, PageEditor
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
17 from MoinMoin.macro import RecentChanges
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
18
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
19 def show_editors(request, pagename, timestamp):
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
20 _ = request.getText
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
21
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
22 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
23 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
24 editors = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
25 pages = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
26 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
27 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
28 break
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
29
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
30 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
31 continue
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
32
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
33 editor = line.getEditor(request)
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 448
diff changeset
34 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
35 pages[line.pagename] = 1
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
36 editors[editor] = editors.get(editor, 0) + 1
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
37
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
38 editors = [(nr, editor) for editor, nr in editors.iteritems()]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
39 editors.sort()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
40
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
41 pg = Page.Page(request, pagename)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
42
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
43 dataset = TupleDataset()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
44 dataset.columns = [Column('editor', label=_("Editor"), align='left'),
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
45 Column('pages', label=_("Pages"), align='right'),
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
46 Column('link', label='', align='left')]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
47 for nr, editor in editors:
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 14
diff changeset
48 dataset.addRow((editor, unicode(nr), pg.link_to(request, text=_("Select Author"), querystr="action=Despam&editor=%s" % wikiutil.url_quote_plus(editor))))
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
49
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
50 table = DataBrowserWidget(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
51 table.setData(dataset)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
52 table.render()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
53
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
54 class tmp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
55 pass
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
56
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
57 def show_pages(request, pagename, editor, timestamp):
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
58 _ = request.getText
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
59
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
60 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
61 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
62 lines = []
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
63 pages = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
64 # mimic macro object for use of RecentChanges subfunctions
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
65 macro = tmp()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
66 macro.request = request
622
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
67 macro.formatter = request.html_formatter
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
68
230
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
69 request.write("<table>")
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
70 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
71 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
72 break
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
73
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
74 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
75 continue
230
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
76
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 448
diff changeset
77 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
78 pages[line.pagename] = 1
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
79 if line.getEditor(request) == editor:
230
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
80 line.time_tuple = request.user.getTime(wikiutil.version2timestamp(line.ed_time_usecs))
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
81 request.write(RecentChanges.format_page_edits(macro, [line], timestamp))
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
82
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
83 request.write('''
230
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
84 </table>
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
85 <p>
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
86 <form method="post" action="%s/%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
87 <input type="hidden" name="action" value="Despam">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
88 <input type="hidden" name="editor" value="%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
89 <input type="submit" name="ok" value="%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
90 </form>
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
91 </p>
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
92 ''' % (request.getScriptname(), wikiutil.quoteWikinameURL(pagename),
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 14
diff changeset
93 wikiutil.url_quote(editor), _("Revert all!")))
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
94
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
95 def revert_page(request, pagename, editor):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
96 if not request.user.may.revert(pagename):
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 889
diff changeset
97 return
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
98
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
99 log = editlog.EditLog(request, rootpagename=pagename)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
100
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
101 first = True
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
102 rev = u"00000000"
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
103 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
104 if first:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
105 first = False
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
106 if line.getEditor(request) != editor:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
107 return
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
108 else:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
109 if line.getEditor(request) != editor:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
110 rev = line.rev
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
111 break
230
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
112
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
113 if rev == u"00000000": # page created by spammer
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
114 comment = u"Page deleted by Despam action"
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
115 pg = PageEditor.PageEditor(request, pagename, do_editor_backup=0)
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
116 try:
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
117 savemsg = pg.deletePage(comment)
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
118 except pg.SaveError, msg:
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
119 savemsg = unicode(msg)
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
120 else: # page edited by spammer
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
121 oldpg = Page.Page(request, pagename, rev=int(rev))
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
122 pg = PageEditor.PageEditor(request, pagename, do_editor_backup=0)
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
123 try:
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
124 savemsg = pg.saveText(oldpg.get_raw_body(), 0, extra=rev, action="SAVE/REVERT")
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
125 except pg.SaveError, msg:
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
126 savemsg = unicode(msg)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
127 return savemsg
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
128
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
129 def revert_pages(request, editor, timestamp):
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
130 _ = request.getText
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
131
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 14
diff changeset
132 editor = wikiutil.url_unquote(editor, want_unicode=False)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
133 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
134 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
135 pages = {}
230
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
136 revertpages = []
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
137 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
138 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
139 break
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
140
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
141 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
142 continue
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
143
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 448
diff changeset
144 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
145 pages[line.pagename] = 1
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
146 if line.getEditor(request) == editor:
230
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
147 revertpages.append(line.pagename)
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
148
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
149 request.write("Debug: Pages to revert:<br>%s" % "<br>".join(revertpages))
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
150 for pagename in revertpages:
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
151 request.write("Debug: Begin reverting %s ...<br>" % pagename)
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
152 msg = revert_page(request, pagename, editor)
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
153 if msg:
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
154 request.write("<p>%s: %s</p>" % (
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
155 Page.Page(request, pagename).link_to(request), msg))
b38b28fbcfed beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
156 request.write("Debug: Finished reverting %s.<br>" % pagename)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
157
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
158 def execute(pagename, request):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
159 _ = request.getText
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
160 # be extra paranoid in dangerous actions
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
161 actname = __name__.split('.')[-1]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
162 if actname in request.cfg.actions_excluded or \
448
45924beef130 user.isSuperUser() check, require cfg.superuser being a list or tuple
Thomas Waldmann <tw@waldmann-edv.de>
parents: 391
diff changeset
163 not request.user.isSuperUser():
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
164 return Page.Page(request, pagename).send_page(request,
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
165 msg=_('You are not allowed to use this action.'))
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
166
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
167 editor = request.form.get('editor', [None])[0]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
168 timestamp = time.time() - 24 * 3600
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
169 # request.form.get('timestamp', [None])[0]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
170 ok = request.form.get('ok', [0])[0]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
171
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 949
diff changeset
172 request.emit_http_headers()
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
173 request.theme.send_title("Despam", pagename=pagename)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
174 # Start content (important for RTL support)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
175 request.write(request.formatter.startContent("content"))
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
176
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
177 if ok:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
178 revert_pages(request, editor, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
179 elif editor:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
180 show_pages(request, pagename, editor, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
181 else:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
182 show_editors(request, pagename, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
183
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
184 # End content and send footer
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
185 request.write(request.formatter.endContent())
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 551
diff changeset
186 request.theme.send_footer(pagename)
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
187 request.theme.send_closing_html()
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
188