Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.macro.WantedPages Namespace Reference

Functions

def macro_WantedPages

Variables

list Dependencies = ["pages"]

Function Documentation

Definition at line 13 of file WantedPages.py.

00013 
00014 def macro_WantedPages(macro):
00015     request = macro.request
00016     _ = request.getText
00017 
00018     # prevent recursion
00019     if request.mode_getpagelinks:
00020         return ''
00021     if request.isSpiderAgent: # reduce bot cpu usage
00022         return ''
00023 
00024     # Get allpages switch from the form
00025     allpages = int(request.values.get('allpages', 0)) != 0
00026 
00027     # Control bar - filter the list of pages
00028     # TODO: we should make this a widget and use on all page listing pages
00029     label = (_('Include system pages'), _('Exclude system pages'))[allpages]
00030     page = macro.formatter.page
00031     controlbar = macro.formatter.div(1, css_class="controlbar") + \
00032                  page.link_to(request, label, querystr={'allpages': '%s' % (allpages and '0' or '1')}) + \
00033                  macro.formatter.div(0)
00034 
00035     # Get page dict readable by current user
00036     pages = request.rootpage.getPageDict()
00037 
00038     # build a dict of wanted pages
00039     wanted = {}
00040     deprecated_links = []
00041     for name, page in pages.items():
00042         # Skip system pages, because missing translations are not wanted pages,
00043         # unless you are a translator and clicked "Include system pages"
00044         if not allpages and wikiutil.isSystemPage(request, name):
00045             continue
00046 
00047         # Add links to pages which do not exist in pages dict
00048         links = page.getPageLinks(request)
00049         is_deprecated = page.parse_processing_instructions(
00050                 ).get('deprecated', False)
00051 
00052         for link in links:
00053             if not link in pages and request.user.may.read(link):
00054                 if is_deprecated:
00055                     deprecated_links.append(link)
00056                 if link in wanted:
00057                     wanted[link][name] = 1
00058                 else:
00059                     wanted[link] = {name: 1}
00060 
00061     for link in deprecated_links:
00062         if len(wanted[link]) == 1:
00063             del wanted[link]
00064 
00065     # Check for the extreme case when there are no wanted pages
00066     if not wanted:
00067         return u"%s<p>%s</p>" % (controlbar, _("No wanted pages in this wiki."))
00068 
00069     # Return a list of page links
00070     wantednames = wanted.keys()
00071     wantednames.sort()
00072     result = []
00073     result.append(macro.formatter.number_list(1))
00074     for name in wantednames:
00075         if not name:
00076             continue
00077         result.append(macro.formatter.listitem(1))
00078         # Add link to the wanted page
00079         result.append(macro.formatter.pagelink(1, name, generated=1))
00080         result.append(macro.formatter.text(name))
00081         result.append(macro.formatter.pagelink(0, name))
00082 
00083         # Add links to pages that want this page, highliting
00084         # the link in those pages.
00085         where = wanted[name].keys()
00086         where.sort()
00087         if macro.formatter.page.page_name in where:
00088             where.remove(macro.formatter.page.page_name)
00089         wherelinks = [pages[pagename].link_to(request, querystr={'highlight': name}, rel='nofollow')
00090                       for pagename in where]
00091         result.append(": " + ', '.join(wherelinks))
00092         result.append(macro.formatter.listitem(0))
00093     result.append(macro.formatter.number_list(0))
00094 
00095     return u'%s%s' % (controlbar, u''.join(result))
00096 

Variable Documentation

Definition at line 11 of file WantedPages.py.