diff --git a/wiki/parser/Box.py b/wiki/parser/Box.py new file mode 100644 index 00000000..e269d318 --- /dev/null +++ b/wiki/parser/Box.py @@ -0,0 +1,110 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - Portail parser + + PURPOSE: + une boite jolie + + CALLING SEQUENCE: + {{{ + #!Box titre + blablabla + + tables, images.... + }}} + +""" +from MoinMoin.parser import wiki +import os,string,re,StringIO +from MoinMoin.action import AttachFile + +##################################################################### +# Fonctions # +##################################################################### +# to_wikiname : transfome la chaine text avec le parser wiki +# classique et le formateur formatter +# (je sais pas a quoi sert request, mais faut pas +# l'enlever !) +####### + +def to_wikiname(request,formatter,text): + ##taken from MiniPage + out=StringIO.StringIO() + request.redirect(out) + wikiizer = wiki.Parser(text,request) + wikiizer.format(formatter) + result=out.getvalue() + request.redirect() + del out + + return result.strip() + +##################################################################### +# BoxFormatter : creer le code html +####### +class BoxFormatter: + + def __init__(self, request, formatter): + self.formatter = formatter + self.request = request + self.counter = 0 + + def make(self, title, body_html, color=None): + if color==None: + css_color_class=u"" + else: + css_color_class = u" %s_box" % color + html = [ + self.formatter.rawHTML(u'
%(this_exif_date)s
+')
+
+
+ if kw['album'] == '1' :
+ if kw['front_image'] == '' :
+ front_image = full[0]
+ else:
+ front_image = kw['front_image']
+ ii = 0
+ for tst in full :
+ if tst == front_image :
+ break
+ ii += 1
+
+
+ for attfile in full :
+ if kw['album'] == '1' :
+ if tst == front_image :
+ i = ii
+
+
+ this_description=description[i]
+ this_exif_date=exif_date[i]
+ this_webnail=web[i]
+ this_imgtype=imgtype[i]
+ this_thumbfile=thumb[i]
+
+
+ thumbf=os.path.join(attachment_path,this_thumbfile)
+ webf=os.path.join(attachment_path,this_webnail)
+
+
+ if kw['renew'] == '1':
+ if os.path.exists(thumbf):
+ os.unlink(thumbf)
+ if os.path.exists(webf):
+ os.unlink(webf)
+
+ if not os.path.exists(webf) or not os.path.exists(thumbf):
+ infile=os.path.join(attachment_path,attfile)
+ im = Image.open(infile)
+ if not os.path.exists(webf):
+ im.thumbnail(((int(kw['webnail_width'])),((int(kw['webnail_width'])))), Image.ANTIALIAS)
+ im.save(webf, this_imgtype)
+ if not os.path.exists(thumbf):
+ im.thumbnail(((int(kw['thumbnail_width'])),((int(kw['thumbnail_width'])))),
+ Image.ANTIALIAS)
+ im.save(thumbf, this_imgtype)
+
+
+ if kw['mode'] == '1':
+ text=mode1_html(current_pagename,
+ kw['border_thick'],
+ kw['width'],
+ kw['thumbnail_width'],
+ kw['text_width'],
+ attfile + "," + ','.join(full),
+ attfile,
+ to_htmltext(this_description + "!,!" + '!,!'.join(description)),
+ to_wikiname(self.request,formatter,this_description),
+ to_htmltext(this_exif_date + "," + ','.join(exif_date)),
+ this_exif_date,
+ this_webnail + "," + ','.join(web),
+ this_webnail,
+ AttachFile.getAttachUrl(current_pagename, this_thumbfile, self.request),
+ kw['show_tools'],
+ kw['show_date'],
+ kw['show_text'],
+ self.request
+ )
+ self.request.write(''.join(text))
+
+ if kw['mode'] == '2':
+ text=mode2_html(current_pagename,
+ kw['border_thick'],
+ kw['width'],
+ kw['thumbnail_width'],
+ kw['text_width'],
+ attfile + "," + ','.join(full),
+ attfile,
+ to_htmltext(this_description + "!,!" + '!,!'.join(description)),
+ to_wikiname(self.request,formatter,this_description),
+ to_htmltext(this_exif_date + "," + ','.join(exif_date)),
+ this_exif_date,
+ this_webnail + "," + ','.join(web),
+ this_webnail,
+ AttachFile.getAttachUrl(current_pagename, this_thumbfile, self.request),
+ kw['show_tools'],
+ kw['show_date'],
+ kw['show_text'],
+ self.request
+ )
+
+ if cols > 1 : self.request.write(' | ')
+ if z < n :
+ self.request.write('') + else: + self.request.write(' | ') + self.request.write('
') + + i += 1 + z += 1 + if z > cols : + z = 1 + + if kw['album'] == '1' : + self.request.write("%(n)s images (%(album_name)s)" % {"n": str(n), "album_name":kw['album_name']}) + break + if kw['album'] == '0' : + if i < n : + self.request.write(' | ') + self.request.write('
so footer isn't too big + """ + _ = self.request.getText + + if self.shouldShowPageinfo(page): + info = page.lastEditInfo() + if info: + if info['editor']: + info = _("last edited %(time)s by %(editor)s") % info + else: + info = _("last modified %(time)s") % info + return info + return '' + + def rtl_stylesheet(self, d): + """ monobook uses a separate css page for rtl alterations. + Add the rtl stylesheet if the user needs it + """ + link = ('') + html = [] + if i18n.getDirection(self.request.lang) == 'rtl': + prefix = self.cfg.url_prefix + href = '%s/%s/css/%s.css' % (prefix, self.name, 'rtl') + html.append(link % (self.stylesheetsCharset, 'all', href)) + return '\n'.join(html) + + def html_head(self, d): + """ Tweak the sending of the head, to include right-to-left + alterations if necessary + """ + html = [ + u'
so footer isn't too big + """ + _ = self.request.getText + + if self.shouldShowPageinfo(page): + info = page.lastEditInfo() + if info: + if info['editor']: + info = _("last edited %(time)s by %(editor)s") % info + else: + info = _("last modified %(time)s") % info + return info + return '' + + def rtl_stylesheet(self, d): + """ monobook uses a separate css page for rtl alterations. + Add the rtl stylesheet if the user needs it + """ + link = ('') + html = [] + if i18n.getDirection(self.request.lang) == 'rtl': + prefix = self.cfg.url_prefix + href = '%s/%s/css/%s.css' % (prefix, self.name, 'rtl') + html.append(link % (self.stylesheetsCharset, 'all', href)) + return '\n'.join(html) + + def html_head(self, d): + """ Tweak the sending of the head, to include right-to-left + alterations if necessary + """ + html = [ + u'
so footer isn't too big + """ + _ = self.request.getText + + if self.shouldShowPageinfo(page): + info = page.lastEditInfo() + if info: + if info['editor']: + info = _("last edited %(time)s by %(editor)s") % info + else: + info = _("last modified %(time)s") % info + return info + return '' + + def rtl_stylesheet(self, d): + """ monobook uses a separate css page for rtl alterations. + Add the rtl stylesheet if the user needs it + """ + link = ('') + html = [] + if i18n.getDirection(self.request.lang) == 'rtl': + prefix = self.cfg.url_prefix + href = '%s/%s/css/%s.css' % (prefix, self.name, 'rtl') + html.append(link % (self.stylesheetsCharset, 'all', href)) + return '\n'.join(html) + + def html_head(self, d): + """ Tweak the sending of the head, to include right-to-left + alterations if necessary + """ + html = [ + u'
so footer isn't too big + """ + _ = self.request.getText + + if self.shouldShowPageinfo(page): + info = page.lastEditInfo() + if info: + if info['editor']: + info = _("last edited %(time)s by %(editor)s") % info + else: + info = _("last modified %(time)s") % info + return info + return '' + + def rtl_stylesheet(self, d): + """ monobook uses a separate css page for rtl alterations. + Add the rtl stylesheet if the user needs it + """ + link = ('') + html = [] + if i18n.getDirection(self.request.lang) == 'rtl': + prefix = self.cfg.url_prefix + href = '%s/%s/css/%s.css' % (prefix, self.name, 'rtl') + html.append(link % (self.stylesheetsCharset, 'all', href)) + return '\n'.join(html) + + def html_head(self, d): + """ Tweak the sending of the head, to include right-to-left + alterations if necessary + """ + html = [ + u'
%s
' % _("Wiki"), + self.navibar(d), + u'%s
' % _("Page"), + self.editbar(d), + u'%s
' % _("User"), + self.username(d), + u'