comparison 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
comparison
equal deleted inserted replaced
3093:0f64646b9deb 3094:92e5cf67842f
5 Mass revert changes done by some specific author / bot. 5 Mass revert changes done by some specific author / bot.
6 6
7 @copyright: 2005 by ???, Thomas Waldmann 7 @copyright: 2005 by ???, Thomas Waldmann
8 @license: GNU GPL, see COPYING for details. 8 @license: GNU GPL, see COPYING for details.
9 """ 9 """
10
11 DAYS = 30 # we look for spam edits in the last x days
10 12
11 import time 13 import time
12 14
13 from MoinMoin.logfile import editlog 15 from MoinMoin.logfile import editlog
14 from MoinMoin.util.dataset import TupleDataset, Column 16 from MoinMoin.util.dataset import TupleDataset, Column
15 from MoinMoin.widget.browser import DataBrowserWidget 17 from MoinMoin.widget.browser import DataBrowserWidget
16 from MoinMoin import wikiutil, Page, PageEditor 18 from MoinMoin import wikiutil, Page, PageEditor
17 from MoinMoin.macro import RecentChanges 19 from MoinMoin.macro import RecentChanges
18 20
21 def render(editor_tuple):
22 etype, evalue = editor_tuple
23 if etype in ('ip', 'email', ):
24 ret = evalue
25 elif etype == 'interwiki':
26 ewiki, euser = evalue
27 if ewiki == 'Self':
28 ret = euser
29 else:
30 ret = '%s:%s' % evalue
31 else:
32 ret = repr(editor_tuple)
33 return ret
34
19 def show_editors(request, pagename, timestamp): 35 def show_editors(request, pagename, timestamp):
20 _ = request.getText 36 _ = request.getText
21 37
22 timestamp = int(timestamp * 1000000) 38 timestamp = int(timestamp * 1000000)
23 log = editlog.EditLog(request) 39 log = editlog.EditLog(request)
28 break 44 break
29 45
30 if not request.user.may.read(line.pagename): 46 if not request.user.may.read(line.pagename):
31 continue 47 continue
32 48
33 editor = line.getEditor(request) 49 editor = line.getInterwikiEditorData(request)
34 if not line.pagename in pages: 50 if not line.pagename in pages:
35 pages[line.pagename] = 1 51 pages[line.pagename] = 1
36 editors[editor] = editors.get(editor, 0) + 1 52 editors[editor] = editors.get(editor, 0) + 1
37 53
38 editors = [(nr, editor) for editor, nr in editors.iteritems()] 54 editors = [(nr, editor) for editor, nr in editors.iteritems()]
39 editors.sort() 55 editors.sort()
56 editors.reverse()
40 57
41 pg = Page.Page(request, pagename) 58 pg = Page.Page(request, pagename)
42 59
43 dataset = TupleDataset() 60 dataset = TupleDataset()
44 dataset.columns = [Column('editor', label=_("Editor"), align='left'), 61 dataset.columns = [Column('editor', label=_("Editor"), align='left'),
45 Column('pages', label=_("Pages"), align='right'), 62 Column('pages', label=_("Pages"), align='right'),
46 Column('link', label='', align='left')] 63 Column('link', label='', align='left')]
47 for nr, editor in editors: 64 for nr, editor in editors:
48 dataset.addRow((editor, unicode(nr), 65 dataset.addRow((render(editor), unicode(nr),
49 pg.link_to(request, text=_("Select Author"), 66 pg.link_to(request, text=_("Select Author"),
50 querystr={ 67 querystr={
51 'action': 'Despam', 68 'action': 'Despam',
52 'editor': editor, # was: url_quote_plus() 69 'editor': editor, # was: url_quote_plus()
53 }))) 70 })))
78 if not request.user.may.read(line.pagename): 95 if not request.user.may.read(line.pagename):
79 continue 96 continue
80 97
81 if not line.pagename in pages: 98 if not line.pagename in pages:
82 pages[line.pagename] = 1 99 pages[line.pagename] = 1
83 if line.getEditor(request) == editor: 100 if repr(line.getInterwikiEditorData(request)) == editor:
84 line.time_tuple = request.user.getTime(wikiutil.version2timestamp(line.ed_time_usecs)) 101 line.time_tuple = request.user.getTime(wikiutil.version2timestamp(line.ed_time_usecs))
85 request.write(RecentChanges.format_page_edits(macro, [line], timestamp)) 102 request.write(RecentChanges.format_page_edits(macro, [line], timestamp))
86 103
87 request.write(''' 104 request.write('''
88 </table> 105 </table>
105 first = True 122 first = True
106 rev = u"00000000" 123 rev = u"00000000"
107 for line in log.reverse(): 124 for line in log.reverse():
108 if first: 125 if first:
109 first = False 126 first = False
110 if line.getEditor(request) != editor: 127 if repr(line.getInterwikiEditorData(request)) != editor:
111 return 128 return
112 else: 129 else:
113 if line.getEditor(request) != editor: 130 if repr(line.getInterwikiEditorData(request)) != editor:
114 rev = line.rev 131 rev = line.rev
115 break 132 break
116 133
117 if rev == u"00000000": # page created by spammer 134 if rev == u"00000000": # page created by spammer
118 comment = u"Page deleted by Despam action" 135 comment = u"Page deleted by Despam action"
145 if not request.user.may.read(line.pagename): 162 if not request.user.may.read(line.pagename):
146 continue 163 continue
147 164
148 if not line.pagename in pages: 165 if not line.pagename in pages:
149 pages[line.pagename] = 1 166 pages[line.pagename] = 1
150 if line.getEditor(request) == editor: 167 if repr(line.getInterwikiEditorData(request)) == editor:
151 revertpages.append(line.pagename) 168 revertpages.append(line.pagename)
152 169
153 request.write("Debug: Pages to revert:<br>%s" % "<br>".join(revertpages)) 170 request.write("Pages to revert:<br>%s" % "<br>".join(revertpages))
154 for pagename in revertpages: 171 for pagename in revertpages:
155 request.write("Debug: Begin reverting %s ...<br>" % pagename) 172 request.write("Begin reverting %s ...<br>" % pagename)
156 msg = revert_page(request, pagename, editor) 173 msg = revert_page(request, pagename, editor)
157 if msg: 174 if msg:
158 request.write("<p>%s: %s</p>" % ( 175 request.write("<p>%s: %s</p>" % (
159 Page.Page(request, pagename).link_to(request), msg)) 176 Page.Page(request, pagename).link_to(request), msg))
160 request.write("Debug: Finished reverting %s.<br>" % pagename) 177 request.write("Finished reverting %s.<br>" % pagename)
161 178
162 def execute(pagename, request): 179 def execute(pagename, request):
163 _ = request.getText 180 _ = request.getText
164 # be extra paranoid in dangerous actions 181 # be extra paranoid in dangerous actions
165 actname = __name__.split('.')[-1] 182 actname = __name__.split('.')[-1]
167 not request.user.isSuperUser(): 184 not request.user.isSuperUser():
168 request.theme.add_msg(_('You are not allowed to use this action.'), "error") 185 request.theme.add_msg(_('You are not allowed to use this action.'), "error")
169 return Page.Page(request, pagename).send_page() 186 return Page.Page(request, pagename).send_page()
170 187
171 editor = request.form.get('editor', [None])[0] 188 editor = request.form.get('editor', [None])[0]
172 timestamp = time.time() - 24 * 3600 189 timestamp = time.time() - DAYS * 24 * 3600
173 # request.form.get('timestamp', [None])[0] 190 # request.form.get('timestamp', [None])[0]
174 ok = request.form.get('ok', [0])[0] 191 ok = request.form.get('ok', [0])[0]
175 192
176 request.emit_http_headers() 193 request.emit_http_headers()
177 request.theme.send_title("Despam", pagename=pagename) 194 request.theme.send_title("Despam", pagename=pagename)