Description

This macro gives a "signature" of all the pages in the Wiki. It gives you a bird's eye view of a page by only showing symbols for key structural elements, such as periods, paragraph separations, and list items. See PageSignature for an example.

code

'''
        MoinMoin - PageSignature Macro - version 1.0

        Copyright (c) 2002 by Brian Dorsey, Asim Jalis
        All rights reserved, see COPYING for details.

        Shows signature for all wiki pages. This is still a work in progress.
        We're still playing with different ways of representing the wiki structure.

        Signature idea from Ward Cunningham
        See http://c2.com/doc/SignatureSurvey for more info


'''

# Imports
import re, string
from MoinMoin import config, wikiutil
from MoinMoin.Page import Page

def execute(macro, args):
        all_pages = wikiutil.getPageList(config.text_dir)
        all_pages.sort()
        result = ""

        result = result + macro.formatter.bullet_list(1)
        for page in all_pages:
                body = Page(page).get_raw_body()
                lines = string.count(body, "\n")

                result = result + macro.formatter.listitem(1)
                result = result + macro.formatter.pagelink(page)
                result = result + macro.formatter.text(' (' + str(lines) + ', ' + signature(body) + ')')
                result = result + macro.formatter.listitem(0)

        result = result + macro.formatter.bullet_list(0)

        return result

def signature(body):
        sig = body
        sig = re.sub('[^\.\n\*]', '', sig)
        sig = re.sub('\n\n+', ' ', sig)
        sig = re.sub('\n', '', sig)
        sig = re.sub('\.', 's', sig)
        return sig

comments on the code

Suggestion: You guys might want to filter out the standard MoinMoin files, just to make this run a little faster. See OutsideLinksCode for a rough example of doing this.

-- SteveHowell

Yeah, it probably takes too long to list the pages now... but I like including the standard pages as well. I want to include their texture. ;) Probably time to profile it and see where it's slow... Or add in a more versitle parser and get that working first. ;) -- BrianDorsey

Report: This works ok on my MoinMoin setup at Boeing. -- JeffSandys

Cool! I'm working on a more flexible version now... but I need to learn more about regexes before it'll work right. -- BrianDorsey

PageSignatureCode (last edited 2008-03-04 08:33:19 by localhost)