Attachment 'DeletedPages_lowlevel.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - DeletedPages Macro (Low-Level-Version)
   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     This is a low-level-version of the DeletedPages Macro and
   9     thus much, much faster than the normal high-level-version.
  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 import os 
  31 from MoinMoin import wikiutil
  32 from MoinMoin import wikimacro
  33 from MoinMoin import user
  34 from MoinMoin.Page import Page
  35 
  36 
  37 Dependencies = ["pages"]
  38 
  39 def execute(macro, args):
  40     request = macro.request
  41     _ = request.getText
  42     formatter = macro.formatter
  43     pagename = formatter.page.page_name
  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     html = []
  52     index_letters = []
  53     path_data = os.path.join (request.cfg.moinmoin_dir, request.cfg.data_dir, 'pages')
  54     pages += os.listdir (path_data)
  55 
  56     # Sort ignoring case
  57     tmp = [(name.upper(), name) for name in pages]
  58     tmp.sort()
  59     pages = [item[1] for item in tmp]
  60                 
  61     current_letter = None
  62     for name in pages:
  63         wikipagename = wikiutil.unquoteWikiname(name)
  64         if (Page(request, wikipagename).exists() == False): 
  65             letter = wikiutil.getUnicodeIndexGroup(wikipagename)
  66             if letter not in index_letters:
  67                 index_letters.append(letter)
  68             if letter != current_letter:
  69                 html.append(u'<a name="%s"><h3>%s</h3></a>' % (
  70                     wikiutil.quoteWikinameURL(letter), letter.replace('~', 'Others')))
  71                 current_letter = letter
  72             else:
  73                 html.append(u'<br>')
  74             html += macro.formatter.div(1, css_class='searchresults')       
  75             html += macro.formatter.definition_list(1)
  76         
  77             html += macro.formatter.definition_term(1)
  78             html.append(u'%s\n' % Page(request, wikipagename).link_to(request, attachment_indicator=1))
  79             html += macro.formatter.definition_term(0)
  80     
  81             html += macro.formatter.definition_desc(1)
  82             acl = Page(request, wikipagename).getACL(request)
  83             aclstring = acl.getString()
  84             if aclstring == '':
  85                 aclstring = '-'
  86             html.append(u'%s ' % aclstring)
  87             html += macro.formatter.linebreak(0)
  88             rev = Page(request, wikipagename).get_real_rev()
  89             if rev > 1:
  90                 rev = rev-1
  91             html.append(u'%s ' % Page(request, wikipagename).link_to(request, _('[Unerase] '), "action=revert&rev=%d" %rev))
  92             html.append(u'%s ' % Page(request, wikipagename).link_to(request, _('[Purge completely] '), "action=purge"))
  93             html += macro.formatter.definition_desc(0)
  94         
  95             html += macro.formatter.definition_list(0)
  96             html += macro.formatter.div(0, css_class='searchresults') 
  97             
  98     index = _make_index_key(index_letters)
  99     return u'%s%s' % (index, u''.join(html))
 100 
 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.