X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=774225ba4ae53f125fb5ff0bc39f9a36766eba97;hb=0fa173798560d7862de9caa0fa225f02037eb14d;hp=07b3307709e243518dfcebb9f4e54b1c2185765c;hpb=2dafdcc5717df0896b6a9c9843e36ea3de981422;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index 07b3307..774225b 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -24,7 +24,6 @@ from time import clock start_time = clock() import cgi, sys, os, re, errno, stat -from os import path, environ # Regular expression defining a WikiWord # (but this definition is also assumed in other places) @@ -32,6 +31,7 @@ word_re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$") # FIXME: we accept stuff like foo/../bar and we shouldn't file_re = re.compile(r"^\b([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)\b$") img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg|bmp|ico)$", 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*([^\]]+)|)(?:\]\]|}})") @@ -41,29 +41,32 @@ title_done = False # CGI stuff --------------------------------------------------------- def script_name(): - return environ.get('SCRIPT_NAME', '') + return os.environ.get('SCRIPT_NAME', '') def privileged_path(): return privileged_url or script_name() def remote_user(): - user = environ.get('REMOTE_USER', '') + user = os.environ.get('REMOTE_USER', '') if user is None or user == '' or user == 'anonymous': user = 'AnonymousCoward' return user def remote_host(): - return environ.get('REMOTE_ADDR', '') + return os.environ.get('REMOTE_ADDR', '') def get_hostname(addr): try: from socket import gethostbyaddr return gethostbyaddr(addr)[0] + ' (' + addr + ')' - except Exception, er: + except Exception: return addr +def is_external_url(pathname): + return (url_re.match(pathname) or pathname.startswith('/')) + def relative_url(pathname, privileged=False): - if not (url_re.match(pathname) or pathname.startswith('/')): + if not is_external_url(pathname): if privileged: url = privileged_path() else: @@ -85,7 +88,7 @@ def send_guru(msg_text, msg_type): print ' Software Failure. Press left mouse button to continue.\n' print msg_text if msg_type == 'error': - print ' Guru Meditation #DEADBEEF.ABADC0DE' + print '\n Guru Meditation #DEADBEEF.ABADC0DE' print '' # FIXME: This little JS snippet is harder to pass than ACID 3.0 print """ @@ -120,12 +123,15 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal print ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' print '' - site_name = globals().get('site_name', 'Unconfigured Site') print "%s: %s" % (site_name, text) print ' ' if not name: print ' ' + for meta in meta_urls: + http_equiv, content = meta + print ' ' % (http_equiv, relative_url(content)) + for link in link_urls: rel, href = link print ' ' % (rel, relative_url(href)) @@ -179,17 +185,29 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal print '
' -def link_tag(params, text=None, ss_class=None, privileged=False): +def send_httperror(status="403 Not Found", query=""): + print "Status: %s" % status + send_title(None, msg_text=("%s: on query '%s'" % (status, query))) + send_footer() + +def link_tag(params, text=None, link_class=None, privileged=False): if text is None: text = params # default - classattr = '' - if ss_class: - classattr += 'class="%s" ' % ss_class - # Prevent crawlers from following links potentially added by spammers or to generated pages - if ss_class == 'external' or ss_class == 'navlink': - classattr += 'rel="nofollow" ' - elif url_re.match(params): - classattr += 'rel="nofollow" ' + + if not link_class: + if is_external_url(params): + link_class = 'external' + elif file_re.match(params) and Page(params).exists(): + link_class = 'wikilink' + else: + params = nonexist_pfx + params + link_class = 'nonexistent' + + classattr = 'class="%s" ' % link_class + # Prevent crawlers from following links potentially added by spammers or to generated pages + if link_class == 'external' or link_class == 'navlink': + classattr += 'rel="nofollow"' + return '%s' % (classattr, relative_url(params, privileged=privileged), text) # Search --------------------------------------------------- @@ -213,7 +231,7 @@ def handle_fullsearch(needle): print "