X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=d7e1a5a9e0d28a466e8f40b5704df5d4ea77148f;hb=ff74de7a49cc2bfa936503a4b37fc5c8a650a5fc;hp=dba75a28afe2493b8cf42f06ac92b5614a630d85;hpb=6ea5bc45761e688cc888c7a17a6399b31d04bcc7;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index dba75a2..d7e1a5a 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -345,27 +345,34 @@ class WikiFormatter: def _hurl_repl(self, word): m = link_re.match(word) name = m.group(1) - descr = m.group(2) or name - - if img_re.match(name): - # DEPRECATED SYNTAX: use {{foo.jpg|descr}} instead - _inl_repl(self, word) + if m.group(2) is None: + descr = name + elif img_re.match(m.group(2)): + descr = '' else: - if img_re.match(descr): - descr = '' + descr = m.group(2) - return link_tag(name, descr, 'wikilink') + return link_tag(name, descr, 'wikilink') def _inl_repl(self, word): m = link_re.match(word) name = m.group(1) descr = m.group(2) or name name = relative_url(name) + argv = descr.split('|') + descr = argv.pop(0) + + if argv: + args = '?' + '&'.join(argv) + else: + args = '' + if descr: # The "extthumb" nonsense works around a limitation of the HTML block model - return '
%s
%s
' % (name, name, descr, descr) + return '
%s
%s
' \ + % (name, name + args, descr, descr) else: - return '' % (name, name) + return '' % (name, name + args) def _email_repl(self, word): return '%s' % (word, word) @@ -571,10 +578,18 @@ class Page: raise er def format_dir(self): - out = '' + out = '== ' + path = '' + for dir in self.page_name.split('/'): + path = (path + '/' + dir) if path else dir + out += '[[' + path + '|' + dir + ']]/' + out += ' ==\n' + for file in page_list(self._filename(), file_re): if img_re.match(file): - out += ' * {{' + self.page_name + '/' + file + '}}\n' + if image_maxwidth: + maxwidth_arg = '|maxwidth=' + str(image_maxwidth) + out += '{{' + self.page_name + '/' + file + '|' + file + maxwidth_arg + '}}\n' else: out += ' * [[' + self.page_name + '/' + file + ']]\n' return out @@ -690,6 +705,16 @@ class Page: else: send_title(None, msg_text='Read access denied by ACLs', msg_type='notice') + def send_image(self, mimetype, args=[]): + if 'maxwidth' in args: + import subprocess + emit_header(mimetype) + sys.stdout.flush() + subprocess.check_call(['gm', 'convert', self._filename(), + '-scale', args['maxwidth'].value + ' >', '-']) + else: + self.send_raw(mimetype) + def _write_file(self, data): tmp_filename = self._tmp_filename() open(tmp_filename, 'wb').write(data) @@ -752,8 +777,15 @@ try: else: from mimetypes import MimeTypes type, encoding = MimeTypes().guess_type(query) - type = type or 'text/plain' - Page(query).send_raw(mimetype=type) + #type = type or 'text/plain' + #Page(query).send_raw(mimetype=type) + if type: + if type.startswith('image/'): + Page(query).send_image(mimetype=type,args=form) + else: + Page(query).send_raw(mimetype=type) + else: + Page(query).format() else: print "Status: 404 Not Found" send_title(None, msg_text='Can\'t work out query: ' + query)