http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10774
Revision: 10774 Author: xqt Date: 2012-12-10 13:05:50 +0000 (Mon, 10 Dec 2012) Log Message: ----------- New functionality for bot restriction templates "bots" and "nobots". "nobots" may have a parameter either a script name or a bots username. {{nobots|interwiki}} denies all bots using interwiki.py {{nobots|botname}} is equal to {{bots|deny=botname}} {{nobots|all}} is equal to {{nobots}} and prohibits all bot edits.
"bots" has two new parameter "allowscript" and "denyscript". Guess what it does.
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2012-12-09 14:28:00 UTC (rev 10773) +++ trunk/pywikipedia/wikipedia.py 2012-12-10 13:05:50 UTC (rev 10774) @@ -1599,9 +1599,17 @@ except (NoPage, IsRedirectPage, SectionError): return True
+ # go through all templates and look for any restriction + # multiple bots/nobots templates are allowed for template in templates: if template[0].lower() == 'nobots': - return False + if len(template[1]) == 0: + return False + else: + bots = template[1][0].split(',') + if 'all' in bots or calledModuleName() in bots \ + or username in bots: + return False elif template[0].lower() == 'bots': if len(template[1]) == 0: return True @@ -1609,15 +1617,13 @@ (ttype, bots) = template[1][0].split('=', 1) bots = bots.split(',') if ttype == 'allow': - if 'all' in bots or username in bots: - return True - else: - return False + return 'all' in bots or username in bots if ttype == 'deny': - if 'all' in bots or username in bots: - return False - else: - return True + return not ('all' in bots or username in bots) + if ttype == 'allowscript': + return 'all' in bots or calledModuleName() in bots + if ttype == 'denyscript': + return not ('all' in bots or calledModuleName() in bots) # no restricting template found return True
pywikipedia-svn@lists.wikimedia.org