Attachment 'LinkedFrom-1.3.py'
Download 1 """
2 MoinMoin - LinkedFrom Macro
3
4 Charles.Crichton (in the domain of) comlab.ox.ac.uk
5
6
7 Usage: [[LinkedFrom]] - List all the pages that statically link to the current page.
8 [[LinkedFrom(regexp)]] - Only lists the linking pages that match the regular expression.
9
10 Use this macro to show a list of all those pages that are linking to the current page. Optionally
11 this list can be restricted to those pages that match a particular regular expression.
12
13 I use it to keep a list of topic pages - such as ["Topic: UML"].
14 Each of these topics contains a [[LinkedFrom]] macro.
15
16 I then have a page for each paper which I have read. If the paper covers a particular topic I place
17 a link to the topic on the page related to the paper. ["Topic: UML"] for example. The page then shows
18 up automatically on the topic page.
19
20 """
21
22 # Imports
23 from MoinMoin import config, user, wikiutil
24 from MoinMoin.Page import Page
25
26 import sys, cStringIO, re
27
28
29
30 def execute(macro, args):
31 request = macro.request
32 _ = request.getText
33
34 if not args:
35 pagename_re = re.compile(".*")
36 else:
37 try:
38 pagename_re = re.compile(args)
39 except re.error, e:
40 return '<p><strong class="error">%s</strong></p>' % _('Error in regular expression.')
41
42 # prevent recursion
43 if request.mode_getpagelinks:
44 return ''
45
46 # kpk change
47 #pages = wikiutil.getPageList(config.text_dir)
48 pages = request.rootpage.getPageList()
49 # end kpk change
50 pagelist = filter(pagename_re.search, pages)
51
52 linkedfrom = {}
53
54 this_page = macro.formatter.page
55
56 for other_page_name in pagelist:
57 other_page = Page(request, other_page_name)
58 if other_page != this_page:
59 links = other_page.getPageLinks(macro.request)
60 for link in links:
61 if link == this_page.page_name:
62 linkedfrom[other_page.page_name] = other_page.page_name
63
64 # check for the extreme case
65 if not linkedfrom:
66 return "" #"<p><b>%s</b></p>" % _("No other pages link to this page in this wiki.")
67
68 # return a list of page links
69 linkedfromnames = linkedfrom.keys()
70 linkedfromnames.sort()
71 result = []
72 result.append(macro.formatter.number_list(1))
73 for name in linkedfromnames:
74 if not name: continue
75 result.append(macro.formatter.listitem(1))
76 result.append(macro.formatter.pagelink(1, name, generated=1))
77 result.append(macro.formatter.text(name))
78 result.append(macro.formatter.pagelink(0))
79 result.append(macro.formatter.listitem(0))
80 result.append(macro.formatter.number_list(0))
81
82 return ''.join(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.