paul@0 | 1 | # -*- coding: iso-8859-1 -*- |
paul@0 | 2 | """ |
paul@0 | 3 | MoinMoin - ep2008 (EuroPython 2008) theme |
paul@0 | 4 | |
paul@50 | 5 | @copyright: 2003-2008 by Nir Soffer, Thomas Waldmann, Paul Boddie |
paul@27 | 6 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@0 | 7 | """ |
paul@0 | 8 | |
paul@0 | 9 | from MoinMoin.theme import ThemeBase |
paul@12 | 10 | from MoinMoin.action import AttachFile |
paul@12 | 11 | import random |
paul@0 | 12 | |
paul@0 | 13 | class Theme(ThemeBase): |
paul@0 | 14 | |
paul@0 | 15 | name = "ep2008" |
paul@0 | 16 | |
paul@57 | 17 | def rsslink(self, d): |
paul@50 | 18 | """ Create rss link in head, used by FireFox |
paul@50 | 19 | |
paul@50 | 20 | RSS link for FireFox. This shows an rss link in the bottom of |
paul@50 | 21 | the page and let you subscribe to the wiki rss feed. |
paul@50 | 22 | |
paul@50 | 23 | @rtype: unicode |
paul@50 | 24 | @return: html head |
paul@50 | 25 | """ |
paul@50 | 26 | |
paul@57 | 27 | extra_rss = self.cfg.extra_rss |
paul@57 | 28 | return ThemeBase.rsslink(self, d) + u'\n' + extra_rss |
paul@50 | 29 | |
paul@0 | 30 | def header(self, d, **kw): |
paul@0 | 31 | """ Assemble wiki header |
paul@0 | 32 | |
paul@0 | 33 | @param d: parameter dictionary |
paul@0 | 34 | @rtype: unicode |
paul@0 | 35 | @return: page header html |
paul@0 | 36 | """ |
paul@0 | 37 | html = [ |
paul@0 | 38 | # Pre header custom html |
paul@0 | 39 | self.emit_custom_html(self.cfg.page_header1), |
paul@0 | 40 | |
paul@0 | 41 | # Header |
paul@0 | 42 | u'<div id="header">', |
paul@0 | 43 | self.logo(), |
paul@0 | 44 | |
paul@0 | 45 | # Banner |
paul@12 | 46 | self.banner(d), |
paul@0 | 47 | |
paul@0 | 48 | self.searchform(d), |
paul@0 | 49 | self.navibar(d), |
paul@0 | 50 | self.msg(d), |
paul@0 | 51 | |
paul@0 | 52 | # NOTE: Hack everything into the header |
paul@0 | 53 | u'<div id="end-of-header">', |
paul@0 | 54 | u'</div>', |
paul@0 | 55 | u'</div>', |
paul@0 | 56 | |
paul@0 | 57 | # Post header custom html (not recommended) |
paul@0 | 58 | self.emit_custom_html(self.cfg.page_header2), |
paul@0 | 59 | |
paul@0 | 60 | # Start of page |
paul@0 | 61 | u'<div class="page-%s">' % d['page_name'], |
paul@0 | 62 | self.startPage(), |
paul@0 | 63 | ] |
paul@0 | 64 | return u'\n'.join(html) |
paul@0 | 65 | |
paul@0 | 66 | def editorheader(self, d, **kw): |
paul@0 | 67 | """ Assemble wiki header for editor |
paul@0 | 68 | |
paul@0 | 69 | @param d: parameter dictionary |
paul@0 | 70 | @rtype: unicode |
paul@0 | 71 | @return: page header html |
paul@0 | 72 | """ |
paul@0 | 73 | html = [ |
paul@0 | 74 | # Pre header custom html |
paul@0 | 75 | self.emit_custom_html(self.cfg.page_header1), |
paul@0 | 76 | |
paul@0 | 77 | # Header |
paul@0 | 78 | u'<div id="header">', |
paul@0 | 79 | self.title(d), |
paul@0 | 80 | self.msg(d), |
paul@0 | 81 | u'</div>', |
paul@0 | 82 | |
paul@0 | 83 | # Post header custom html (not recommended) |
paul@0 | 84 | self.emit_custom_html(self.cfg.page_header2), |
paul@0 | 85 | |
paul@0 | 86 | # Start of page |
paul@0 | 87 | u'<div class="page-%s">' % d['page_name'], |
paul@0 | 88 | self.startPage(), |
paul@0 | 89 | ] |
paul@0 | 90 | return u'\n'.join(html) |
paul@0 | 91 | |
paul@0 | 92 | def footer(self, d, **keywords): |
paul@0 | 93 | """ Assemble wiki footer |
paul@0 | 94 | |
paul@0 | 95 | @param d: parameter dictionary |
paul@0 | 96 | @keyword ...:... |
paul@0 | 97 | @rtype: unicode |
paul@0 | 98 | @return: page footer html |
paul@0 | 99 | """ |
paul@28 | 100 | request = self.request |
paul@28 | 101 | formatter = request.formatter |
paul@0 | 102 | page = d['page'] |
paul@11 | 103 | |
paul@11 | 104 | if self.cfg.special_username: |
paul@11 | 105 | username = self.specialUsername(d) |
paul@11 | 106 | else: |
paul@11 | 107 | username = self.username(d) |
paul@11 | 108 | |
paul@0 | 109 | html = [ |
paul@0 | 110 | # End of page |
paul@46 | 111 | #self.pageinfo(page), |
paul@0 | 112 | self.endPage(), |
paul@0 | 113 | u'</div>', |
paul@0 | 114 | |
paul@0 | 115 | # Pre footer custom html (not recommended!) |
paul@0 | 116 | self.emit_custom_html(self.cfg.page_footer1), |
paul@0 | 117 | |
paul@0 | 118 | # Footer |
paul@0 | 119 | u'<div id="footer">', |
paul@28 | 120 | u'<div id="contact">', |
paul@28 | 121 | formatter.pagelink(1, self.cfg.contact_page), |
paul@28 | 122 | self.cfg.contact_label, |
paul@28 | 123 | formatter.pagelink(0), |
paul@28 | 124 | u'</div>', |
paul@10 | 125 | u'<div id="contribute">', |
paul@10 | 126 | #self.cfg.contribute_string, |
paul@10 | 127 | #u'<div class="contribute-hidden">', |
paul@10 | 128 | #self.username(d), |
paul@10 | 129 | #u'<div id="locationline">', |
paul@10 | 130 | #self.interwiki(d), |
paul@10 | 131 | #self.title(d), |
paul@10 | 132 | #u'</div>', |
paul@11 | 133 | username, |
paul@10 | 134 | self.editbar(d), |
paul@0 | 135 | self.trail(d), |
paul@10 | 136 | #u'</div>', |
paul@0 | 137 | u'</div>', |
paul@0 | 138 | self.credits(d), |
paul@0 | 139 | self.showversion(d, **keywords), |
paul@0 | 140 | u'</div>', |
paul@0 | 141 | |
paul@0 | 142 | # Post footer custom html |
paul@0 | 143 | self.emit_custom_html(self.cfg.page_footer2), |
paul@0 | 144 | ] |
paul@0 | 145 | return u'\n'.join(html) |
paul@0 | 146 | |
paul@10 | 147 | def editbarItems(self, page): |
paul@10 | 148 | """ Return list of items to show on the editbar |
paul@10 | 149 | |
paul@10 | 150 | This is separate method to make it easy to customize the |
paul@10 | 151 | editbar in sub classes. |
paul@10 | 152 | """ |
paul@10 | 153 | |
paul@10 | 154 | request = self.request |
paul@10 | 155 | |
paul@10 | 156 | items = [self.editorLink(page), |
paul@10 | 157 | self.infoLink(page), |
paul@10 | 158 | self.subscribeLink(page), |
paul@10 | 159 | self.quicklinkLink(page),] |
paul@10 | 160 | |
paul@10 | 161 | if page.isWritable() and request.user.valid and request.user.may.write(page.page_name): |
paul@10 | 162 | items.append(self.attachmentsLink(page)) |
paul@10 | 163 | |
paul@10 | 164 | if request.user.valid: |
paul@10 | 165 | items.append(self.actionsMenu(page)) |
paul@10 | 166 | |
paul@10 | 167 | return items |
paul@10 | 168 | |
paul@10 | 169 | def specialUsername(self, d): |
paul@10 | 170 | request = self.request |
paul@10 | 171 | _ = request.getText |
paul@10 | 172 | |
paul@10 | 173 | if request.user.valid and request.user.name: |
paul@10 | 174 | return u'<div class="username">%s</div>' % request.formatter.text(request.user.name) |
paul@10 | 175 | else: |
paul@10 | 176 | # NOTE: Using the contribute string! |
paul@10 | 177 | return u'<div class="no-username">%s</div>' % \ |
paul@10 | 178 | d['page'].link_to(request, text=self.cfg.contribute_string, |
paul@10 | 179 | querystr={'action': 'login'}, id="login") |
paul@10 | 180 | |
paul@12 | 181 | def banner(self, d): |
paul@12 | 182 | request = self.request |
paul@12 | 183 | formatter = request.formatter |
paul@12 | 184 | |
paul@12 | 185 | # Either get banners per page or acquire them from a central source. |
paul@12 | 186 | |
paul@12 | 187 | if self.cfg.banner_per_page: |
paul@12 | 188 | pagename = d["page"].page_name |
paul@12 | 189 | else: |
paul@12 | 190 | pagename = self.cfg.banner_attachment_page |
paul@12 | 191 | |
paul@12 | 192 | # Only get attachments with a certain prefix. |
paul@12 | 193 | |
paul@12 | 194 | attachments = [] |
paul@12 | 195 | for filename in AttachFile._get_files(request, pagename): |
paul@12 | 196 | if filename.startswith(self.cfg.banner_prefix): |
paul@12 | 197 | attachments.append(filename) |
paul@12 | 198 | |
paul@12 | 199 | # Display the default banner if no attachments are found. |
paul@12 | 200 | |
paul@14 | 201 | target = self.cfg.banner_link_page |
paul@14 | 202 | |
paul@12 | 203 | if not attachments: |
paul@14 | 204 | return "%s%s%s" % (formatter.pagelink(1, target), |
paul@14 | 205 | self.cfg.banner_string, |
paul@14 | 206 | formatter.pagelink(0)) |
paul@12 | 207 | |
paul@12 | 208 | # Choose an attachment at random and return the HTML to show it. |
paul@12 | 209 | |
paul@12 | 210 | attachment = random.choice(attachments) |
paul@12 | 211 | |
paul@12 | 212 | kw = {} |
paul@12 | 213 | kw['src'] = AttachFile.getAttachUrl(pagename, attachment, request) |
paul@12 | 214 | kw['alt'] = self.cfg.banner_alt_text |
paul@12 | 215 | kw['id'] = u'banner' |
paul@12 | 216 | |
paul@12 | 217 | return "%s%s%s" % (formatter.pagelink(1, target), |
paul@12 | 218 | formatter.image(**kw), |
paul@12 | 219 | formatter.pagelink(0)) |
paul@12 | 220 | |
paul@0 | 221 | def execute(request): |
paul@0 | 222 | """ |
paul@0 | 223 | Generate and return a theme object |
paul@0 | 224 | |
paul@0 | 225 | @param request: the request object |
paul@0 | 226 | @rtype: MoinTheme |
paul@0 | 227 | @return: Theme object |
paul@0 | 228 | """ |
paul@0 | 229 | return Theme(request) |
paul@0 | 230 | |
paul@0 | 231 | # vim: tabstop=4 expandtab shiftwidth=4 |