Attachment 'FreemindSitemap_action_for_moin_1.8.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - "FreemindSitemap" action
4
5 Create a freemind mind map of your wiki's structure.
6
7 @copyright: 2009 Josef Meier <jo.meier@gmx.de>
8 @license: GNU GPL, see COPYING for details.
9 """
10
11 import StringIO
12 import string
13 import time
14 import re
15 from MoinMoin import wikiutil
16 import xml.etree.ElementTree as ElementTree
17 from xml.etree.ElementTree import tostring
18
19
20 def getSortedPagelist(request):
21 #pages = request.rootpage.getPageDict(include_underlay=0)
22 pagelist = request.rootpage.getPageList(include_underlay=False)
23 pagelist.sort()
24 return pagelist
25
26
27 def pagelist2freemind(request, pagelist):
28 map = ElementTree.Element("map")
29 map.set("version", "0.7.1")
30
31 # Create the root element of our wiki xml tree
32 root = ElementTree.SubElement(map, "node")
33 root.set("TEXT", "Root")
34
35 for idx, name in enumerate(pagelist):
36 if wikiutil.isSystemPage(request, name):
37 continue
38
39 pages = string.split( name, "/")
40 currNode = root
41 for page in pages:
42 children = currNode.getchildren()
43
44 found = False
45 for child in children:
46 if child.get("TEXT") == page:
47 currNode = child
48 found = True
49 break
50
51 if not found:
52 newNode = ElementTree.SubElement(currNode, "node")
53 newNode.set("TEXT", page )
54 newNode.set("LINK", name.encode("UTF-8") )
55 currNode = newNode
56
57 # Print xml structure to string variable.
58 stringIO = StringIO.StringIO()
59 tree = ElementTree.ElementTree(map)
60 tree.write(stringIO)
61 freemindFormat = stringIO.getvalue()
62 xmlFormat = """<?xml version="1.0" encoding="utf-8"?>"""
63 return xmlFormat + freemindFormat
64
65
66 def getSiteMapFreemind(pagename, request):
67 _ = request.getText
68
69 pagelist = getSortedPagelist(request)
70 freemindFormat = pagelist2freemind(request, pagelist)
71
72 result = freemindFormat.replace("\n", "\r\n")
73 return result
74
75
76 def execute(pagename, request):
77 result = getSiteMapFreemind(pagename, request)
78
79 request.mimetype = 'text'
80 request.write(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.You are not allowed to attach a file to this page.