comparison MoinMoin/macro/WantedPages.py @ 0:77665d8e2254

tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0 (automatically generated log message) imported from: moin--main--1.5--base-0
author Thomas Waldmann <tw-public@gmx.de>
date Thu, 22 Sep 2005 15:09:50 +0000
parents
children 2202f548cbb0
comparison
equal deleted inserted replaced
-1:000000000000 0:77665d8e2254
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - WantedPages Macro
4
5 @copyright: 2001 by Jürgen Hermann <jh@web.de>
6 @license: GNU GPL, see COPYING for details.
7 """
8
9 import urllib
10 from MoinMoin import config, wikiutil
11
12 Dependencies = ["pages"]
13
14 def execute(macro, args):
15 request = macro.request
16 _ = request.getText
17
18 # prevent recursion
19 if request.mode_getpagelinks:
20 return ''
21
22 # Get allpages switch from the form
23 allpages = int(request.form.get('allpages', [0])[0]) != 0
24
25 # Control bar - filter the list of pages
26 # TODO: we should make this a widget and use on all page listing pages
27 controlbar = '''<div class="controlbar">
28 <a href="%(qpagename)s?allpages=%(allpages)d">%(label)s</a>
29 </div>''' % {
30 'qpagename': wikiutil.quoteWikinameURL(macro.formatter.page.page_name),
31 'allpages': not allpages,
32 'label': (_('Include system pages'), _('Exclude system pages'))[allpages],
33 }
34
35 # Get page dict readable by current user
36 pages = request.rootpage.getPageDict()
37
38 # build a dict of wanted pages
39 wanted = {}
40 for name, page in pages.items():
41 # Skip system pages, because missing translations are not wanted pages,
42 # unless you are a translator and clicked "Include system pages"
43 if not allpages and wikiutil.isSystemPage(request, name):
44 continue
45
46 # Add links to pages which does not exists in pages dict
47 links = page.getPageLinks(request)
48 for link in links:
49 if not pages.has_key(link):
50 if wanted.has_key(link):
51 wanted[link][name] = 1
52 else:
53 wanted[link] = {name: 1}
54
55 # Check for the extreme case when there are no wanted pages
56 if not wanted:
57 return u"%s<p>%s</p>" % (controlbar ,_("No wanted pages in this wiki."))
58
59 # Return a list of page links
60 wantednames = wanted.keys()
61 wantednames.sort()
62 result = []
63 result.append(macro.formatter.number_list(1))
64 for name in wantednames:
65 if not name: continue
66 result.append(macro.formatter.listitem(1))
67 # Add link to the wanted page
68 result.append(macro.formatter.pagelink(1, name, generated=1))
69 result.append(macro.formatter.text(name))
70 result.append(macro.formatter.pagelink(0, name))
71
72 # Add links to pages that want this page, highliting
73 # the link in those pages.
74 where = wanted[name].keys()
75 where.sort()
76 if macro.formatter.page.page_name in where:
77 where.remove(macro.formatter.page.page_name)
78 querystr='highlight=%s' % urllib.quote_plus(name.encode(config.charset))
79 wherelinks = [pages[pagename].link_to(request, querystr=querystr)
80 for pagename in where]
81 result.append(": " + ', '.join(wherelinks))
82 result.append(macro.formatter.listitem(0))
83 result.append(macro.formatter.number_list(0))
84
85 return u'%s%s' % (controlbar, u''.join(result))