http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10912
Revision: 10912 Author: drtrigon Date: 2013-01-13 20:03:40 +0000 (Sun, 13 Jan 2013) Log Message: ----------- bug fix; allow bot to write in any case new feature; pass additional parameters to put
Modified Paths: -------------- trunk/pywikipedia/basic.py trunk/pywikipedia/sum_disc.py
Modified: trunk/pywikipedia/basic.py =================================================================== --- trunk/pywikipedia/basic.py 2013-01-13 17:47:01 UTC (rev 10911) +++ trunk/pywikipedia/basic.py 2013-01-13 20:03:40 UTC (rev 10912) @@ -99,8 +99,7 @@ return text return None
- def save(self, text, page, comment=None, minorEdit=True, - botflag=True): + def save(self, text, page, comment=None, **kwargs): # only save if something was changed if text != page.get(): # Show the title of the page we're working on. @@ -117,7 +116,7 @@ try: # Save the page page.put(text, comment=comment or self.comment, - minorEdit=minorEdit, botflag=botflag) + minorEdit=minorEdit, botflag=botflag, **kwargs) except pywikibot.LockedPage: pywikibot.output(u"Page %s is locked; skipping." % page.title(asLink=True)) @@ -143,7 +142,7 @@
## @since 10326 # @remarks needed by various bots - def save(self, page, text, comment=None, minorEdit=True, botflag=True): + def save(self, page, text, comment=None, **kwargs): pywikibot.output(u'\03{lightblue}Writing to wiki on %s...\03{default}' % page.title(asLink=True))
comment_output = comment or pywikibot.action @@ -154,7 +153,7 @@ for i in range(3): # try max. 3 times try: # Save the page - page.put(text, comment=comment, minorEdit=minorEdit, botflag=botflag) + page.put(text, comment=comment, **kwargs) except pywikibot.LockedPage: pywikibot.output(u"\03{lightblue}Page %s is locked; skipping.\03{default}" % page.title(asLink=True)) except pywikibot.EditConflict: @@ -167,14 +166,14 @@
## @since 10326 # @remarks needed by various bots - def append(self, page, text, comment=None, minorEdit=True, section=None): + def append(self, page, text, comment=None, section=None, **kwargs): if section: pywikibot.output(u'\03{lightblue}Appending to wiki on %s in section %s...\03{default}' % (page.title(asLink=True), section))
for i in range(3): # try max. 3 times try: # Append to page section - page.append(text, comment=comment, minorEdit=minorEdit, section=section) + page.append(text, comment=comment, section=section, **kwargs) except pywikibot.PageNotSaved, error: pywikibot.output(u'\03{lightblue}Cannot change %s because of %s\03{default}' % (page.title(), error)) else: @@ -187,7 +186,7 @@ content += u'\n\n' content += text
- return self.save(page, content, comment=comment, minorEdit=minorEdit) + return self.save(page, content, comment=comment, **kwargs)
## @since 10326 # @remarks needed by various bots
Modified: trunk/pywikipedia/sum_disc.py =================================================================== --- trunk/pywikipedia/sum_disc.py 2013-01-13 17:47:01 UTC (rev 10911) +++ trunk/pywikipedia/sum_disc.py 2013-01-13 20:03:40 UTC (rev 10912) @@ -1068,20 +1068,20 @@ if not self._mode: # default: write direct to user disc page comment = head + add % {'num':count} - #self.append(self._userPage, buf, comment=comment, minorEdit=False) + #self.append(self._userPage, buf, comment=comment, minorEdit=False, force=True) (page, text, minEd) = (self._userPage, buf, False) else: # enhanced (with template): update user disc page and write to user specified page tmplsite = pywikibot.Page(self.site, self._tmpl_data) comment = head + mod % {'num':count, 'page':tmplsite.title(asLink=True)} - self.save(self._userPage, self._content, comment=comment, minorEdit=False) + self.save(self._userPage, self._content, comment=comment, minorEdit=False, force=True) comment = head + add % {'num':count} - #self.append(tmplsite, buf, comment=comment) + #self.append(tmplsite, buf, comment=comment, force=True) (page, text, minEd) = (tmplsite, buf, True) # 'True' is default if (self._param['cleanup_count'] < 0): # default mode, w/o cleanup try: - self.append(page, text, comment=comment, minorEdit=minEd) + self.append(page, text, comment=comment, minorEdit=minEd, force=True) except pywikibot.MaxTriesExceededError: logging.getLogger('sum_disc').warning( u'Problem MaxTriesExceededError occurred, thus skipping this user!') @@ -1091,7 +1091,7 @@ text = self.cleanupDiscSum( self.load(page) or u'', days=self._param['cleanup_count'] ) + u'\n\n' + text comment = head + clean % {'num':count} - self.save(page, text, comment=comment, minorEdit=minEd) + self.save(page, text, comment=comment, minorEdit=minEd, force=True) purge = self._userPage.purgeCache()
pywikibot.output(u'\03{lightpurple}*** Discussion updates added to: %s (purge: %s)\03{default}' % (self._userPage.title(asLink=True), purge))