classattr = ''
if ss_class:
classattr += 'class="%s" ' % ss_class
- # Prevent crawlers from following links to generated pages
- # and links added by potential spammers
+ # Prevent crawlers from following links potentially added by spammers or to generated pages
if ss_class == 'external' or ss_class == 'navlink':
classattr += 'rel="nofollow" '
if authentication:
def _tit_repl(self, word):
if self.h_level:
- result = "</h%d></a>" % self.h_level
+ result = '</h%d>' % self.h_level
self.h_level = 0
else:
self.h_level = len(word) - 1
self.h_count += 1
- result = '<a href="#%d"><h%d id="%d">' % (self.h_count, self.h_level, self.h_count)
+ result = '<h%d id="%d"><a class="heading" href="#%d">*</a> ' % (self.h_level, self.h_count, self.h_count)
return result
def _rule_repl(self, word):
raise "Can't handle match " + `match`
def print_html(self):
- print "<div class='wiki'><p>"
+ print '<div class="wiki"><p>'
# For each line, we scan through looking for magic
# strings, outputting verbatim any intervening text
if self.in_pre: print '</pre>'
if self.in_table: print '</tbody></table><p>'
print self._undent()
- print "</p></div>"
+ print '</p></div>'
# ----------------------------------------------------------
class Page:
raise er
return self.attrs
- def can_edit(self):
+ def can(self, action, default=True):
attrs = self.get_attrs()
try:
# SomeUser:read,write All:read
acl = attrs["acl"]
for rule in acl.split():
- (user,perms) = acl.split(':')
+ (user,perms) = rule.split(':')
if user == remote_user() or user == "All":
- if 'write' in perms.split(','):
+ if action in perms.split(','):
return True
+ else:
+ return False
return False
- except:
+ except Exception, er:
pass
- return True
+ return default
+
+ def can_write(self):
+ return self.can("write", True)
+
+ def can_read(self):
+ return self.can("read", True)
def send_page(self):
page_name = None
- if self.can_edit():
+ if self.can_write():
page_name = self.page_name
send_title(page_name, self.split_title(), msg=self.msg, msg_type=self.msg_type)
- PageFormatter(self.get_raw_body()).print_html()
+ if self.can_read():
+ PageFormatter(self.get_raw_body()).print_html()
+ else:
+ print "<p>This page is not visible to you</p>"
send_footer(page_name, self._last_modified())
def _last_modified(self):
# Configuration values
site_name = 'Codewiz'
- # set to None for read-only sites
- # leave empty ('') to allow anonymous edits
+ # set to None for read-only sites, leave empty ('') to allow anonymous edits
# otherwise, set to a URL that requires authentication
privileged_url = 'https://www.codewiz.org/~bernie/wiki'