annotate MoinMoin/action/Despam.py @ 5250:00ca621ffbc2 1.9.0rc1

updated underlay
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 03 Nov 2009 00:40:45 +0100
parents e86a7b66eb0e
children 2c992293ece4
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
4570
e86a7b66eb0e Despam: must use request.values because it also does GET requests, add logging/debug code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4569
diff changeset
15 from MoinMoin import log
e86a7b66eb0e Despam: must use request.values because it also does GET requests, add logging/debug code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4569
diff changeset
16 logging = log.getLogger(__name__)
e86a7b66eb0e Despam: must use request.values because it also does GET requests, add logging/debug code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4569
diff changeset
17
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
18 from MoinMoin.logfile import editlog
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
19 from MoinMoin.util.dataset import TupleDataset, Column
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
20 from MoinMoin.widget.browser import DataBrowserWidget
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
21 from MoinMoin import wikiutil, Page, PageEditor
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
22 from MoinMoin.macro import RecentChanges
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
23
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
24 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
25 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
26 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
27 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
28 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
29 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
30 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
31 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
32 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
33 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
34 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
35 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
36 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
37
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
38 def show_editors(request, pagename, timestamp):
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
39 _ = request.getText
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
40
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
41 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
42 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
43 editors = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
44 pages = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
45 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
46 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
47 break
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
48
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
49 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
50 continue
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
51
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
52 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
53 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
54 pages[line.pagename] = 1
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
55 editors[editor] = editors.get(editor, 0) + 1
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
56
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
57 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
58 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
59 editors.reverse()
14
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 pg = Page.Page(request, pagename)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
62
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
63 dataset = TupleDataset()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
64 dataset.columns = [Column('editor', label=_("Editor"), align='left'),
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
65 Column('pages', label=_("Pages"), align='right'),
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
66 Column('link', label='', align='left')]
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
67 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
68 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
69 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
70 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
71 'action': 'Despam',
4552
7d8c6d279cff Despam action: explicitely using repr() there is more clear than having it happen somewhere deeper in the code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
72 'editor': repr(editor),
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
73 })))
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
74
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
75 table = DataBrowserWidget(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
76 table.setData(dataset)
4093
742cabb168b9 browser._format: refactored input parameter "method". The default value is changed from "GET" to None. Now it does not add a form tag to the table on default. You have to give a value of "GET" or "POST" to add a form tag using the given method.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3907
diff changeset
77 return table.render(method="GET")
14
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 class tmp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
80 pass
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
81
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
82 def show_pages(request, pagename, editor, timestamp):
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
83 _ = request.getText
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
84
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
85 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
86 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
87 pages = {}
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
88 # mimic macro object for use of RecentChanges subfunctions
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
89 macro = tmp()
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
90 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
91 macro.formatter = request.html_formatter
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
92
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
93 request.write("<table>")
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
94 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
95 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
96 break
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
97
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
98 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
99 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
100
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 448
diff changeset
101 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
102 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
103 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
104 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
105 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
106
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
107 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
108 </table>
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
109 <p>
4235
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4201
diff changeset
110 <form method="post" action="%s">
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
111 <input type="hidden" name="action" value="Despam">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
112 <input type="hidden" name="editor" value="%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
113 <input type="submit" name="ok" value="%s">
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
114 </form>
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
115 </p>
4235
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4201
diff changeset
116 ''' % (request.href(pagename), wikiutil.url_quote(editor), _("Revert all!")))
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
117
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
118 def revert_page(request, pagename, editor):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
119 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
120 return
14
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 log = editlog.EditLog(request, rootpagename=pagename)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
123
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
124 first = True
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
125 rev = u"00000000"
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
126 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
127 if first:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
128 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
129 if repr(line.getInterwikiEditorData(request)) != editor:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
130 return
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
131 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
132 if repr(line.getInterwikiEditorData(request)) != editor:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
133 rev = line.rev
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
134 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
135
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1793
diff changeset
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 savemsg = unicode(msg)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
150 return savemsg
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
151
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
152 def revert_pages(request, editor, timestamp):
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
153 _ = request.getText
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
154
4569
3caaa8c74c41 wikiutil: replace moin's cgi/urllib wrappers by calls to werkzeug.utils code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4552
diff changeset
155 editor = wikiutil.url_unquote(editor)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
156 timestamp = int(timestamp * 1000000)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
157 log = editlog.EditLog(request)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
158 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
159 revertpages = []
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
160 for line in log.reverse():
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
161 if line.ed_time_usecs < timestamp:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
162 break
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
163
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
164 if not request.user.may.read(line.pagename):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
165 continue
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
166
551
17ab8fe4a94b refactored some d.has_key(k) to k in d (faster)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 448
diff changeset
167 if not line.pagename in pages:
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
168 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
169 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
170 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
171
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("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
173 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
174 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
175 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
176 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
177 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
178 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
179 request.write("Finished reverting %s.<br>" % pagename)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
180
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
181 def execute(pagename, request):
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
182 _ = request.getText
3525
ee0644a26e30 action Attachfile, Despam, backup, thread_monitor: removed duplicated checks done by request.__init__
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3213
diff changeset
183 # check for superuser
ee0644a26e30 action Attachfile, Despam, backup, thread_monitor: removed duplicated checks done by request.__init__
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3213
diff changeset
184 if 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
4570
e86a7b66eb0e Despam: must use request.values because it also does GET requests, add logging/debug code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4569
diff changeset
188 editor = request.values.get('editor')
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
4201
40acd13fb3d6 Changed form access to MultiDict forms
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4176
diff changeset
190 ok = request.form.get('ok', 0)
4570
e86a7b66eb0e Despam: must use request.values because it also does GET requests, add logging/debug code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4569
diff changeset
191 logging.debug("editor: %r ok: %r" % (editor, ok))
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
192
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
193 request.theme.send_title("Despam", pagename=pagename)
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
194 # Start content (important for RTL support)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
195 request.write(request.formatter.startContent("content"))
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
196
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
197 if ok:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
198 revert_pages(request, editor, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
199 elif editor:
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
200 show_pages(request, pagename, editor, timestamp)
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
201 else:
3905
0248e23277ef DataBrowserWidget: remove toHTML/render methods, change all callers to use .format()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3525
diff changeset
202 request.write(show_editors(request, pagename, timestamp))
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
203
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
204 # End content and send footer
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
205 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
206 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
207 request.theme.send_closing_html()
14
c8a7e012ebeb Despam / mass revert action, needs superuser
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
208