X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=5a401abde033bc06cd504fdb61c4e00fc41676e2;hb=62db44f1f908f7f3f0d9942f841b89115b8d6c67;hp=afaebefc6a4321560a861d04f174c7d8661a304b;hpb=3cebb905becc61868f9431c2cf8939d1f1cd198e;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index afaebef..5a401ab 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -18,7 +18,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = '$Id$'[4:12] +__version__ = '4.0-' + '$Id$'[4:11] from time import clock start_time = clock() @@ -26,13 +26,14 @@ title_done = False import cgi, sys, os, re, errno, stat -# FIXME: we accept stuff like foo/../bar and we shouldn't -file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)") +image_ext = 'png|gif|jpg|jpeg|bmp|ico' video_ext = "ogg|ogv|oga" # Not supported by Firefox 3.5: mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt -img_re = re.compile(r".*\.(png|gif|jpg|jpeg|bmp|ico|" + video_ext + ")", re.IGNORECASE) +image_re = re.compile(r".*\.(" + image_ext + "|" + video_ext + ")", re.IGNORECASE) video_re = re.compile(r".*\.(" + video_ext + ")", re.IGNORECASE) -url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S") -ext_re = re.compile(r"\.([^\./]+)$") +# FIXME: we accept stuff like foo/../bar and we shouldn't +file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)") +url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S") +ext_re = re.compile(r"\.([^\./]+)$") # CGI stuff --------------------------------------------------------- def script_name(): @@ -198,7 +199,7 @@ def send_httperror(status="403 Not Found", query=""): def link_tag(dest, text=None, privileged=False, **kvargs): if text is None: text = humanlink(dest) - elif img_re.match(text): + elif image_re.match(text): text = '' + text + '' link_class = kvargs.get('class', kvargs.get('cssclass', None)) @@ -223,7 +224,7 @@ def link_inline(name, descr=None, kvargs={}): url = relative_url(name) if video_re.match(name): return '' % url - elif img_re.match(name): + elif image_re.match(name): return '%s' % (url, url + url_args(kvargs), descr) elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page return Page(name).send_naked() @@ -336,13 +337,14 @@ def send_footer(mod_string=None): cgi.print_arguments() cgi.print_form(form) cgi.print_environ() + #FIXME link_inline("sys/footer") print(''' ') @@ -366,6 +368,7 @@ class WikiFormatter: "**": ["b", False], "##": ["tt", False], "__": ["u", False], + "--": ["del", False], "^^": ["sup", False], ",,": ["sub", False], "''": ["em", False], # LEGACY @@ -378,6 +381,9 @@ class WikiFormatter: style[1] = not style[1] return ['' + def _glyph_repl(self, word): + return '—' + def _tit_repl(self, word): if self.h_level: result = '

\n' % self.h_level @@ -533,29 +539,30 @@ class WikiFormatter: print('

') scan_re = re.compile(r"""(?: - # Styles and formatting - (?P \*\*|'''|//|''|\#\#|``|__|\^\^|,,) + # Styles and formatting ("--" must cling to a word to disambiguate it from the dash) + (?P \*\* | // | \#\# | __ | --\b | \b-- | \^\^ | ,, | ''' | '' | `` ) | (?P \={2,6}) | (?P
\\\\) | (?P ^-{3,}) | (?P \b( FIXME | TODO | DONE )\b ) + | (?P --) # Links | (?P \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>) | (?P \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\]) # Inline HTML - | (?P <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b ) + | (?P <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b ) | (?P ( /\s*> | ) ) | (?P [<>&] ) # Auto links (LEGACY) - | (?P \b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)) + | (?P \b[a-zA-Z0-9_/-]+\.(""" + image_ext + "|" + video_ext + r""")) | (?P \b(?:[A-Z][a-z]+){2,}\b) | (?P (http|https|ftp|mailto)\:[^\s'\"]+\S) | (?P [-\w._+]+\@[\w.-]+) - # Lists, divs, spans + # Lists, divs, spans and inline objects | (?P

  • ^\s+[\*\#]\s+) | (?P
       \{\{\{|\s*\}\}\})
                 | (?P   \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
    @@ -635,7 +642,7 @@ class Page:
             except IOError, err:
                 if err.errno == errno.ENOENT:
                     if default is None:
    -                    default = '//[[%s|Describe %s|action=edit]]//' % (self.page_name, self.page_name)
    +                    default = '//[[?a=edit&q=%s|Describe %s]]//' % (self.page_name, self.page_name)
                     return default
                 if err.errno == errno.EISDIR:
                     return self.format_dir()
    @@ -644,13 +651,13 @@ class Page:
         def format_dir(self):
             out = '== '
             pathname = ''
    -        for dirname in self.page_name.split('/'):
    +        for dirname in self.page_name.strip('/').split('/'):
                 pathname = (pathname + '/' + dirname) if pathname else dirname
                 out += '[[' + pathname + '|' + dirname + ']]/'
             out += ' ==\n'
      
             for filename in page_list(self._filename(), file_re):
    -            if img_re.match(filename):
    +            if image_re.match(filename):
                     if image_maxwidth:
                         maxwidth_arg = ' | maxwidth=' + str(image_maxwidth)
                     out += '{{' + self.page_name + '/' + filename + ' | ' + humanlink(filename) + maxwidth_arg + ' | class=thumbleft}}\n'
    @@ -794,6 +801,9 @@ class Page:
                     os.remove(name)
                 except OSError, err:
                     if err.errno != errno.ENOENT: raise err
    +        path = os.path.split(name)[0]
    +        if not os.path.exists(path):
    +            os.makedirs(path)
             os.rename(tmp_filename, name)
     
         def save(self, newdata, changelog):