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