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:
send_title(None, msg_text=("%s: on query '%s'" % (status, query)))
send_footer()
-def link_tag(params, text=None, ss_class=None, privileged=False):
+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 '<a %shref="%s">%s</a>' % (classattr, relative_url(params, privileged=privileged), text)
# Search ---------------------------------------------------
print "<ul>"
for (count, page_name) in hits:
- print '<li><p>' + Page(page_name).link_to()
+ print '<li><p>' + link_tag(page_name)
print ' . . . . ' + `count`
print ['match', 'matches'][count != 1]
print '</p></li>'
print "<ul>"
for filename in hits:
- print '<li><p>' + Page(filename).link_to() + "</p></li>"
+ print '<li><p>' + link_tag(filename) + "</p></li>"
print "</ul>"
print_search_stats(len(hits), len(all_pages))
return self._undent() + '\n<hr size="%d" noshade="noshade" />\n' % (len(word) - 2)
def _word_repl(self, word):
- return Page(word).link_to()
+ return link_tag(word)
def _img_repl(self, word):
pathname = relative_url(word)
elif img_re.match(m.group(2)):
descr = '<img border="0" src="' + descr + '" />'
- return link_tag(name, descr, 'wikilink')
+ return link_tag(name, descr)
def _inl_repl(self, word):
m = link_re.match(word)
return False
raise err
- def link_to(self):
- word = self.page_name
- if self.exists():
- return link_tag(word, word, 'wikilink')
- else:
- return link_tag(word, nonexist_pfx + word, 'nonexistent')
-
def get_raw_body(self):
try:
return open(self._filename(), 'rb').read()
//-->
</script>
"""
- print "<p>" + Page('EditingTips').link_to() + "</p>"
+ print "<p>" + link_tag('EditingTips') + "</p>"
if preview:
print "<div class='preview'>"
WikiFormatter(preview).print_html()