Attachment 'DeletedPages.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - DeletedPages Macro
   4 
   5     This macro shows a list of pages that have been deleted by
   6     ?action=delete but still exist silently on disc.
   7     You need to be superuser to call this macro.
   8 
   9     Syntax:
  10     
  11     [[DeletedPages]]
  12     
  13     @copyright: 2006 by Oliver Siemoneit
  14     @license: GNU GPL, see COPYING for details.
  15 
  16     DeletedPages partly based on _macro_TitleSearch from
  17     wikimarco.py by Jürgen Hermann
  18     @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
  19     @license: GNU GPL, see COPYING for details.
  20 
  21     Changes:
  22 
  23     Version 1.1 by Oliver Siemoneit
  24     * Macro supports multilang if translations for
  25       '[Unerase] ' and '[Purge completely] ' are provided elsewhere.
  26 
  27     
  28 """
  29 
  30 
  31 import os
  32 from MoinMoin import wikiutil
  33 from MoinMoin import wikimacro
  34 from MoinMoin import user
  35 from MoinMoin.Page import Page
  36 
  37 
  38 Dependencies = ["pages"]
  39 
  40 def execute(macro, args):
  41     request = macro.request
  42     _ = request.getText
  43     formatter = macro.formatter
  44         
  45     # Check if user is superuser. If not: return with error msg
  46     if not request.user.isSuperUser():
  47         err = _('You are not allowed to perform this action.')
  48         return "%s%s%s" % (formatter.sysmsg(1), formatter.text(err), formatter.sysmsg(0))
  49 
  50     pages = []
  51     visible_pages = request.rootpage.getPageList(exists=1)
  52     existing_pages = request.rootpage.getPageList(exists=0)
  53     for page in existing_pages:
  54         if visible_pages.count(page) == 0:
  55             pages.append(page)
  56     html = []
  57     index_letters = []
  58     
  59     # Sort ignoring case
  60     tmp = [(name.upper(), name) for name in pages]
  61     tmp.sort()
  62     pages = [item[1] for item in tmp]
  63                 
  64     current_letter = None
  65     for wikipagename in pages:
  66         letter = wikiutil.getUnicodeIndexGroup(wikipagename)
  67         if letter not in index_letters:
  68             index_letters.append(letter)
  69         if letter != current_letter:
  70             html.append(u'<a name="%s"><h3>%s</h3></a>' % (
  71                 wikiutil.quoteWikinameURL(letter), letter.replace('~', 'Others')))
  72             current_letter = letter
  73         else:
  74             html.append(u'<br>')
  75         html += macro.formatter.div(1, css_class='searchresults')       
  76         html += macro.formatter.definition_list(1)
  77         
  78         html += macro.formatter.definition_term(1)
  79         html.append(u'%s\n' % Page(request, wikipagename).link_to(request, attachment_indicator=1))
  80         html += macro.formatter.definition_term(0)
  81     
  82         html += macro.formatter.definition_desc(1)
  83         acl = Page(request, wikipagename).getACL(request)
  84         aclstring = acl.getString()
  85         if aclstring == '':
  86             aclstring = '-'
  87         html.append(u'%s ' % aclstring)
  88         html += macro.formatter.linebreak(0)
  89         rev = Page(request, wikipagename).get_real_rev()
  90         if rev > 1:
  91             rev = rev-1
  92         html.append(u'%s ' % Page(request, wikipagename).link_to(request, _('[Unerase] '), "action=revert&rev=%d" %rev))
  93         html.append(u'%s ' % Page(request, wikipagename).link_to(request, _('[Purge completely] '), "action=purge"))
  94         html += macro.formatter.definition_desc(0)
  95         
  96         html += macro.formatter.definition_list(0)
  97         html += macro.formatter.div(0, css_class='searchresults') 
  98        
  99     index = _make_index_key(index_letters)
 100     return u'%s%s' % (index, u''.join(html))
 101 
 102 
 103 def _make_index_key(index_letters, additional_html=""):
 104     index_letters.sort()
 105     links = map(lambda ch:
 106                     '<a href="#%s">%s</a>' %
 107                     (wikiutil.quoteWikinameURL(ch), ch.replace('~', 'Others')),
 108                 index_letters)
 109     return "<p>%s%s</p>" % (' | '.join(links), additional_html)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-11-27 20:54:50, 3.8 KB) [[attachment:DeletedPages.py]]
  • [get | view] (2006-11-30 19:51:16, 4.0 KB) [[attachment:DeletedPages_lowlevel.py]]
  • [get | view] (2006-11-27 20:57:31, 1.6 KB) [[attachment:purge.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.