/usr/share/pyshared/MoinMoin/action/Despam.py is in python-moinmoin 1.9.3-1ubuntu2.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | # -*- coding: iso-8859-1 -*-
"""
MoinMoin - Despam action
Mass revert changes done by some specific author / bot.
@copyright: 2005 by ???, Thomas Waldmann
@license: GNU GPL, see COPYING for details.
"""
DAYS = 30 # we look for spam edits in the last x days
import time
from MoinMoin import log
logging = log.getLogger(__name__)
from MoinMoin.logfile import editlog
from MoinMoin.util.dataset import TupleDataset, Column
from MoinMoin.widget.browser import DataBrowserWidget
from MoinMoin import wikiutil, Page, PageEditor
from MoinMoin.macro import RecentChanges
def render(editor_tuple):
etype, evalue = editor_tuple
if etype in ('ip', 'email', ):
ret = evalue
elif etype == 'interwiki':
ewiki, euser = evalue
if ewiki == 'Self':
ret = euser
else:
ret = '%s:%s' % evalue
else:
ret = repr(editor_tuple)
return ret
def show_editors(request, pagename, timestamp):
_ = request.getText
timestamp = int(timestamp * 1000000)
log = editlog.EditLog(request)
editors = {}
pages = {}
for line in log.reverse():
if line.ed_time_usecs < timestamp:
break
if not request.user.may.read(line.pagename):
continue
editor = line.getInterwikiEditorData(request)
if not line.pagename in pages:
pages[line.pagename] = 1
editors[editor] = editors.get(editor, 0) + 1
editors = [(nr, editor) for editor, nr in editors.iteritems()]
editors.sort()
editors.reverse()
pg = Page.Page(request, pagename)
dataset = TupleDataset()
dataset.columns = [Column('editor', label=_("Editor"), align='left'),
Column('pages', label=_("Pages"), align='right'),
Column('link', label='', align='left')]
for nr, editor in editors:
dataset.addRow((render(editor), unicode(nr),
pg.link_to(request, text=_("Select Author"),
querystr={
'action': 'Despam',
'editor': repr(editor),
})))
table = DataBrowserWidget(request)
table.setData(dataset)
return table.render(method="GET")
class tmp:
pass
def show_pages(request, pagename, editor, timestamp):
_ = request.getText
timestamp = int(timestamp * 1000000)
log = editlog.EditLog(request)
pages = {}
# mimic macro object for use of RecentChanges subfunctions
macro = tmp()
macro.request = request
macro.formatter = request.html_formatter
request.write("<table>")
for line in log.reverse():
if line.ed_time_usecs < timestamp:
break
if not request.user.may.read(line.pagename):
continue
if not line.pagename in pages:
pages[line.pagename] = 1
if repr(line.getInterwikiEditorData(request)) == editor:
line.time_tuple = request.user.getTime(wikiutil.version2timestamp(line.ed_time_usecs))
request.write(RecentChanges.format_page_edits(macro, [line], timestamp))
request.write('''
</table>
<p>
<form method="post" action="%(url)s">
<input type="hidden" name="action" value="Despam">
<input type="hidden" name="ticket" value="%(ticket)s">
<input type="hidden" name="editor" value="%(editor)s">
<input type="submit" name="ok" value="%(label)s">
</form>
</p>
''' % dict(
url=request.href(pagename),
ticket=wikiutil.createTicket(request),
editor=wikiutil.url_quote(editor),
label=_("Revert all!"),
))
def revert_page(request, pagename, editor):
if not request.user.may.revert(pagename):
return
log = editlog.EditLog(request, rootpagename=pagename)
first = True
rev = u"00000000"
for line in log.reverse():
if first:
first = False
if repr(line.getInterwikiEditorData(request)) != editor:
return
else:
if repr(line.getInterwikiEditorData(request)) != editor:
rev = line.rev
break
if rev == u"00000000": # page created by spammer
comment = u"Page deleted by Despam action"
pg = PageEditor.PageEditor(request, pagename, do_editor_backup=0)
try:
savemsg = pg.deletePage(comment)
except pg.SaveError, msg:
savemsg = unicode(msg)
else: # page edited by spammer
oldpg = Page.Page(request, pagename, rev=int(rev))
pg = PageEditor.PageEditor(request, pagename, do_editor_backup=0)
try:
savemsg = pg.saveText(oldpg.get_raw_body(), 0, extra=rev, action="SAVE/REVERT")
except pg.SaveError, msg:
savemsg = unicode(msg)
return savemsg
def revert_pages(request, editor, timestamp):
_ = request.getText
editor = wikiutil.url_unquote(editor)
timestamp = int(timestamp * 1000000)
log = editlog.EditLog(request)
pages = {}
revertpages = []
for line in log.reverse():
if line.ed_time_usecs < timestamp:
break
if not request.user.may.read(line.pagename):
continue
if not line.pagename in pages:
pages[line.pagename] = 1
if repr(line.getInterwikiEditorData(request)) == editor:
revertpages.append(line.pagename)
request.write("Pages to revert:<br>%s" % "<br>".join([wikiutil.escape(p) for p in revertpages]))
for pagename in revertpages:
request.write("Begin reverting %s ...<br>" % wikiutil.escape(pagename))
msg = revert_page(request, pagename, editor)
if msg:
request.write("<p>%s: %s</p>" % (
Page.Page(request, pagename).link_to(request), msg))
request.write("Finished reverting %s.<br>" % wikiutil.escape(pagename))
def execute(pagename, request):
_ = request.getText
# check for superuser
if not request.user.isSuperUser():
request.theme.add_msg(_('You are not allowed to use this action.'), "error")
return Page.Page(request, pagename).send_page()
editor = request.values.get('editor')
timestamp = time.time() - DAYS * 24 * 3600
ok = request.form.get('ok', 0)
logging.debug("editor: %r ok: %r" % (editor, ok))
request.theme.send_title("Despam", pagename=pagename)
# Start content (important for RTL support)
request.write(request.formatter.startContent("content"))
if (request.method == 'POST' and ok and
wikiutil.checkTicket(request, request.form.get('ticket', ''))):
revert_pages(request, editor, timestamp)
elif editor:
show_pages(request, pagename, editor, timestamp)
else:
request.write(show_editors(request, pagename, timestamp))
# End content and send footer
request.write(request.formatter.endContent())
request.theme.send_footer(pagename)
request.theme.send_closing_html()
|