jenkins-bot has submitted this change and it was merged.
Change subject: Porting pywikibot-compat/standardize_interwiki.py to core. ......................................................................
Porting pywikibot-compat/standardize_interwiki.py to core.
Change-Id: Ia4cb80aab4bbdb443fa8ae224c027f7d303e134d --- A scripts/standardize_interwiki.py M tests/script_tests.py 2 files changed, 95 insertions(+), 0 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/standardize_interwiki.py b/scripts/standardize_interwiki.py new file mode 100644 index 0000000..7ca682f --- /dev/null +++ b/scripts/standardize_interwiki.py @@ -0,0 +1,94 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +Loop over all pages in the home wiki, standardizing the interwiki links. + +Parameters: + +-start: - Set from what page you want to start +""" +# +# (C) Rob W.W. Hooft, 2003 +# (C) Pywikibot team, 2003-2015 +# +# Distributed under the terms of the MIT license. +# +from __future__ import absolute_import, unicode_literals + +__version__ = '$Id$' + +import pywikibot + +from pywikibot import textlib + +# The summary that the Bot will use. +comment = { + 'ar': u'روبوت: توحيد قياسي للإنترويكي', + 'cs': u'Standadizace interwiki', + 'de': u'Bot: Interwikilinks standardisieren', + 'en': u'Robot: Interwiki standardization', + 'fa': u'ربات: تصحیح جایگذاری میانویکیها', + 'fr': u'Robot : Standardisation des interwikis', + 'he': u'בוט: מסדר את האינטרוויקי', + 'it': u'Bot: Standardizzo interwiki', + 'ja': u'ロボットによる: 言語間リンクを標準化', + 'ml': u'യന്ത്രം: അന്തർവിക്കി ക്രമവൽക്കരണം', + 'nl': u'Bot: standaardisatie interwikiverwijzingen', + 'no': u'bot: Språklenkestandardisering', + 'ksh': u'Bot: Engerwiki Lengks opprüühme', + 'nds': u'Bot: Links twüschen Wikis standardisseern', + 'zh': u'機器人: 跨語連結標準化', +} + + +# Some parameters +options = list() +start = list() +filelist = list() +hints = {} +debug = 0 +start = '!' +nothing = False + +# Load the default parameters and start +for arg in pywikibot.handle_args(): + if arg.startswith('-start'): + if len(arg) == 6: + start = pywikibot.input(u'From what page do you want to start?') + else: + start = arg[7:] +site = pywikibot.Site() +comm = pywikibot.translate(site, comment) + +# What follows is the main part of the code. +try: + for pl in site.allpages(start): + plname = pl.title() + pywikibot.output(u'\nLoading %s...' % plname) + try: + oldtext = pl.get() + except pywikibot.IsRedirectPage: + pywikibot.output(u"%s is a redirect!" % plname) + continue + old = pl.interwiki() + new = {} + for pl2 in old: + new[pl2.site] = pywikibot.Page(pl2) + newtext = textlib.replaceLanguageLinks(oldtext, new, site=site) + if new: + if oldtext != newtext: + pywikibot.showDiff(oldtext, newtext) + # Submit changes + try: + pl.put(newtext, comment=comm) + except pywikibot.LockedPage: + pywikibot.output(u"%s is locked" % plname) + continue + else: + pywikibot.output(u'No changes needed.') + continue + else: + pywikibot.output(u'No interwiki found.') + continue +finally: + pywikibot.stopme() diff --git a/tests/script_tests.py b/tests/script_tests.py index aea9dcc..5338bf7 100644 --- a/tests/script_tests.py +++ b/tests/script_tests.py @@ -110,6 +110,7 @@ 'nowcommons', 'script_wui', 'shell', + 'standardize_interwiki', 'states_redirect', 'unusedfiles', 'upload',