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