view MoinMoin/macro/ @ 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 <>
date Thu, 22 Sep 2005 15:09:50 +0000
children 2202f548cbb0
line wrap: on
line source

# -*- coding: iso-8859-1 -*-
    MoinMoin - WantedPages Macro

    @copyright: 2001 by Jürgen Hermann <>
    @license: GNU GPL, see COPYING for details.

import urllib
from MoinMoin import config, wikiutil

Dependencies = ["pages"]

def execute(macro, args):
    request = macro.request
    _ = request.getText

    # prevent recursion
    if request.mode_getpagelinks: 
        return ''   

    # Get allpages switch from the form
    allpages = int(request.form.get('allpages', [0])[0]) != 0
    # Control bar - filter the list of pages
    # TODO: we should make this a widget and use on all page listing pages
    controlbar = '''<div class="controlbar">
<a href="%(qpagename)s?allpages=%(allpages)d">%(label)s</a>
</div>''' % {
        'qpagename': wikiutil.quoteWikinameURL(,
        'allpages': not allpages,
        'label': (_('Include system pages'), _('Exclude system pages'))[allpages],

    # Get page dict readable by current user
    pages = request.rootpage.getPageDict()

    # build a dict of wanted pages
    wanted = {}       
    for name, page in pages.items():
        # Skip system pages, because missing translations are not wanted pages,
        # unless you are a translator and clicked "Include system pages"
        if not allpages and wikiutil.isSystemPage(request, name):
        # Add links to pages which does not exists in pages dict
        links = page.getPageLinks(request)
        for link in links:
            if not pages.has_key(link):
                if wanted.has_key(link):
                    wanted[link][name] = 1
                    wanted[link] = {name: 1}

    # Check for the extreme case when there are no wanted pages
    if not wanted:
        return u"%s<p>%s</p>" % (controlbar ,_("No wanted pages in this wiki."))

    # Return a list of page links
    wantednames = wanted.keys()
    result = []
    for name in wantednames:
        if not name: continue
        # Add link to the wanted page
        result.append(macro.formatter.pagelink(1, name, generated=1))
        result.append(macro.formatter.pagelink(0, name))

        # Add links to pages that want this page, highliting
        # the link in those pages.
        where = wanted[name].keys()
        if in where:
        querystr='highlight=%s' % urllib.quote_plus(name.encode(config.charset))
        wherelinks = [pages[pagename].link_to(request, querystr=querystr)
                      for pagename in where]
        result.append(": " + ', '.join(wherelinks))

    return u'%s%s' % (controlbar, u''.join(result))