img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re.IGNORECASE)
video_re = re.compile(r"^.*\.(ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re.IGNORECASE)
url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$")
-link_re = re.compile("(?:\[\[|{{)([^\s\|]+)(?:\s*\|\s*([^\]]+)|)(?:\]\]|}})")
+link_re = re.compile(r"(?:\[\[|{{)([^\s\|]+)(?:\s*\|\s*([^\]]+)|)(?:\]\]|}})")
+ext_re = re.compile(r"\.([^\./]+)$")
title_done = False
print ' Software Failure. Press left mouse button to continue.\n'
print msg_text
if msg_type == 'error':
- print '\n Guru Meditation #DEADBEEF.ABADC0DE'
+ print '\n Guru Meditation #DEADBEEF.ABADC0DE'
print '</pre>'
try:
sendfile(sys.stdout, open('gurumeditation.js', 'rb'))
def link_inline(name, descr=None, args=''):
if not descr: descr = name
+ url = relative_url(name)
if video_re.match(name):
- return '<video src="%s">Your browser does not support the HTML5 video tag</video>' % name
+ return '<video src="%s">Your browser does not support the HTML5 video tag</video>' % url
+ elif img_re.match(name):
+ return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (url, url + args, descr)
+ elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page
+ return Page(name).send_naked()
else:
- return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (name, name + args, descr)
+ return '<iframe width="100%%" scrolling="auto" frameborder="0" src="%s"><a href="%s">%s</a></iframe>' \
+ % (url, url, name)
# Search ---------------------------------------------------
return link_tag(m.group(1), m.group(2))
def _inl_repl(self, word):
- m = link_re.match(word)
- name = relative_url(m.group(1))
- descr = m.group(2)
+ (name, descr) = link_re.match(word).groups()
if descr:
argv = descr.split('|')
return False
raise err
- def get_raw_body(self):
+ def get_raw_body(self, default=None):
try:
return open(self._filename(), 'rb').read()
except IOError, err:
if err.errno == errno.ENOENT:
- return '' # just doesn't exist, use default
+ if default is None:
+ default = '//[[?edit=%s|Describe %s]]//' % (self.page_name, self.page_name)
+ return default
if err.errno == errno.EISDIR:
return self.format_dir()
raise err
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="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())
+ 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=''))
print '<label for="file" accesskey="u">Or Upload a file:</label> <input type="file" name="file" value="%s" />' % filename
print """
<br />
output = child.stdout.read()
rc = child.wait()
if rc:
- self.msg_text += "Post-editing hook returned %d.\n" % rc
- self.msg_text += 'Command was: ' + ' '.join(cmd) + '\n'
+ self.msg_text += "Post-editing hook returned %d. Command was:\n'%s'\n" % (rc, "' '".join(cmd))
if output:
self.msg_text += 'Output follows:\n' + output
else: