http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10404
Revision: 10404 Author: russblau Date: 2012-06-21 18:19:05 +0000 (Thu, 21 Jun 2012) Log Message: ----------- Add explicit Site().login() calls to all scripts that write to the wiki.
Modified Paths: -------------- branches/rewrite/scripts/basic.py branches/rewrite/scripts/blockpageschecker.py branches/rewrite/scripts/category.py branches/rewrite/scripts/category_redirect.py branches/rewrite/scripts/clean_sandbox.py branches/rewrite/scripts/cosmetic_changes.py branches/rewrite/scripts/editarticle.py branches/rewrite/scripts/imageuncat.py branches/rewrite/scripts/interwiki.py branches/rewrite/scripts/isbn.py branches/rewrite/scripts/redirect.py branches/rewrite/scripts/replace.py branches/rewrite/scripts/solve_disambiguation.py branches/rewrite/scripts/touch.py
Modified: branches/rewrite/scripts/basic.py =================================================================== --- branches/rewrite/scripts/basic.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/basic.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -51,7 +51,7 @@ self.generator = generator self.dry = dry # Set the edit summary message - self.summary = i18n.twtranslate(pywikibot.getSite(), 'basic-changing') + self.summary = i18n.twtranslate(site, 'basic-changing')
def run(self): for page in self.generator: @@ -130,6 +130,7 @@ return False
def main(): + global site # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. @@ -152,11 +153,12 @@ # -start:XYZ or -ref:Asdf was given. if not genFactory.handleArg(arg): pageTitleParts.append(arg) - + site = pywikibot.Site() + site.login() if pageTitleParts != []: # We will only work on a single page. pageTitle = ' '.join(pageTitleParts) - page = pywikibot.Page(pywikibot.Link(pageTitle, pywikibot.getSite())) + page = pywikibot.Page(pywikibot.Link(pageTitle, site)) gen = iter([page])
if not gen:
Modified: branches/rewrite/scripts/blockpageschecker.py =================================================================== --- branches/rewrite/scripts/blockpageschecker.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/blockpageschecker.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -240,6 +240,7 @@ pywikibot.output(u"Your project is not supported by this script.\nYou have to edit the script and add it!") return site = pywikibot.getSite() + site.login() if protectedpages: generator = site.protectedpages(namespace=namespace, type=protectType) # Take the right templates to use, the category and the comment
Modified: branches/rewrite/scripts/category.py =================================================================== --- branches/rewrite/scripts/category.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/category.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -884,7 +884,7 @@ create_pages = True else: genFactory.handleArg(arg) - + pywikibot.Site().login() gen = genFactory.getCombinedGenerator() if action == 'add': if not gen:
Modified: branches/rewrite/scripts/category_redirect.py =================================================================== --- branches/rewrite/scripts/category_redirect.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/category_redirect.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -36,6 +36,7 @@ def __init__(self): self.cooldown = 7 # days self.site = pywikibot.getSite() + self.site.login() self.catprefix = self.site.namespace(14)+":" self.log_text = [] self.edit_requests = []
Modified: branches/rewrite/scripts/clean_sandbox.py =================================================================== --- branches/rewrite/scripts/clean_sandbox.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/clean_sandbox.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -120,6 +120,7 @@ self.availableOptions['delay_td'] = datetime.timedelta(minutes=d)
self.site = pywikibot.Site() + self.site.login() if sandboxTitle.get(self.site.code) is None or \ content.get(self.site.code) is None: pywikibot.output(u'This bot is not configured for the given site ' \
Modified: branches/rewrite/scripts/cosmetic_changes.py =================================================================== --- branches/rewrite/scripts/cosmetic_changes.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/cosmetic_changes.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -909,8 +909,9 @@ # Load default summary message. editSummary = i18n.twtranslate(pywikibot.getSite(), 'cosmetic_changes-standalone') + site = pywikibot.getSite() + site.login() if pageTitle: - site = pywikibot.getSite() gen = iter([pywikibot.Page(pywikibot.Link(t, site)) for t in pageTitle]) if not gen: gen = genFactory.getCombinedGenerator()
Modified: branches/rewrite/scripts/editarticle.py =================================================================== --- branches/rewrite/scripts/editarticle.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/editarticle.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -40,6 +40,7 @@ self.set_options(*args) self.setpage() self.site = pywikibot.getSite() + self.site.login()
def set_options(self, *args): """Parse commandline and set options attribute"""
Modified: branches/rewrite/scripts/imageuncat.py =================================================================== --- branches/rewrite/scripts/imageuncat.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/imageuncat.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -1337,6 +1337,7 @@ genFactory = pagegenerators.GeneratorFactory()
site = pywikibot.getSite(u'commons', u'commons') + site.login() for arg in pywikibot.handleArgs(*args): if arg.startswith('-yesterday'): generator = uploadedYesterday(site)
Modified: branches/rewrite/scripts/interwiki.py =================================================================== --- branches/rewrite/scripts/interwiki.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/interwiki.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -2414,8 +2414,9 @@ globalvar.summary += u'; '
# ensure that we don't try to change main page + site = pywikibot.getSite() + site.login() try: - site = pywikibot.getSite() mainpagename = site.mediawiki_message('mainpage') globalvar.skip.add(pywikibot.Page(site, mainpagename)) except pywikibot.Error: @@ -2438,7 +2439,6 @@ hintlessPageGen = pagegenerators.NewpagesPageGenerator(newPages, namespace=ns)
elif optRestore or optContinue or globalvar.restoreAll: - site = pywikibot.getSite() dumpFileName = pywikibot.config.datafilepath( 'data', 'interwiki-dumps',
Modified: branches/rewrite/scripts/isbn.py =================================================================== --- branches/rewrite/scripts/isbn.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/isbn.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -1469,6 +1469,7 @@ pageTitle.append(arg)
site = pywikibot.getSite() + site.login() if pageTitle: gen = iter([pywikibot.Page(pywikibot.Link(t, site)) for t in pageTitle]) if not gen:
Modified: branches/rewrite/scripts/redirect.py =================================================================== --- branches/rewrite/scripts/redirect.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/redirect.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -70,6 +70,7 @@ use_move_log=False, use_api=False, start=None, until=None, number=None, step=None): self.site = pywikibot.getSite() + self.site.login() self.xmlFilename = xmlFilename self.namespaces = namespaces if use_api and self.namespaces == []:
Modified: branches/rewrite/scripts/replace.py =================================================================== --- branches/rewrite/scripts/replace.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/replace.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -170,7 +170,7 @@ if "inside" in self.exceptions: self.excsInside += self.exceptions['inside'] from pywikibot import xmlreader - self.site = pywikibot.getSite() + self.site = pywikibot.Site() dump = xmlreader.XmlDump(self.xmlFilename) self.parser = dump.parse()
@@ -536,7 +536,7 @@ allowoverlap = True else: commandline_replacements.append(arg) - + pywikibot.Site().login() gen = genFactory.getCombinedGenerator() if (len(commandline_replacements) % 2): raise pywikibot.Error, 'require even number of replacements.'
Modified: branches/rewrite/scripts/solve_disambiguation.py =================================================================== --- branches/rewrite/scripts/solve_disambiguation.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/solve_disambiguation.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -1067,12 +1067,14 @@ pywikibot.showHelp() else: pageTitle.append(arg) - + site = pywikibot.Site() + site.login() + # if the disambiguation page is given as a command line argument, # connect the title's parts with spaces if pageTitle != []: pageTitle = ' '.join(pageTitle) - page = pywikibot.Page(pywikibot.Link(pageTitle, pywikibot.getSite())) + page = pywikibot.Page(pywikibot.Link(pageTitle, site)) generator = iter([page])
# if no disambiguation page was given as an argument, and none was @@ -1080,7 +1082,7 @@ if not generator: pageTitle = pywikibot.input( u'On which disambiguation page do you want to work?') - page = pywikibot.Page(pywikibot.Link(pageTitle, pywikibot.getSite())) + page = pywikibot.Page(pywikibot.Link(pageTitle, site)) generator = iter([page])
bot = DisambiguationRobot(always, alternatives, getAlternatives, dnSkip,
Modified: branches/rewrite/scripts/touch.py =================================================================== --- branches/rewrite/scripts/touch.py 2012-06-21 13:03:17 UTC (rev 10403) +++ branches/rewrite/scripts/touch.py 2012-06-21 18:19:05 UTC (rev 10404) @@ -79,7 +79,7 @@ redirs = True else: pageTitle.append(arg) - + pywikibot.Site().login() gen = genFactory.getCombinedGenerator() if not gen: if pageTitle: