Back to index

moin  1.9.0~rc2
OrphanedPages.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - OrphanedPages Macro
00004 
00005     @copyright: 2001 Juergen Hermann <jh@web.de>
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 Dependencies = ["pages"]
00010 
00011 def macro_OrphanedPages(macro):
00012     _ = macro.request.getText
00013 
00014     if macro.request.mode_getpagelinks: # prevent recursion
00015         return ''
00016     if macro.request.isSpiderAgent: # reduce bot cpu usage
00017         return ''
00018 
00019     # delete all linked pages from a dict of all pages
00020     pages = macro.request.rootpage.getPageDict()
00021     orphaned = {}
00022     orphaned.update(pages)
00023     for page in pages.values():
00024         links = page.getPageLinks(macro.request)
00025         for link in links:
00026             if link in orphaned:
00027                 del orphaned[link]
00028 
00029     result = []
00030     f = macro.formatter
00031     if not orphaned:
00032         result.append(f.paragraph(1))
00033         result.append(f.text(_("No orphaned pages in this wiki.")))
00034         result.append(f.paragraph(0))
00035     else:
00036         # return a list of page links
00037         orphanednames = orphaned.keys()
00038         orphanednames.sort()
00039         result.append(f.number_list(1))
00040         for name in orphanednames:
00041             if not name:
00042                 continue
00043             result.append(f.listitem(1))
00044             result.append(f.pagelink(1, name, generated=1))
00045             result.append(f.text(name))
00046             result.append(f.pagelink(0, name))
00047             result.append(f.listitem(0))
00048         result.append(f.number_list(0))
00049 
00050     return ''.join(result)
00051