Attachment 'modern.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - modern theme + approve support
4
5 @copyright: 2003-2005 by Nir Soffer, Thomas Waldmann, Robert Penz
6 @license: GNU GPL, see COPYING for details.
7 """
8
9 import os
10
11 from MoinMoin.theme import ThemeBase
12 from MoinMoin import i18n, wikiutil, config, version
13
14 class Theme(ThemeBase):
15
16 name = "modern"
17 _showApproveLink = None
18
19 def approved(self, page):
20 """ this methods writes approved by xxx into the output and set a flag
21 which controls the output of the """
22 approvedFile = os.path.join(page.getPagePath(), "approved")
23 if os.path.isfile(approvedFile):
24 approvedRevision = {}
25 for line in open(approvedFile).readlines():
26 tmp = line.split("\t")
27 approvedRevision[tmp[0]] = tmp[1]
28 currentRevision = "%08d" % page.get_real_rev()
29 if currentRevision in approvedRevision:
30 self._showApproveLink = False
31 return "approved by " + approvedRevision[currentRevision]
32 if page.get_real_rev() == page.getRevList()[0]:
33 self._showApproveLink = True
34 else:
35 self._showApproveLink = False
36 return ""
37
38 def approveLink(self, page):
39 """ Return approve link to valid users
40
41 @rtype: unicode
42 @return: approve link
43 """
44 _ = self.request.getText
45
46 #if user has perms
47 title = _("Approve")
48 quotedname = wikiutil.quoteWikinameURL(page.page_name)
49 link = wikiutil.link_tag(self.request, quotedname +
50 '?action=ApprovePage', title)
51 return link
52
53 def editbar(self, d):
54 """ This is a bad hack to add our approveLink to the editbar
55 as otherwise the whole editbar methode would be needed to be overwritten """
56 output = ThemeBase.editbar(self, d)
57 if self._showApproveLink:
58 if "approve" not in self.request.cfg.actions_excluded and self.request.user.may.approve(d["page_name"]):
59 output = output[:-6] + self.approveLink(d['page']) + output[-6:]
60 return output
61
62 def header(self, d, **kw):
63 """ Assemble wiki header
64
65 @param d: parameter dictionary
66 @rtype: unicode
67 @return: page header html
68 """
69 revision = self.request.page.rev or self.request.page.get_real_rev()
70 html = [
71 # Pre header custom html
72 self.emit_custom_html(self.cfg.page_header1),
73
74 # Header
75 u'<div id="header">',
76 self.logo(),
77 self.searchform(d),
78 self.username(d),
79 self.trail(d),
80 self.navibar(d),
81 self.approved(d['page']),
82 #u'<hr id="pageline">',
83 u'<div id="pageline"><hr style="display:none;"></div>',
84 self.msg(d),
85 self.editbar(d),
86 u'</div>',
87
88 # Post header custom html (not recommended)
89 self.emit_custom_html(self.cfg.page_header2),
90
91 # Start of page
92 self.startPage(),
93 self.title(d),
94 ]
95 return u'\n'.join(html)
96
97 def editorheader(self, d, **kw):
98 """ Assemble wiki header for editor
99
100 @param d: parameter dictionary
101 @rtype: unicode
102 @return: page header html
103 """
104 html = [
105 # Pre header custom html
106 self.emit_custom_html(self.cfg.page_header1),
107
108 # Header
109 u'<div id="header">',
110 self.msg(d),
111 u'</div>',
112
113 # Post header custom html (not recommended)
114 self.emit_custom_html(self.cfg.page_header2),
115
116 # Start of page
117 self.startPage(),
118 ]
119 return u'\n'.join(html)
120
121 def footer(self, d, **keywords):
122 """ Assemble wiki footer
123
124 @param d: parameter dictionary
125 @keyword ...:...
126 @rtype: unicode
127 @return: page footer html
128 """
129 page = d['page']
130 html = [
131 # End of page
132 self.pageinfo(page),
133 self.endPage(),
134
135 # Pre footer custom html (not recommended!)
136 self.emit_custom_html(self.cfg.page_footer1),
137
138 # Footer
139 u'<div id="footer">',
140 self.editbar(d),
141 self.credits(d),
142 self.showversion(d, **keywords),
143 u'</div>',
144
145 # Post footer custom html
146 self.emit_custom_html(self.cfg.page_footer2),
147 ]
148 return u'\n'.join(html)
149
150
151 def execute(request):
152 """
153 Generate and return a theme object
154
155 @param request: the request object
156 @rtype: MoinTheme
157 @return: Theme object
158 """
159 return Theme(request)
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.