Attachment 'PageLinks.py'
Download 1 """
2 MoinMoin - PageLinks Macro
3
4 Modified from the OrphanedPages Macro by Jürgen Hermann
5 and the PartialInclude Macro written by Seth Shikora.
6 by Charles Crichton, Oxford University Computing Laboratory (2003)
7
8 Portions copyright (c) 2001 by Jürgen Hermann <jh@web.de>
9 All rights reserved, see COPYING for details.
10
11 This macro may be used to create a list of links to pages in the wiki. Pages may (or may not)
12 exist for these links. A regular expression may be specified so that only links corresponding
13 to a particular pattern are listed.
14
15 Usage:
16
17 [[PageLinks]] - List all of the page links in a wiki.
18 [[PageLinks(regexp)]] - Lists only those links corresponding to a particular regular expression.
19
20 I use this to build menus of pages that I intend to write - alongside those that I have already
21 written. More specifically I keep a list of academic papers. When I am editing my comments on a particular
22 paper I want to categorise the paper into a particular field so I add a link of the form ["Topic: field"]
23 to the paper.
24
25 I then have a page which lists all of the fields with the following on it:
26
27 [[PageLinks(Topic:.*)]]
28
29 This gives me a list of topics (which I may or may not have created a page for yet.)
30
31 Used in conjunction with the [[LinkedFrom]] macro this is a powerful way of managing links.
32
33 """
34
35 # Imports
36 from MoinMoin import config, user, wikiutil
37 from MoinMoin.Page import Page
38 from MoinMoin.i18n import _
39
40 import sys, cStringIO, re
41
42 _guard = 0
43
44
45 def execute(macro, args):
46
47 # prevent recursive calls
48 global _guard
49 if _guard: return ''
50
51 if not args:
52 pagename_re = re.compile(".*")
53 else:
54 try:
55 pagename_re = re.compile(args)
56 except re.error, e:
57 return '<p><strong class="error">%s</strong></p>' % _('Error in regular expression.')
58
59 _guard = 1
60
61 pagelist = wikiutil.getPageList(config.text_dir)
62
63 alllinks = filter(pagename_re.search, pagelist)
64
65 this_page = macro.formatter.page
66
67 for other_page_name in pagelist:
68 other_page = Page(other_page_name)
69 if other_page != this_page:
70 links = other_page.getPageLinks(macro.request)
71 for link in links:
72 alllinks.append(link)
73 _guard = 0
74
75 #pagelist = filter(pagename_re.search, pages)
76
77 linkedtonamesset = {}
78 for nametomatch in alllinks:
79 if pagename_re.match(nametomatch):
80 linkedtonamesset[nametomatch] = nametomatch
81
82 linkedtonames = linkedtonamesset.keys()
83
84 # check for the extreme case
85 if not linkedtonames:
86 return "<p><b>%s</b></p>" % _("No matching links in this wiki.")
87
88 # return a list of page links
89 linkedtonames.sort()
90 result = macro.formatter.bullet_list(1)
91 for name in linkedtonames:
92 if not name: continue
93 result = result + macro.formatter.listitem(1)
94 result = result + macro.formatter.pagelink(name, generated=1)
95 result = result + macro.formatter.listitem(0)
96 result = result + macro.formatter.bullet_list(0)
97
98 return result
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.You are not allowed to attach a file to this page.