Attachment 'SiteIndex.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 SiteIndex Macro 2014.4.29
4
5 List wiki pages in the site (regular ones, system ones or both).
6 It works like TitleIndex, but without letter indexing.
7
8 @copyright: 2009 Renato Silva
9 @license: GNU GPLv2
10 """
11
12 Dependencies = ["namespace"]
13 from MoinMoin import wikiutil
14 from MoinMoin.Page import Page
15 import re
16
17 def add_spaces(wiki_name):
18 wiki_name = re.compile('([^A-Z\s])([A-Z])').sub(ur'\1 \2', wiki_name)
19 wiki_name = re.compile('(\d)(\D)').sub(ur'\1 \2', wiki_name)
20 wiki_name = wiki_name.replace('_', ' ')
21 return wiki_name.replace('/', ' /')
22
23 def macro_SiteIndex(macro, subpages=True, count=False, system_pages=False, regular_pages=True, spaces=True, max_name=0):
24 hide_subpages = not subpages
25 request = macro.request
26 fmt = macro.formatter
27 _ = macro._
28 output = []
29
30 def get_root_page_name(subpage_name): return subpage_name.split('/')[0]
31 def is_system_page(name): return wikiutil.isSystemPage(request, name)
32 def is_regular_page(name): return not is_system_page(name)
33 def is_root_page(name): return name.find('/') < 0
34
35 system_page_filter = is_system_page if system_pages else None
36 regular_page_filter = is_regular_page if regular_pages else None
37 allowed = None if regular_pages and system_pages else regular_page_filter or system_page_filter
38
39 page_names = request.rootpage.getPageList(filter=allowed)
40 if allowed == None: allowed = (lambda name: True)
41 total_pages = len(page_names)
42 if total_pages == 0:
43 return _('No page found...')
44
45 page_names.sort()
46 missing_pages = []
47 subpage_count = 0
48 subpage_counts = {}
49 last_root_page = page_names[0]
50 for page_name in page_names:
51 subpage_counts[page_name] = -1
52
53 for index, page_name in enumerate(page_names):
54 if hide_subpages and count:
55 found_root_page = is_root_page(page_name)
56 found_subpage = not found_root_page
57 found_last_page = index == (total_pages - 1)
58
59 if found_subpage:
60 subpage_count += 1
61 root_page_name = get_root_page_name(page_name)
62 missing_page = not Page(request, root_page_name).exists()
63
64 if missing_page and root_page_name not in missing_pages:
65 missing_pages.append(root_page_name)
66 last_root_page = root_page_name
67 elif not allowed(root_page_name):
68 last_root_page = root_page_name
69
70 if (found_root_page or found_last_page) and (subpage_count > 0 or is_root_page(last_root_page)):
71 subpage_counts[last_root_page] = subpage_count
72 subpage_count = 0
73 if found_root_page:
74 last_root_page = page_name
75
76 page_names += missing_pages
77 page_names.sort()
78 output.append(fmt.bullet_list(1))
79
80 for page_name in page_names:
81 page = Page(request, page_name)
82 root_page_found = is_root_page(page_name)
83
84 if not hide_subpages or root_page_found:
85 output.append(fmt.listitem(1))
86 prepared_page_name = add_spaces(page_name) if spaces else page_name
87 if max_name > 0:
88 link_title = re.compile('(.{%d}).+' % max_name).sub(ur'\1...', prepared_page_name)
89 else:
90 link_title = prepared_page_name
91 output.append(page.link_to(request, text=link_title, attachment_indicator=0))
92 subpage_count = subpage_counts[page_name]
93
94 if root_page_found and count and subpage_count > 0:
95 _text = _('%d subpages') % subpage_count if subpage_count > 1 else _('one subpage')
96 link = page.link_to(request, text=(' (%s)' % _text), querystr={'action': 'LocalSiteMap'}, css_class='site_index_show_subpages')
97 output.append(link)
98
99 output.append(fmt.listitem(0))
100
101 output.append(fmt.bullet_list(0))
102 return ''.join(output)
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.