Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.action.Despam Namespace Reference

Classes

class  tmp

Functions

def render
def show_editors
def show_pages
def revert_page
def revert_pages
def execute

Variables

int DAYS = 30
tuple logging = log.getLogger(__name__)

Class Documentation

class MoinMoin::action::Despam::tmp

Definition at line 79 of file Despam.py.


Function Documentation

def MoinMoin.action.Despam.execute (   pagename,
  request 
)

Definition at line 181 of file Despam.py.

00181 
00182 def execute(pagename, request):
00183     _ = request.getText
00184     # check for superuser
00185     if not request.user.isSuperUser():
00186         request.theme.add_msg(_('You are not allowed to use this action.'), "error")
00187         return Page.Page(request, pagename).send_page()
00188 
00189     editor = request.values.get('editor')
00190     timestamp = time.time() - DAYS * 24 * 3600
00191     ok = request.form.get('ok', 0)
00192     logging.debug("editor: %r ok: %r" % (editor, ok))
00193 
00194     request.theme.send_title("Despam", pagename=pagename)
00195     # Start content (important for RTL support)
00196     request.write(request.formatter.startContent("content"))
00197 
00198     if ok:
00199         revert_pages(request, editor, timestamp)
00200     elif editor:
00201         show_pages(request, pagename, editor, timestamp)
00202     else:
00203         request.write(show_editors(request, pagename, timestamp))
00204 
00205     # End content and send footer
00206     request.write(request.formatter.endContent())
00207     request.theme.send_footer(pagename)
00208     request.theme.send_closing_html()
00209 

Here is the call graph for this function:

def MoinMoin.action.Despam.render (   editor_tuple)

Definition at line 24 of file Despam.py.

00024 
00025 def render(editor_tuple):
00026     etype, evalue = editor_tuple
00027     if etype in ('ip', 'email', ):
00028         ret = evalue
00029     elif etype == 'interwiki':
00030         ewiki, euser = evalue
00031         if ewiki == 'Self':
00032             ret = euser
00033         else:
00034             ret = '%s:%s' % evalue
00035     else:
00036         ret = repr(editor_tuple)
00037     return ret

Here is the caller graph for this function:

def MoinMoin.action.Despam.revert_page (   request,
  pagename,
  editor 
)

Definition at line 118 of file Despam.py.

00118 
00119 def revert_page(request, pagename, editor):
00120     if not request.user.may.revert(pagename):
00121         return
00122 
00123     log = editlog.EditLog(request, rootpagename=pagename)
00124 
00125     first = True
00126     rev = u"00000000"
00127     for line in log.reverse():
00128         if first:
00129             first = False
00130             if repr(line.getInterwikiEditorData(request)) != editor:
00131                 return
00132         else:
00133             if repr(line.getInterwikiEditorData(request)) != editor:
00134                 rev = line.rev
00135                 break
00136 
00137     if rev == u"00000000": # page created by spammer
00138         comment = u"Page deleted by Despam action"
00139         pg = PageEditor.PageEditor(request, pagename, do_editor_backup=0)
00140         try:
00141             savemsg = pg.deletePage(comment)
00142         except pg.SaveError, msg:
00143             savemsg = unicode(msg)
00144     else: # page edited by spammer
00145         oldpg = Page.Page(request, pagename, rev=int(rev))
00146         pg = PageEditor.PageEditor(request, pagename, do_editor_backup=0)
00147         try:
00148             savemsg = pg.saveText(oldpg.get_raw_body(), 0, extra=rev, action="SAVE/REVERT")
00149         except pg.SaveError, msg:
00150             savemsg = unicode(msg)
00151     return savemsg

Here is the caller graph for this function:

def MoinMoin.action.Despam.revert_pages (   request,
  editor,
  timestamp 
)

Definition at line 152 of file Despam.py.

00152 
00153 def revert_pages(request, editor, timestamp):
00154     _ = request.getText
00155 
00156     editor = wikiutil.url_unquote(editor)
00157     timestamp = int(timestamp * 1000000)
00158     log = editlog.EditLog(request)
00159     pages = {}
00160     revertpages = []
00161     for line in log.reverse():
00162         if line.ed_time_usecs < timestamp:
00163             break
00164 
00165         if not request.user.may.read(line.pagename):
00166             continue
00167 
00168         if not line.pagename in pages:
00169             pages[line.pagename] = 1
00170             if repr(line.getInterwikiEditorData(request)) == editor:
00171                 revertpages.append(line.pagename)
00172 
00173     request.write("Pages to revert:<br>%s" % "<br>".join(revertpages))
00174     for pagename in revertpages:
00175         request.write("Begin reverting %s ...<br>" % pagename)
00176         msg = revert_page(request, pagename, editor)
00177         if msg:
00178             request.write("<p>%s: %s</p>" % (
00179                 Page.Page(request, pagename).link_to(request), msg))
00180         request.write("Finished reverting %s.<br>" % pagename)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.Despam.show_editors (   request,
  pagename,
  timestamp 
)

Definition at line 38 of file Despam.py.

00038 
00039 def show_editors(request, pagename, timestamp):
00040     _ = request.getText
00041 
00042     timestamp = int(timestamp * 1000000)
00043     log = editlog.EditLog(request)
00044     editors = {}
00045     pages = {}
00046     for line in log.reverse():
00047         if line.ed_time_usecs < timestamp:
00048             break
00049 
00050         if not request.user.may.read(line.pagename):
00051             continue
00052 
00053         editor = line.getInterwikiEditorData(request)
00054         if not line.pagename in pages:
00055             pages[line.pagename] = 1
00056             editors[editor] = editors.get(editor, 0) + 1
00057 
00058     editors = [(nr, editor) for editor, nr in editors.iteritems()]
00059     editors.sort()
00060     editors.reverse()
00061 
00062     pg = Page.Page(request, pagename)
00063 
00064     dataset = TupleDataset()
00065     dataset.columns = [Column('editor', label=_("Editor"), align='left'),
00066                        Column('pages', label=_("Pages"), align='right'),
00067                        Column('link', label='', align='left')]
00068     for nr, editor in editors:
00069         dataset.addRow((render(editor), unicode(nr),
00070             pg.link_to(request, text=_("Select Author"),
00071                 querystr={
00072                     'action': 'Despam',
00073                     'editor': repr(editor),
00074                 })))
00075 
00076     table = DataBrowserWidget(request)
00077     table.setData(dataset)
00078     return table.render(method="GET")

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.Despam.show_pages (   request,
  pagename,
  editor,
  timestamp 
)

Definition at line 82 of file Despam.py.

00082 
00083 def show_pages(request, pagename, editor, timestamp):
00084     _ = request.getText
00085 
00086     timestamp = int(timestamp * 1000000)
00087     log = editlog.EditLog(request)
00088     pages = {}
00089     #  mimic macro object for use of RecentChanges subfunctions
00090     macro = tmp()
00091     macro.request = request
00092     macro.formatter = request.html_formatter
00093 
00094     request.write("<table>")
00095     for line in log.reverse():
00096         if line.ed_time_usecs < timestamp:
00097             break
00098 
00099         if not request.user.may.read(line.pagename):
00100             continue
00101 
00102         if not line.pagename in pages:
00103             pages[line.pagename] = 1
00104             if repr(line.getInterwikiEditorData(request)) == editor:
00105                 line.time_tuple = request.user.getTime(wikiutil.version2timestamp(line.ed_time_usecs))
00106                 request.write(RecentChanges.format_page_edits(macro, [line], timestamp))
00107 
00108     request.write('''
00109 </table>
00110 <p>
00111 <form method="post" action="%s">
00112 <input type="hidden" name="action" value="Despam">
00113 <input type="hidden" name="editor" value="%s">
00114 <input type="submit" name="ok" value="%s">
00115 </form>
00116 </p>
00117 ''' % (request.href(pagename), wikiutil.url_quote(editor), _("Revert all!")))

Here is the caller graph for this function:


Variable Documentation

Definition at line 11 of file Despam.py.

Definition at line 16 of file Despam.py.