Prianka has uploaded a new change for review.
https://gerrit.wikimedia.org/r/195030
Change subject: Porting pywikibot-compat/stanndardize_interwiki.py to core.
......................................................................
Porting pywikibot-compat/stanndardize_interwiki.py to core.
Change-Id: Ia4cb80aab4bbdb443fa8ae224c027f7d303e134d
---
M pywikibot/textlib.py
A scripts/standardize_interwiki.py
2 files changed, 104 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/30/195030/1
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index aa40e10..5e820c9 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -636,10 +636,11 @@
s = []
for site in ar:
try:
- title = links[site].title(asLink=True, forceInterwiki=True,
- insite=insite)
- link = title.replace('[[:', '[[')
- s.append(link)
+ if isinstance(links[site], pywikibot.Page):
+ title = links[site].title(asLink=True, forceInterwiki=True,
+ insite=insite)
+ link = title.replace('[[:', '[[')
+ s.append(link)
except AttributeError:
s.append(pywikibot.Site(code=site).linkto(links[site],
othersite=insite))
if insite.lang in insite.family.interwiki_on_one_line:
diff --git a/scripts/standardize_interwiki.py b/scripts/standardize_interwiki.py
new file mode 100644
index 0000000..65ed07b
--- /dev/null
+++ b/scripts/standardize_interwiki.py
@@ -0,0 +1,99 @@
+#!/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
+
+Usage: python pwb.py scripts/standardize_interwiki.py -start:!
+"""
+#
+# (C) Rob W.W. Hooft, 2003
+# (C) Pywikibot team, 2003-2015
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+#
+
+import pywikibot
+from pywikibot import pagegenerators, 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'機器人: 跨語連結標準化',
+}
+
+
+def main(*args):
+ # Some parameters
+ start = list()
+
+ # Load the default parameters and start
+ genFactory = pagegenerators.GeneratorFactory()
+ for arg in pywikibot.handle_args(args):
+ if arg.startswith('-start'):
+ if len(arg) == 6:
+ start = unicode(pywikibot.input(
+ u'From what page do you want to start?'))
+ else:
+ start = unicode(arg[7:])
+ else:
+ genFactory.handleArg(arg)
+ 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] = pl2
+ newtext = textlib.replaceLanguageLinks(oldtext, new, site=site)
+ if new:
+ if oldtext != newtext:
+ pywikibot.showDiff(oldtext, newtext)
+ # Submit changes
+ try:
+ if not pl:
+ status, reason, data = pl.put(newtext,
comment=comm)
+ if str(status) != '302':
+ pywikibot.output(status, reason)
+ 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()
+
+if __name__ == "__main__":
+ main()
--
To view, visit https://gerrit.wikimedia.org/r/195030
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia4cb80aab4bbdb443fa8ae224c027f7d303e134d
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Prianka <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits