# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-__version__ = '$Id$'[4:12]
+__version__ = '4.0-' + '$Id$'[4:11]
from time import clock
start_time = clock()
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():
return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip())
def humanlink(s):
- return re.sub(r'([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' '))
+ return re.sub(r'(?:.*[/:]|)([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' '))
# Split arg lists like "blah| blah blah| width=100 | align = center",
# return a list containing anonymous arguments and a map containing the named arguments
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 = '<img border="0" src="' + relative_url(text) + '" alt="' + text + '" />'
link_class = kvargs.get('class', kvargs.get('cssclass', None))
url = relative_url(name)
if video_re.match(name):
return '<video controls="1" src="%s">Your browser does not support the HTML5 video tag</video>' % url
- elif img_re.match(name):
+ elif image_re.match(name):
return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (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()
cgi.print_arguments()
cgi.print_form(form)
cgi.print_environ()
+ #FIXME link_inline("sys/footer")
print('''
<div id="footer"><hr />
<p class="copyright">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img class="license" alt="Creative Commons License" src="%s" /></a>
<span class="benchmark">generated in %0.3fs</span> by <a href="http://www.codewiz.org/wiki/GeekiGeeki">GeekiGeeki</a> version %s
</p>
-''' % (relative_url('cc-by-sa.png'), clock() - start_time, __version__))
+''' % (relative_url('sys/cc-by-sa.png'), clock() - start_time, __version__))
if mod_string:
print('<p class="modified">last modified %s</p>' % mod_string)
print('</div></body></html>')
"**": ["b", False],
"##": ["tt", False],
"__": ["u", False],
+ "--": ["del", False],
"^^": ["sup", False],
",,": ["sub", False],
"''": ["em", False], # LEGACY
style[1] = not style[1]
return ['</', '<'][style[1]] + style[0] + '>'
+ def _glyph_repl(self, word):
+ return '—'
+
def _tit_repl(self, word):
if self.h_level:
result = '</h%d><p>\n' % self.h_level
print('<div class="wiki"><p>')
scan_re = re.compile(r"""(?:
- # Styles and formatting
- (?P<b> \*\*|'''|//|''|\#\#|``|__|\^\^|,,)
+ # Styles and formatting ("--" must cling to a word to disambiguate it from the dash)
+ (?P<b> \*\* | // | \#\# | __ | --\b | \b-- | \^\^ | ,, | ''' | '' | `` )
| (?P<tit> \={2,6})
| (?P<br> \\\\)
| (?P<rule> ^-{3,})
| (?P<hi> \b( FIXME | TODO | DONE )\b )
+ | (?P<glyph> --)
# Links
| (?P<macro> \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)
| (?P<hurl> \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])
# Inline HTML
- | (?P<html> <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b )
+ | (?P<html> <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b )
| (?P<htmle> ( /\s*> | </(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])> ) )
| (?P<ent> [<>&] )
# Auto links (LEGACY)
- | (?P<img> \b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt))
+ | (?P<img> \b[a-zA-Z0-9_/-]+\.(""" + image_ext + "|" + video_ext + r"""))
| (?P<word> \b(?:[A-Z][a-z]+){2,}\b)
| (?P<url> (http|https|ftp|mailto)\:[^\s'\"]+\S)
| (?P<email> [-\w._+]+\@[\w.-]+)
- # Lists, divs, spans
+ # Lists, divs, spans and inline objects
| (?P<li> ^\s+[\*\#]\s+)
| (?P<pre> \{\{\{|\s*\}\}\})
| (?P<inl> \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
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()
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'
+ ' from ' + cgi.escape(get_hostname(remote_host()))
+ '</b></p>'))
print('<div class="editor"><form name="editform" method="post" enctype="multipart/form-data" action="%s">' % relative_url(self.page_name))
- print('<input type="hidden" name="edit" value="%s">' % (self.page_name))
+ print('<input type="hidden" name="a" value="edit" /><input type="hidden" name="q" value="' + self.page_name + '" />')
print('<input type="input" id="editor" name="changelog" value="Edit page %s" accesskey="c" /><br />' % (self.page_name))
print('<textarea wrap="off" spellcheck="true" id="editor" name="savetext" rows="17" cols="100" accesskey="e">%s</textarea>' \
% cgi.escape(preview or self.get_raw_body(default='')))
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):