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.
  • [get | view] (2003-12-07 18:15:54, 6.8 KB) [[attachment:AttachmentLink.py]]
  • [get | view] (2003-12-07 18:15:54, 16.7 KB) [[attachment:Blog.py]]
  • [get | view] (2003-12-07 18:15:54, 2.8 KB) [[attachment:IncludeCalendarPage.py]]
  • [get | view] (2003-12-07 18:15:54, 3.0 KB) [[attachment:IncludePages.py]]
  • [get | view] (2005-03-14 22:41:00, 2.7 KB) [[attachment:LinkedFrom-1.3.py]]
  • [get | view] (2003-12-07 18:15:54, 2.9 KB) [[attachment:LinkedFrom.py]]
  • [get | view] (2003-12-07 18:15:54, 3.2 KB) [[attachment:PageLinks.py]]
  • [get | view] (2003-12-07 18:15:54, 3.1 KB) [[attachment:autosub.py]]
  • [get | view] (2003-12-07 18:15:54, 2.3 KB) [[attachment:cc-20030808.tgz]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.