1
2
3 """
4 MoinMoin - Orphans Macro
5
6 Copyright (c) 2001 by Richard Jones <richard@bizarsoftware.com.au>
7 Copyright (c) 2000 by J\374rgen Hermann <jh@web.de>
8 All rights reserved, see COPYING for details.
9
10 with modifications by Christian Bird <chris.bird@lineo.com>:
11 The Orphans macro written by Richard Jones is a pretty good idea.
12 The only problem is that it runs in O(n^2) time which slows down
13 polynomially as the site grows. Ours consisting of 300+ pages takes
14 over almost a minute to run the Orphans macro. This faster macro takes
15 advantage of hashing, compiling the regular expression only once and a
16 couple other things to run faster in O(n) time, so it slows down
17 linearly. On our site, the macro execution time isn't noticeable.
18
19 $Id: $
20 """
21
22
23 import string, re
24 from MoinMoin import config, wikiutil, Page
25
26 def execute(macro, args):
27
28 all_pages = wikiutil.getPageList(config.text_dir)
29
30
31 page_hash = {}
32 for page in all_pages:
33 page_hash[page] = 0
34
35
36
37
38
39 wiki_re = re.compile("((?:[A-Z][a-z]+){2,})")
40
41 for page_name in all_pages:
42 page = Page.Page(page_name).get_raw_body()
43
44 wiki_names = wiki_re.findall(page)
45
46 for name in wiki_names:
47 if page_hash.has_key(name): page_hash[name] = 1
48
49
50 if 0 not in page_hash.values() :
51 return macro.formatter.strong(1) + 'No Orphan pages' + \
52 macro.formatter.strong(0)
53
54 all_pages.sort()
55 l = [macro.formatter.strong(1), 'Orphan pages:',
56 macro.formatter.strong(0), macro.formatter.bullet_list(1)]
57
58 for name in all_pages:
59 if not page_hash[name]:
60 l.append(macro.formatter.listitem(1))
61 l.append(macro.formatter.pagelink(name))
62 l.append(macro.formatter.listitem(0))
63 l.append(macro.formatter.bullet_list(0))
64
65 return string.join(l, '\n')
MoinMoin: macro/FasterOrphans.py (last edited 2007-10-29 19:13:40 by localhost)