annotate MoinMoin/action/Despam.py @ 617:cf420addd95c

removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 05 May 2006 13:31:08 +0200
parents 3b08d9413589
children 8fba6d15a2f5
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 from MoinMoin.formatter.text_html import Formatter
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
19
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
20 def show_editors(request, pagename, timestamp):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
21 _ = request.getText
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
22
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
23 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
24 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
25 editors = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
26 pages = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
27 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
28 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
29 break
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
30
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
31 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
32 continue
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
33
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
34 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
35 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
36 pages[line.pagename] = 1
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
37 editors[editor] = editors.get(editor, 0) + 1
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
38
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
39 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
40 editors.sort()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
41
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
42 pg = Page.Page(request, pagename)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
43
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
44 dataset = TupleDataset()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
45 dataset.columns = [Column('editor', label=_("Editor"), align='left'),
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
46 Column('pages', label=_("Pages"), align='right'),
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
47 Column('link', label='', align='left')]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
48 for nr, editor in editors:
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 14
diff changeset
49 dataset.addRow((editor, unicode(nr), pg.link_to(request, text=_("Select Author"), querystr="action=Despam&editor=%s" % wikiutil.url_quote_plus(editor))))
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
50
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
51 table = DataBrowserWidget(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
52 table.setData(dataset)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
53 table.render()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
54
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
55 class tmp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
56 pass
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
57
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
58 def show_pages(request, pagename, editor, timestamp):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
59 _ = request.getText
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
60
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
61 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
62 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
63 lines = []
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
64 pages = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
65 # mimic macro object for use of RecentChanges subfunctions
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
66 macro = tmp()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
67 macro.request = request
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
68 macro.formatter = Formatter(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
69
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
70 request.write("<table>")
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
71 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
72 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
73 break
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
74
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
75 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
76 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
77
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 448
diff changeset
78 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
79 pages[line.pagename] = 1
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
80 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
81 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
82 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
83
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
84 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
85 </table>
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
86 <p>
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
87 <form method="post" action="%s/%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
88 <input type="hidden" name="action" value="Despam">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
89 <input type="hidden" name="editor" value="%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
90 <input type="submit" name="ok" value="%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
91 </form>
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
92 </p>
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
93 ''' % (request.getScriptname(), wikiutil.quoteWikinameURL(pagename),
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 14
diff changeset
94 wikiutil.url_quote(editor), _("Revert all!")))
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
95
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
96 def revert_page(request, pagename, editor):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
97 if not request.user.may.revert(pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
98 return
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
99
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
100 log = editlog.EditLog(request, rootpagename=pagename)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
101
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
102 first = True
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
103 rev = u"00000000"
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
104 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
105 if first:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
106 first = False
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
107 if line.getEditor(request) != editor:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
108 return
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
109 else:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
110 if line.getEditor(request) != editor:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
111 rev = line.rev
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
112 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
113
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 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
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 savemsg = unicode(msg)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
128 return savemsg
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
129
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
130 def revert_pages(request, editor, timestamp):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
131 _ = request.getText
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
132
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 14
diff changeset
133 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
134 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
135 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
136 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
137 revertpages = []
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
138 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
139 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
140 break
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
141
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
142 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
143 continue
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
144
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 448
diff changeset
145 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
146 pages[line.pagename] = 1
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
147 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
148 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
149
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 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
159 def execute(pagename, request):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
160 _ = request.getText
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
161 # be extra paranoid in dangerous actions
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
162 actname = __name__.split('.')[-1]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
163 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
164 not request.user.isSuperUser():
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
165 return Page.Page(request, pagename).send_page(request,
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
166 msg = _('You are not allowed to use this action.'))
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
167
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
168 editor = request.form.get('editor', [None])[0]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
169 timestamp = time.time() - 24 * 3600
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
170 # request.form.get('timestamp', [None])[0]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
171 ok = request.form.get('ok', [0])[0]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
172
317
d2015038d0e7 send http headers for Despam action
Thomas Waldmann <tw@waldmann-edv.de>
parents: 230
diff changeset
173 request.http_headers()
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 551
diff changeset
174 request.theme.send_title("Despam", pagename=pagename)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
175 # Start content (important for RTL support)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
176 request.write(request.formatter.startContent("content"))
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
177
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
178 if ok:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
179 revert_pages(request, editor, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
180 elif editor:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
181 show_pages(request, pagename, editor, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
182 else:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
183 show_editors(request, pagename, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
184
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
185 # End content and send footer
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
186 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
187 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
188 request.theme.send_closing_html()
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
189