changeset 230:b38b28fbcfed

beginning of Despam fixing (todo: debug why it does only revert one new spam page), fixed typos imported from: moin--main--1.5--patch-233
author Thomas Waldmann <tw@waldmann-edv.de>
date Mon, 21 Nov 2005 08:37:18 +0000
parents 13bed76b7bc9
children 8c1468088e94
files MoinMoin/action/DeletePage.py MoinMoin/action/Despam.py
diffstat 2 files changed, 33 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/DeletePage.py	Sun Nov 20 21:35:09 2005 +0000
+++ b/MoinMoin/action/DeletePage.py	Mon Nov 21 08:37:18 2005 +0000
@@ -16,8 +16,8 @@
 def execute(pagename, request):
     _ = request.getText
     actname = __name__.split('.')[-1]
-    # Create a page editor that does not do edior backups, becuase
-    # delete generate "deleted" version, of the page.
+    # Create a page editor that does not do editor backups, because
+    # delete generates a "deleted" version of the page.
     page = PageEditor(request, pagename, do_editor_backup=0)
 
     # be extra paranoid in dangerous actions
@@ -51,7 +51,7 @@
     button = _('Delete')
     comment_label = _("Optional reason for the deletion")
 
-    # TODO: this form suck, redesign like RenamePage
+    # TODO: this form sucks, redesign like RenamePage
     formhtml = '''
 <form method="post" action="">
 <strong>%(querytext)s</strong>
--- a/MoinMoin/action/Despam.py	Sun Nov 20 21:35:09 2005 +0000
+++ b/MoinMoin/action/Despam.py	Mon Nov 21 08:37:18 2005 +0000
@@ -67,22 +67,22 @@
     macro.request = request
     macro.formatter = Formatter(request)
 
-    request.write("<p>")
+    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 pages.has_key(line.pagename):
             pages[line.pagename] = 1
             if line.getEditor(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('''
-</p>
+</table>
 <p>
 <form method="post" action="%s/%s">
 <input type="hidden" name="action" value="Despam">
@@ -110,13 +110,21 @@
             if line.getEditor(request) != editor:
                 rev = line.rev
                 break
-    oldpg = Page.Page(request, pagename, rev=int(rev))
-    pg = PageEditor.PageEditor(request, pagename)
-    try:
-        savemsg = pg.saveText(oldpg.get_raw_body(), 0, extra=rev, action="SAVE/REVERT")
-    except pg.SaveError, msg:
-        # msg contain a unicode string
-        savemsg = unicode(msg)
+
+    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):
@@ -126,7 +134,7 @@
     timestamp = int(timestamp * 1000000)
     log = editlog.EditLog(request)
     pages = {}
-    messages = []
+    revertpages = []
     for line in log.reverse():
         if line.ed_time_usecs < timestamp:
             break
@@ -137,10 +145,16 @@
         if not pages.has_key(line.pagename):
             pages[line.pagename] = 1
             if line.getEditor(request) == editor:
-                msg = revert_page(request, line.pagename, editor)
-                if msg:
-                    request.write("<p>%s: %s</p>" % (
-                        Page.Page(request, line.pagename).link_to(request), msg))
+                revertpages.append(line.pagename)
+
+    request.write("Debug: Pages to revert:<br>%s" % "<br>".join(revertpages))
+    for pagename in revertpages:
+        request.write("Debug: Begin reverting %s ...<br>" % 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("Debug: Finished reverting %s.<br>" % pagename)
 
 def execute(pagename, request):
     _ = request.getText