Revision: 8636 Author: xqt Date: 2010-10-09 23:32:32 +0000 (Sat, 09 Oct 2010)
Log Message: ----------- update from trunk r8635
Modified Paths: -------------- branches/rewrite/scripts/interwiki.py
Modified: branches/rewrite/scripts/interwiki.py =================================================================== --- branches/rewrite/scripts/interwiki.py 2010-10-09 23:22:42 UTC (rev 8635) +++ branches/rewrite/scripts/interwiki.py 2010-10-09 23:32:32 UTC (rev 8636) @@ -1819,17 +1819,19 @@
if page.section(): # This is not a page, but a subpage. Do not edit it. - pywikibot.output(u"Not editing %s: not doing interwiki on subpages" % page) + pywikibot.output(u"Not editing %s: not doing interwiki on subpages" + % page) raise SaveError(u'Link has a #section') try: pagetext = page.get() except pywikibot.NoPage: - pywikibot.output(u"Not editing %s: page does not exist" % page) + pywikibot.output(u"Not editing %s: page does not exist" + % page) raise SaveError(u'Page doesn't exist')
- # clone original newPages dictionary, so that we can modify it to the local page's needs + # clone original newPages dictionary, so that we can modify it to the + # local page's needs new = dict(newPages) - interwikis = [pywikibot.Page(l) for l in page.iterlanglinks()]
# remove interwiki links to ignore @@ -1840,21 +1842,31 @@ continue
try: - if (new[ignorepage.site] == ignorepage) and (ignorepage.site != page.site): + if (new[ignorepage.site] == ignorepage) and \ + (ignorepage.site != page.site): if (ignorepage not in interwikis): - pywikibot.output(u"Ignoring link to %(to)s for %(from)s" % {'to': ignorepage, 'from': page}) + pywikibot.output( + u"Ignoring link to %(to)s for %(from)s" + % {'to': ignorepage, + 'from': page}) new.pop(ignorepage.site) else: - pywikibot.output(u"NOTE: Not removing interwiki from %(from)s to %(to)s (exists both commented and non-commented)" % {'to': ignorepage, 'from': page}) + pywikibot.output( + u"NOTE: Not removing interwiki from %(from)s to %(to)s (exists both commented and non-commented)" + % {'to': ignorepage, + 'from': page}) except KeyError: pass
- # sanity check - the page we are fixing must be the only one for that site. + # sanity check - the page we are fixing must be the only one for that + # site. pltmp = new[page.site] if pltmp != page: s = u"None" if pltmp is not None: s = pltmp - pywikibot.output(u"BUG>>> %s is not in the list of new links! Found %s." % (page, s)) + pywikibot.output( + u"BUG>>> %s is not in the list of new links! Found %s." + % (page, s)) raise SaveError(u'BUG: sanity check failed')
# Avoid adding an iw link back to itself @@ -1866,9 +1878,12 @@ old[page2.site] = page2
# Check what needs to get done - mods, mcomment, adding, removing, modifying = compareLanguages(old, new, insite = page.site) + mods, mcomment, adding, removing, modifying = compareLanguages(old, + new, + insite=page.site)
- # When running in autonomous mode without -force switch, make sure we don't remove any items, but allow addition of the new ones + # When running in autonomous mode without -force switch, make sure we + # don't remove any items, but allow addition of the new ones if globalvar.autonomous and not globalvar.force and len(removing) > 0: for rmsite in removing: # Sometimes sites have an erroneous link to itself as an @@ -1879,14 +1894,16 @@ #put it to new means don't delete it if not globalvar.cleanup or \ rmPage.title(asLink=True, forceInterwiki=True) not in globalvar.remove or \ - rmPage.site.sitename() == 'wikipedia:hi': #work-arround for bug #3081100 (do not remove hi-pages) + rmPage.site.sitename() == 'wikipedia:hi' and \ + page.site.sitename() != 'wikipedia:de': #work-arround for bug #3081100 (do not remove hi-pages) new[rmsite] = rmPage pywikibot.output( u"WARNING: %s is either deleted or has a mismatching disambiguation state." % rmPage) # Re-Check what needs to get done - mods, mcomment, adding, removing, modifying = compareLanguages(old, new, insite=page.site) - + mods, mcomment, adding, removing, modifying = compareLanguages(old, + new, + insite=page.site) if not mods: if not globalvar.quiet: pywikibot.output(u'No changes needed on page %s' @@ -1895,20 +1912,26 @@ return False
# Show a message in purple. - pywikibot.output(u"\03{lightpurple}Updating links on page %s.\03{default}" % page) - + pywikibot.output( + u"\03{lightpurple}Updating links on page %s.\03{default}" + % page) pywikibot.output(u"Changes to be made: %s" % mods) oldtext = page.get() template = (page.namespace() == 10) newtext = pywikibot.replaceLanguageLinks(oldtext, new, - site = page.site, - template = template) - # This is for now. Later there should be different funktions for each kind + site=page.site, + template=template) + # This is for now. Later there should be different funktions for each + # kind if not botMayEdit(page): if template: - pywikibot.output(u'SKIPPING: %s should have interwiki links on subpage.' % page.aslink(True)) + pywikibot.output( + u'SKIPPING: %s should have interwiki links on subpage.' + % page.aslink(True)) else: - pywikibot.output(u'SKIPPING: %s is under construction or to be deleted.' % page.aslink(True)) + pywikibot.output( + u'SKIPPING: %s is under construction or to be deleted.' + % page.aslink(True)) return False if newtext == oldtext: return False @@ -1917,8 +1940,12 @@ # pywikibot.output(u"NOTE: Replace %s" % page) # Determine whether we need permission to submit ask = False - if removing and removing != [page.site]: # Allow for special case of a self-pointing interwiki link - self.problem(u'Found incorrect link to %s in %s'% (",".join([x.lang for x in removing]), page), createneed = False) + + # Allow for special case of a self-pointing interwiki link + if removing and removing != [page.site]: + self.problem(u'Found incorrect link to %s in %s' + % (",".join([x.lang for x in removing]), + page), createneed=False) ask = True if globalvar.force or globalvar.cleanup: ask = False @@ -1930,9 +1957,10 @@ # If we cannot ask, deny permission answer = 'n' else: - answer = pywikibot.inputChoice(u'Submit?', - ['Yes', 'No', 'open in Browser', 'Give up', 'Always'], - ['y', 'n', 'b', 'g', 'a']) + answer = pywikibot.inputChoice(u'Submit?', + ['Yes', 'No', 'open in Browser', + 'Give up', 'Always'], + ['y', 'n', 'b', 'g', 'a']) if answer == 'b': webbrowser.open("http://%s%s" % ( page.site.hostname(), @@ -1954,7 +1982,8 @@ if bot: while pywikibot.get_throttle.waittime() + 2.0 < pywikibot.put_throttle.waittime(): if not globalvar.quiet: - pywikibot.output(u"NOTE: Performing a recursive query first to save time....") + pywikibot.output( + u"NOTE: Performing a recursive query first to save time....") qdone = bot.oneQuery() if not qdone: # Nothing more to do @@ -1965,20 +1994,23 @@ while True: try: if globalvar.async: - page.put_async(newtext, comment = mcomment) + page.put_async(newtext, comment=mcomment) status = 302 else: - status, reason, data = page.put(newtext, comment = mcomment) + status, reason, data = page.put(newtext, comment=mcomment) except pywikibot.LockedPage: pywikibot.output(u'Page %s is locked. Skipping.' % page.title(asLink=True, forceInterwiki=True)) raise SaveError(u'Locked') except pywikibot.EditConflict: - pywikibot.output(u'ERROR putting page: An edit conflict occurred. Giving up.') + pywikibot.output( + u'ERROR putting page: An edit conflict occurred. Giving up.') raise SaveError(u'Edit conflict') except (pywikibot.SpamfilterError), error: - pywikibot.output(u'ERROR putting page: %s blacklisted by spamfilter. Giving up.' % (error.url,)) + pywikibot.output( + u'ERROR putting page: %s blacklisted by spamfilter. Giving up.' + % (error.url,)) raise SaveError(u'Spam filter') except (pywikibot.PageNotSaved), error: pywikibot.output(u'ERROR putting page: %s' % (error.args,)) @@ -1987,14 +2019,16 @@ if timeout>3600: raise pywikibot.output(u'ERROR putting page: %s' % (error.args,)) - pywikibot.output(u'Sleeping %i seconds before trying again.' % (timeout,)) + pywikibot.output(u'Sleeping %i seconds before trying again.' + % (timeout,)) timeout *= 2 time.sleep(timeout) except pywikibot.ServerError: if timeout > 3600: raise pywikibot.output(u'ERROR putting page: ServerError.') - pywikibot.output(u'Sleeping %i seconds before trying again.' % (timeout,)) + pywikibot.output(u'Sleeping %i seconds before trying again.' + % (timeout,)) timeout *= 2 time.sleep(timeout) else: @@ -2007,7 +2041,9 @@ elif answer == 'g': raise GiveUpOnPage(u'User asked us to give up') else: - raise LinkMustBeRemoved(u'Found incorrect link to %s in %s'% (",".join([x.lang for x in removing]), page)) + raise LinkMustBeRemoved(u'Found incorrect link to %s in %s' + % (",".join([x.lang for x in removing]), + page))
def reportBacklinks(self, new, updatedSites): """ @@ -2313,6 +2349,8 @@ fmt = lambda d, site: site.lang
head, add, rem, mod = pywikibot.translate(insite.lang, msg) + if insite.lang=='de' and not globalvar.autonomous: + head = u'Halbautomatischer %s' % head #prevents abuse filter blocking for hi-wiki
colon = u': ' comma = u', '