annotate MoinMoin/action/Despam.py @ 3094:92e5cf67842f

fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 01:27:27 +0100
parents ba14d391c2ba
children 6162f334bd5a
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
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1793
diff changeset
4
14
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
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
11 DAYS = 30 # we look for spam edits in the last x days
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
12
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 14
diff changeset
13 import time
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
15 from MoinMoin.logfile import editlog
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
16 from MoinMoin.util.dataset import TupleDataset, Column
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
17 from MoinMoin.widget.browser import DataBrowserWidget
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
18 from MoinMoin import wikiutil, Page, PageEditor
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
19 from MoinMoin.macro import RecentChanges
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
20
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
21 def render(editor_tuple):
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
22 etype, evalue = editor_tuple
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
23 if etype in ('ip', 'email', ):
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
24 ret = evalue
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
25 elif etype == 'interwiki':
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
26 ewiki, euser = evalue
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
27 if ewiki == 'Self':
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
28 ret = euser
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
29 else:
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
30 ret = '%s:%s' % evalue
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
31 else:
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
32 ret = repr(editor_tuple)
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
33 return ret
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
34
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
35 def show_editors(request, pagename, timestamp):
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
36 _ = request.getText
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 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
39 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
40 editors = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
41 pages = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
42 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
43 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
44 break
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
45
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
46 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
47 continue
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
48
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
49 editor = line.getInterwikiEditorData(request)
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 448
diff changeset
50 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
51 pages[line.pagename] = 1
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
52 editors[editor] = editors.get(editor, 0) + 1
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
53
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
54 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
55 editors.sort()
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
56 editors.reverse()
14
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 pg = Page.Page(request, pagename)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
59
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
60 dataset = TupleDataset()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
61 dataset.columns = [Column('editor', label=_("Editor"), align='left'),
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
62 Column('pages', label=_("Pages"), align='right'),
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
63 Column('link', label='', align='left')]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
64 for nr, editor in editors:
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
65 dataset.addRow((render(editor), unicode(nr),
1341
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
66 pg.link_to(request, text=_("Select Author"),
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
67 querystr={
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
68 'action': 'Despam',
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
69 'editor': editor, # was: url_quote_plus()
f4558797325a new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
70 })))
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
71
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
72 table = DataBrowserWidget(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
73 table.setData(dataset)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
74 table.render()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
75
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
76 class tmp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
77 pass
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
78
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
79 def show_pages(request, pagename, editor, timestamp):
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
80 _ = request.getText
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
81
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
82 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
83 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
84 pages = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
85 # mimic macro object for use of RecentChanges subfunctions
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
86 macro = tmp()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
87 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
88 macro.formatter = request.html_formatter
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
89
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
90 request.write("<table>")
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
91 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
92 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
93 break
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
94
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
95 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
96 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
97
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 448
diff changeset
98 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
99 pages[line.pagename] = 1
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
100 if repr(line.getInterwikiEditorData(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
101 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
102 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
103
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
104 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
105 </table>
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
106 <p>
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
107 <form method="post" action="%s/%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
108 <input type="hidden" name="action" value="Despam">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
109 <input type="hidden" name="editor" value="%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
110 <input type="submit" name="ok" value="%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
111 </form>
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
112 </p>
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
113 ''' % (request.getScriptname(), wikiutil.quoteWikinameURL(pagename),
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 14
diff changeset
114 wikiutil.url_quote(editor), _("Revert all!")))
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
115
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
116 def revert_page(request, pagename, editor):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
117 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
118 return
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
119
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
120 log = editlog.EditLog(request, rootpagename=pagename)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
121
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
122 first = True
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
123 rev = u"00000000"
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
124 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
125 if first:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
126 first = False
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
127 if repr(line.getInterwikiEditorData(request)) != editor:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
128 return
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
129 else:
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
130 if repr(line.getInterwikiEditorData(request)) != editor:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
131 rev = line.rev
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
132 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
133
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1793
diff changeset
134 if rev == u"00000000": # page created by spammer
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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 savemsg = unicode(msg)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
148 return savemsg
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
149
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
150 def revert_pages(request, editor, timestamp):
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
151 _ = request.getText
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
152
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 14
diff changeset
153 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
154 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
155 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
156 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
157 revertpages = []
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
158 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
159 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
160 break
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
161
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
162 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
163 continue
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
164
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 448
diff changeset
165 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
166 pages[line.pagename] = 1
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
167 if repr(line.getInterwikiEditorData(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
168 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
169
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
170 request.write("Pages to revert:<br>%s" % "<br>".join(revertpages))
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
171 for pagename in revertpages:
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
172 request.write("Begin reverting %s ...<br>" % pagename)
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
173 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
174 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
175 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
176 Page.Page(request, pagename).link_to(request), msg))
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
177 request.write("Finished reverting %s.<br>" % pagename)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
178
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
179 def execute(pagename, request):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
180 _ = request.getText
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
181 # be extra paranoid in dangerous actions
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
182 actname = __name__.split('.')[-1]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
183 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
184 not request.user.isSuperUser():
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: 2286
diff changeset
185 request.theme.add_msg(_('You are not allowed to use this action.'), "error")
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: 2286
diff changeset
186 return Page.Page(request, pagename).send_page()
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
187
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
188 editor = request.form.get('editor', [None])[0]
3094
92e5cf67842f fixed Despam action: editor grouping was broken, increase time interval to 30d (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2966
diff changeset
189 timestamp = time.time() - DAYS * 24 * 3600
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
190 # request.form.get('timestamp', [None])[0]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
191 ok = request.form.get('ok', [0])[0]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
192
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 949
diff changeset
193 request.emit_http_headers()
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
194 request.theme.send_title("Despam", pagename=pagename)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
195 # Start content (important for RTL support)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
196 request.write(request.formatter.startContent("content"))
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
197
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
198 if ok:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
199 revert_pages(request, editor, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
200 elif editor:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
201 show_pages(request, pagename, editor, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
202 else:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
203 show_editors(request, pagename, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
204
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
205 # End content and send footer
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
206 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
207 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
208 request.theme.send_closing_html()
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
209