瀏覽代碼

Made check_exclusion() more case-insensitive (#26)

tags/v0.1^2
Ben Kurtovic 12 年之前
父節點
當前提交
b04494b3f3
共有 1 個文件被更改,包括 12 次插入4 次删除
  1. +12
    -4
      earwigbot/wiki/page.py

+ 12
- 4
earwigbot/wiki/page.py 查看文件

@@ -729,7 +729,7 @@ class Page(CopyrightMixIn):
def check_exclusion(self, username=None, optouts=None):
"""Check whether or not we are allowed to edit the page.

Return ``True`` if we *are* allowed to edit this page, or ``False`` if
Return ``True`` if we *are* allowed to edit this page, and ``False`` if
we aren't.

*username* is used to determine whether we are part of a specific list
@@ -746,22 +746,30 @@ class Page(CopyrightMixIn):
``{{bots|optout=all}}``, but `True` on
``{{bots|optout=orfud,norationale,replaceable}}``.
"""
def parse_param(template, param):
value = template.get_param(param).value
return [item.strip().lower() for item in value.split(",")]

if not username:
username = self.site.get_user().name

# Lowercase everything:
username = username.lower()
optouts = [optout.lower() for optout in optouts] if optouts else []

re_bots = "\{\{\s*(no)?bots\s*(\||\}\})"
filter = self.parse().filter_templates(matches=re_bots, recursive=True)
for template in filter:
if template.has_param("deny"):
denies = template.get_param("deny").value.split(",")
denies = parse_param(template, "deny")
if "all" in denies or username in denies:
return False
if template.has_param("allow"):
allows = template.get_param("allow").value.split(",")
allows = parse_param(template, "allow")
if "all" in allows or username in allows:
continue
if optouts and template.has_param("optout"):
tasks = template.get_param("optout").value.split(",")
tasks = parse_param(template, "optout")
matches = [optout in tasks for optout in optouts]
if "all" in tasks or any(matches):
return False


Loading…
取消
儲存