"""
MoinMoin - Orphans Macro
Copyright (c) 2001 by Richard Jones <richard@bizarsoftware.com.au>
Copyright (c) 2000 by J\374rgen Hermann <jh@web.de>
All rights reserved, see COPYING for details.
with modifications by Christian Bird <chris.bird@lineo.com>
$Id: $
"""
# Imports
import string, re
from MoinMoin import config, wikiutil, Page
def execute(macro, args):
# select the pages from the page list
all_pages = wikiutil.getPageList(config.text_dir)
#create a hash of all pages for a checklist
page_hash = {}
for page in all_pages:
page_hash[page] = 0
# compile the wiki name regular expression, replace this with a better one
#because this one isn't totally complete
wiki_re = re.compile("((?:[A-Z][a-z]+){2,})")
for page_name in all_pages:
page = Page.Page(page_name).get_raw_body()
#get all the wikinames on this page
wiki_names = wiki_re.findall(page)
#if that wiki name exists then set the hash value to 1 (check it off the list)
for name in wiki_names:
if page_hash.has_key(name): page_hash[name] = 1
#If there are no zeroes then all pages were found!
if 0 not in page_hash.values() :
return macro.formatter.strong(1) + 'No Orphan pages' + \
macro.formatter.strong(0)
all_pages.sort()
l = [macro.formatter.strong(1), 'Orphan pages:',
macro.formatter.strong(0), macro.formatter.bullet_list(1)]
#for each page, if it wasn't checked off then display it
for name in all_pages:
if not page_hash[name]:
l.append(macro.formatter.listitem(1))
l.append(macro.formatter.pagelink(name))
l.append(macro.formatter.listitem(0))
l.append(macro.formatter.bullet_list(0))
return string.join(l, '\n')