jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Link: Use anchor in create_separated
......................................................................
[FIX] Link: Use anchor in create_separated
The create_separated method in Link does use '_label' instead of the correct
'_anchor' property.
Change-Id: I4bb9faccff5683a99d8d1a801d01ca188482e526
---
M pywikibot/page.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 25d2779..c9dbfd6 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -5076,9 +5076,9 @@
elif section is not None:
link._section = None
if label:
- link._label = label
+ link._anchor = label
elif label is not None:
- link._label = ''
+ link._anchor = ''
return link
--
To view, visit https://gerrit.wikimedia.org/r/223004
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4bb9faccff5683a99d8d1a801d01ca188482e526
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: replace.py: remove line endings when reading from file
......................................................................
replace.py: remove line endings when reading from file
Use file.read().splitlines() to prevent spaces from also
being stripped.
Change-Id: I9de69215f98ca583e636b41734ee8effaca5dbee
---
M scripts/replace.py
1 file changed, 2 insertions(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/replace.py b/scripts/replace.py
index f5eeeb6..31188d8 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -817,7 +817,8 @@
if replacement_file:
try:
with codecs.open(replacement_file, 'r', 'utf-8') as f:
- file_replacements = f.readlines()
+ # strip newlines, but not other characters
+ file_replacements = f.read().splitlines()
except (IOError, OSError) as e:
pywikibot.error(u'Error loading {0}: {1}'.format(
replacement_file, e))
--
To view, visit https://gerrit.wikimedia.org/r/222911
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9de69215f98ca583e636b41734ee8effaca5dbee
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] L10N tests for site.lang key
......................................................................
[bugfix] L10N tests for site.lang key
Keys of i18n json files has been changed from site.code to site.lang.
After updating the L10N test is broken due to some sites has different
lang and code property.
- Now check templates for all sites in languages_by_size list.
- skip known problems
- create method name with lang and code
- Check whether a given language has a corresponding site
Change-Id: I43131490147846d3486a6d457dc055ecb7593077
---
M tests/l10n_tests.py
1 file changed, 36 insertions(+), 9 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/l10n_tests.py b/tests/l10n_tests.py
index 10e95b9..287d602 100644
--- a/tests/l10n_tests.py
+++ b/tests/l10n_tests.py
@@ -31,7 +31,7 @@
"""Create the new class."""
# this comment is to avoid senseless flake8 warning
- def test_method(msg, code):
+ def test_method(msg, site):
def test_template(self):
"""Test validity of template."""
@@ -40,27 +40,37 @@
template = re.findall(u'.*?{{(.*?)[|}]', msg)
self.assertTrue(template)
+ # known problem
+ if site.code == 'simple':
+ raise unittest.SkipTest(
+ "'simple' wiki has 'en' language code but "
+ "missing template. Must be solved by the "
+ "corresponding script.")
if template:
- # check whether site is valid
- site = pywikibot.Site('en', 'wikipedia')
- self.assertIn(code, site.languages())
-
# check whether template exists
title = template[0]
- site = pywikibot.Site(code, 'wikipedia')
page = pywikibot.Page(site, title, ns=10)
self.assertTrue(page.exists())
return test_template
# create test methods for package messages processed by unittest
+ site = pywikibot.Site('en', 'wikipedia')
+ codes = site.family.languages_by_size
+ del site
for package in PACKAGES:
- for lang in i18n.twget_keys(package):
+ keys = i18n.twget_keys(package)
+ for code in codes:
+ current_site = pywikibot.Site(code, 'wikipedia')
+ lang = current_site.lang
+ if lang not in keys:
+ continue
template_msg = i18n.twtranslate(lang, package, fallback=False)
if template_msg is None:
continue
- test_name = "test_%s_%s" % (package.replace('-', '_'), lang)
- dct[test_name] = test_method(template_msg, lang)
+ test_name = ("test_%s_%s_%s"
+ % (package, lang, code)).replace('-', '_')
+ dct[test_name] = test_method(template_msg, current_site)
return type.__new__(cls, name, bases, dct)
@@ -74,6 +84,23 @@
net = True # magic flag tells jenkins to not run the test.
+class TestSites(TestCase):
+
+ """Other test L10N cases processed by unittest."""
+
+ site = pywikibot.Site('en', 'wikipedia')
+
+ def test_valid_sites(self):
+ """Test whether language key has a corresponding site."""
+ codes = self.site.family.languages_by_size
+ languages = [pywikibot.Site(code, 'wikipedia').lang for code in codes]
+ for package in PACKAGES:
+ keys = i18n.twget_keys(package)
+ for key in keys:
+ self.assertIn(key, languages,
+ "%s not found in site codes" % key)
+
+
if __name__ == '__main__':
try:
unittest.main()
--
To view, visit https://gerrit.wikimedia.org/r/222981
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I43131490147846d3486a6d457dc055ecb7593077
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Show the file which raised the pywikibot.Error
......................................................................
Show the file which raised the pywikibot.Error
- For investigating the error, it helps to know the affected file page.
- New error message. The error occurs when an invalid or broken template
was fetched.
Change-Id: I0b03a76d233fe664d067e668df781f1998f472ce
---
M scripts/checkimages.py
1 file changed, 2 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 267eb23..1b50c33 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -1325,9 +1325,8 @@
licenses_TEST = regex_are_licenses.findall(self.imageCheckText)
if not self.licenses_found and licenses_TEST:
raise pywikibot.Error(
- "APIs seems down. No templates found with them but "
- "actually there are templates used in the image's "
- "page!")
+ "Invalid or broken templates found in the image's "
+ "page %s!" % self.image)
self.allLicenses = []
if not self.list_licenses:
--
To view, visit https://gerrit.wikimedia.org/r/218598
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0b03a76d233fe664d067e668df781f1998f472ce
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Print a message to run i18n_from_json when python i18n are missing
......................................................................
Print a message to run i18n_from_json when python i18n are missing
python i18n translation files are no longer supported but needed for compat.
But it is easy to create the needed files with a maintenance script. This
patch gives a warning to create these files if they are missing.
Change-Id: Ifd7b65f4d247c59fcea12677c4ead4d1f6567a45
---
M pywikibot/i18n.py
1 file changed, 9 insertions(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index e62d04d..75590c4 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -335,7 +335,15 @@
import table.
"""
package = twtitle.split("-")[0]
- transdict = getattr(__import__("i18n", {}, {}, [package]), package).msg
+ try:
+ transdict = getattr(__import__("i18n", {}, {}, [package]), package).msg
+ except AttributeError:
+ raise TranslationError("No translation file '%s' has been defined\n"
+ "for TranslateWiki key %r.\n"
+ "Please run the maintenance script "
+ "'i18n_from_json.py'\ninside maintenance "
+ "folder to generate the files."
+ % (package, twtitle))
code_needed = False
# If a site is given instead of a code, use its language
--
To view, visit https://gerrit.wikimedia.org/r/222878
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifd7b65f4d247c59fcea12677c4ead4d1f6567a45
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [i18n] change site codes to language codes
......................................................................
[i18n] change site codes to language codes
- _altlang is already changed to use language codes instead of site codes.
This patch renames all site code messages to lang code messages which is
provided by twn. The code map at twn will also be changed in
I4495235231a95f312c2c814aed584ff4c2293e13
Change-Id: I2e5feae49492a8adfcb12bf6bbacf541d847d384
---
R add_text/be-tarask.json
R add_text/gsw.json
R add_text/lzh.json
R add_text/nan.json
R add_text/nb.json
R add_text/sgs.json
R add_text/vro.json
R add_text/yue.json
R archivebot/be-tarask.json
R archivebot/gsw.json
R archivebot/nb.json
R basic/be-tarask.json
R basic/gsw.json
R basic/nb.json
R blockpageschecker/be-tarask.json
R blockpageschecker/gsw.json
R blockpageschecker/nb.json
R capitalize_redirects/be-tarask.json
R capitalize_redirects/gsw.json
R capitalize_redirects/nb.json
R casechecker/be-tarask.json
R casechecker/gsw.json
R casechecker/nb.json
R catall/be-tarask.json
R catall/gsw.json
R catall/nb.json
R category/be-tarask.json
R category/gsw.json
R category/nb.json
R category/sgs.json
R category/vro.json
R category/yue.json
R category_redirect/be-tarask.json
R category_redirect/gsw.json
R category_redirect/nb.json
R category_redirect/sgs.json
R clean_sandbox/be-tarask.json
R clean_sandbox/gsw.json
R clean_sandbox/nb.json
R commons/be-tarask.json
R commons/gsw.json
R commons/nb.json
R commons_link/be-tarask.json
R commons_link/gsw.json
R commons_link/nb.json
R commonscat/be-tarask.json
R commonscat/nb.json
R cosmetic_changes/be-tarask.json
R cosmetic_changes/gsw.json
R cosmetic_changes/nb.json
R delete/be-tarask.json
R delete/gsw.json
R delete/nb.json
R djvutext/be-tarask.json
R djvutext/gsw.json
R djvutext/nb.json
R editarticle/be-tarask.json
R editarticle/gsw.json
R editarticle/nb.json
R featured/be-tarask.json
R featured/gsw.json
R featured/nb.json
R featured/sgs.json
R fixing_redirects/be-tarask.json
R fixing_redirects/gsw.json
R fixing_redirects/nb.json
R followlive/be-tarask.json
R interwiki/be-tarask.json
R interwiki/gsw.json
R interwiki/lzh.json
R interwiki/nan.json
R interwiki/nb.json
R interwiki/sgs.json
R interwiki/vro.json
R interwiki/yue.json
R isbn/be-tarask.json
R isbn/gsw.json
R isbn/nb.json
R lonelypages/be-tarask.json
R lonelypages/gsw.json
R lonelypages/nb.json
R makecat/be-tarask.json
R makecat/nb.json
R misspelling/be-tarask.json
R misspelling/nb.json
R movepages/be-tarask.json
R movepages/gsw.json
R movepages/nb.json
R ndashredir/be-tarask.json
R ndashredir/gsw.json
R ndashredir/nb.json
R noreferences/be-tarask.json
R noreferences/gsw.json
R noreferences/nb.json
R pagefromfile/be-tarask.json
R pagefromfile/nb.json
R piper/be-tarask.json
R protect/be-tarask.json
R protect/gsw.json
R protect/nb.json
R pywikibot/be-tarask.json
R pywikibot/gsw.json
R pywikibot/nb.json
R redirect/be-tarask.json
R redirect/gsw.json
R redirect/lzh.json
R redirect/nb.json
R redirect/sgs.json
R redirect/yue.json
R reflinks/be-tarask.json
R reflinks/gsw.json
R reflinks/nb.json
R remove_edp_images/be-tarask.json
R replace/be-tarask.json
R replace/gsw.json
R replace/nb.json
R revertbot/be-tarask.json
R revertbot/gsw.json
R revertbot/nb.json
R selflink/be-tarask.json
R selflink/nb.json
R solve_disambiguation/be-tarask.json
R solve_disambiguation/gsw.json
R solve_disambiguation/nb.json
R spamremove/be-tarask.json
R spamremove/nb.json
R spellcheck/be-tarask.json
R spellcheck/gsw.json
R spellcheck/nb.json
R table2wiki/be-tarask.json
R table2wiki/gsw.json
R table2wiki/nb.json
R template/be-tarask.json
R template/gsw.json
R template/nb.json
R thirdparty/be-tarask.json
R thirdparty/gsw.json
R thirdparty/nb.json
R undelete/be-tarask.json
R undelete/nb.json
R unlink/be-tarask.json
R unlink/gsw.json
R unlink/nb.json
R unprotect/be-tarask.json
R unprotect/nb.json
R weblinkchecker/be-tarask.json
R weblinkchecker/gsw.json
R weblinkchecker/nb.json
R welcome/be-tarask.json
R welcome/gsw.json
R welcome/nb.json
R welcome/yue.json
152 files changed, 0 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/add_text/be-x-old.json b/add_text/be-tarask.json
similarity index 100%
rename from add_text/be-x-old.json
rename to add_text/be-tarask.json
diff --git a/add_text/als.json b/add_text/gsw.json
similarity index 100%
rename from add_text/als.json
rename to add_text/gsw.json
diff --git a/add_text/zh-classical.json b/add_text/lzh.json
similarity index 100%
rename from add_text/zh-classical.json
rename to add_text/lzh.json
diff --git a/add_text/zh-min-nan.json b/add_text/nan.json
similarity index 100%
rename from add_text/zh-min-nan.json
rename to add_text/nan.json
diff --git a/add_text/no.json b/add_text/nb.json
similarity index 100%
rename from add_text/no.json
rename to add_text/nb.json
diff --git a/add_text/bat-smg.json b/add_text/sgs.json
similarity index 100%
rename from add_text/bat-smg.json
rename to add_text/sgs.json
diff --git a/add_text/fiu-vro.json b/add_text/vro.json
similarity index 100%
rename from add_text/fiu-vro.json
rename to add_text/vro.json
diff --git a/add_text/zh-yue.json b/add_text/yue.json
similarity index 100%
rename from add_text/zh-yue.json
rename to add_text/yue.json
diff --git a/archivebot/be-x-old.json b/archivebot/be-tarask.json
similarity index 100%
rename from archivebot/be-x-old.json
rename to archivebot/be-tarask.json
diff --git a/archivebot/als.json b/archivebot/gsw.json
similarity index 100%
rename from archivebot/als.json
rename to archivebot/gsw.json
diff --git a/archivebot/no.json b/archivebot/nb.json
similarity index 100%
rename from archivebot/no.json
rename to archivebot/nb.json
diff --git a/basic/be-x-old.json b/basic/be-tarask.json
similarity index 100%
rename from basic/be-x-old.json
rename to basic/be-tarask.json
diff --git a/basic/als.json b/basic/gsw.json
similarity index 100%
rename from basic/als.json
rename to basic/gsw.json
diff --git a/basic/no.json b/basic/nb.json
similarity index 100%
rename from basic/no.json
rename to basic/nb.json
diff --git a/blockpageschecker/be-x-old.json b/blockpageschecker/be-tarask.json
similarity index 100%
rename from blockpageschecker/be-x-old.json
rename to blockpageschecker/be-tarask.json
diff --git a/blockpageschecker/als.json b/blockpageschecker/gsw.json
similarity index 100%
rename from blockpageschecker/als.json
rename to blockpageschecker/gsw.json
diff --git a/blockpageschecker/no.json b/blockpageschecker/nb.json
similarity index 100%
rename from blockpageschecker/no.json
rename to blockpageschecker/nb.json
diff --git a/capitalize_redirects/be-x-old.json b/capitalize_redirects/be-tarask.json
similarity index 100%
rename from capitalize_redirects/be-x-old.json
rename to capitalize_redirects/be-tarask.json
diff --git a/capitalize_redirects/als.json b/capitalize_redirects/gsw.json
similarity index 100%
rename from capitalize_redirects/als.json
rename to capitalize_redirects/gsw.json
diff --git a/capitalize_redirects/no.json b/capitalize_redirects/nb.json
similarity index 100%
rename from capitalize_redirects/no.json
rename to capitalize_redirects/nb.json
diff --git a/casechecker/be-x-old.json b/casechecker/be-tarask.json
similarity index 100%
rename from casechecker/be-x-old.json
rename to casechecker/be-tarask.json
diff --git a/casechecker/als.json b/casechecker/gsw.json
similarity index 100%
rename from casechecker/als.json
rename to casechecker/gsw.json
diff --git a/casechecker/no.json b/casechecker/nb.json
similarity index 100%
rename from casechecker/no.json
rename to casechecker/nb.json
diff --git a/catall/be-x-old.json b/catall/be-tarask.json
similarity index 100%
rename from catall/be-x-old.json
rename to catall/be-tarask.json
diff --git a/catall/als.json b/catall/gsw.json
similarity index 100%
rename from catall/als.json
rename to catall/gsw.json
diff --git a/catall/no.json b/catall/nb.json
similarity index 100%
rename from catall/no.json
rename to catall/nb.json
diff --git a/category/be-x-old.json b/category/be-tarask.json
similarity index 100%
rename from category/be-x-old.json
rename to category/be-tarask.json
diff --git a/category/als.json b/category/gsw.json
similarity index 100%
rename from category/als.json
rename to category/gsw.json
diff --git a/category/no.json b/category/nb.json
similarity index 100%
rename from category/no.json
rename to category/nb.json
diff --git a/category/bat-smg.json b/category/sgs.json
similarity index 100%
rename from category/bat-smg.json
rename to category/sgs.json
diff --git a/category/fiu-vro.json b/category/vro.json
similarity index 100%
rename from category/fiu-vro.json
rename to category/vro.json
diff --git a/category/zh-yue.json b/category/yue.json
similarity index 100%
rename from category/zh-yue.json
rename to category/yue.json
diff --git a/category_redirect/be-x-old.json b/category_redirect/be-tarask.json
similarity index 100%
rename from category_redirect/be-x-old.json
rename to category_redirect/be-tarask.json
diff --git a/category_redirect/als.json b/category_redirect/gsw.json
similarity index 100%
rename from category_redirect/als.json
rename to category_redirect/gsw.json
diff --git a/category_redirect/no.json b/category_redirect/nb.json
similarity index 100%
rename from category_redirect/no.json
rename to category_redirect/nb.json
diff --git a/category_redirect/bat-smg.json b/category_redirect/sgs.json
similarity index 100%
rename from category_redirect/bat-smg.json
rename to category_redirect/sgs.json
diff --git a/clean_sandbox/be-x-old.json b/clean_sandbox/be-tarask.json
similarity index 100%
rename from clean_sandbox/be-x-old.json
rename to clean_sandbox/be-tarask.json
diff --git a/clean_sandbox/als.json b/clean_sandbox/gsw.json
similarity index 100%
rename from clean_sandbox/als.json
rename to clean_sandbox/gsw.json
diff --git a/clean_sandbox/no.json b/clean_sandbox/nb.json
similarity index 100%
rename from clean_sandbox/no.json
rename to clean_sandbox/nb.json
diff --git a/commons/be-x-old.json b/commons/be-tarask.json
similarity index 100%
rename from commons/be-x-old.json
rename to commons/be-tarask.json
diff --git a/commons/als.json b/commons/gsw.json
similarity index 100%
rename from commons/als.json
rename to commons/gsw.json
diff --git a/commons/no.json b/commons/nb.json
similarity index 100%
rename from commons/no.json
rename to commons/nb.json
diff --git a/commons_link/be-x-old.json b/commons_link/be-tarask.json
similarity index 100%
rename from commons_link/be-x-old.json
rename to commons_link/be-tarask.json
diff --git a/commons_link/als.json b/commons_link/gsw.json
similarity index 100%
rename from commons_link/als.json
rename to commons_link/gsw.json
diff --git a/commons_link/no.json b/commons_link/nb.json
similarity index 100%
rename from commons_link/no.json
rename to commons_link/nb.json
diff --git a/commonscat/be-x-old.json b/commonscat/be-tarask.json
similarity index 100%
rename from commonscat/be-x-old.json
rename to commonscat/be-tarask.json
diff --git a/commonscat/no.json b/commonscat/nb.json
similarity index 100%
rename from commonscat/no.json
rename to commonscat/nb.json
diff --git a/cosmetic_changes/be-x-old.json b/cosmetic_changes/be-tarask.json
similarity index 100%
rename from cosmetic_changes/be-x-old.json
rename to cosmetic_changes/be-tarask.json
diff --git a/cosmetic_changes/als.json b/cosmetic_changes/gsw.json
similarity index 100%
rename from cosmetic_changes/als.json
rename to cosmetic_changes/gsw.json
diff --git a/cosmetic_changes/no.json b/cosmetic_changes/nb.json
similarity index 100%
rename from cosmetic_changes/no.json
rename to cosmetic_changes/nb.json
diff --git a/delete/be-x-old.json b/delete/be-tarask.json
similarity index 100%
rename from delete/be-x-old.json
rename to delete/be-tarask.json
diff --git a/delete/als.json b/delete/gsw.json
similarity index 100%
rename from delete/als.json
rename to delete/gsw.json
diff --git a/delete/no.json b/delete/nb.json
similarity index 100%
rename from delete/no.json
rename to delete/nb.json
diff --git a/djvutext/be-x-old.json b/djvutext/be-tarask.json
similarity index 100%
rename from djvutext/be-x-old.json
rename to djvutext/be-tarask.json
diff --git a/djvutext/als.json b/djvutext/gsw.json
similarity index 100%
rename from djvutext/als.json
rename to djvutext/gsw.json
diff --git a/djvutext/no.json b/djvutext/nb.json
similarity index 100%
rename from djvutext/no.json
rename to djvutext/nb.json
diff --git a/editarticle/be-x-old.json b/editarticle/be-tarask.json
similarity index 100%
rename from editarticle/be-x-old.json
rename to editarticle/be-tarask.json
diff --git a/editarticle/als.json b/editarticle/gsw.json
similarity index 100%
rename from editarticle/als.json
rename to editarticle/gsw.json
diff --git a/editarticle/no.json b/editarticle/nb.json
similarity index 100%
rename from editarticle/no.json
rename to editarticle/nb.json
diff --git a/featured/be-x-old.json b/featured/be-tarask.json
similarity index 100%
rename from featured/be-x-old.json
rename to featured/be-tarask.json
diff --git a/featured/als.json b/featured/gsw.json
similarity index 100%
rename from featured/als.json
rename to featured/gsw.json
diff --git a/featured/no.json b/featured/nb.json
similarity index 100%
rename from featured/no.json
rename to featured/nb.json
diff --git a/featured/bat-smg.json b/featured/sgs.json
similarity index 100%
rename from featured/bat-smg.json
rename to featured/sgs.json
diff --git a/fixing_redirects/be-x-old.json b/fixing_redirects/be-tarask.json
similarity index 100%
rename from fixing_redirects/be-x-old.json
rename to fixing_redirects/be-tarask.json
diff --git a/fixing_redirects/als.json b/fixing_redirects/gsw.json
similarity index 100%
rename from fixing_redirects/als.json
rename to fixing_redirects/gsw.json
diff --git a/fixing_redirects/no.json b/fixing_redirects/nb.json
similarity index 100%
rename from fixing_redirects/no.json
rename to fixing_redirects/nb.json
diff --git a/followlive/be-x-old.json b/followlive/be-tarask.json
similarity index 100%
rename from followlive/be-x-old.json
rename to followlive/be-tarask.json
diff --git a/interwiki/be-x-old.json b/interwiki/be-tarask.json
similarity index 100%
rename from interwiki/be-x-old.json
rename to interwiki/be-tarask.json
diff --git a/interwiki/als.json b/interwiki/gsw.json
similarity index 100%
rename from interwiki/als.json
rename to interwiki/gsw.json
diff --git a/interwiki/zh-classical.json b/interwiki/lzh.json
similarity index 100%
rename from interwiki/zh-classical.json
rename to interwiki/lzh.json
diff --git a/interwiki/zh-min-nan.json b/interwiki/nan.json
similarity index 100%
rename from interwiki/zh-min-nan.json
rename to interwiki/nan.json
diff --git a/interwiki/no.json b/interwiki/nb.json
similarity index 100%
rename from interwiki/no.json
rename to interwiki/nb.json
diff --git a/interwiki/bat-smg.json b/interwiki/sgs.json
similarity index 100%
rename from interwiki/bat-smg.json
rename to interwiki/sgs.json
diff --git a/interwiki/fiu-vro.json b/interwiki/vro.json
similarity index 100%
rename from interwiki/fiu-vro.json
rename to interwiki/vro.json
diff --git a/interwiki/zh-yue.json b/interwiki/yue.json
similarity index 100%
rename from interwiki/zh-yue.json
rename to interwiki/yue.json
diff --git a/isbn/be-x-old.json b/isbn/be-tarask.json
similarity index 100%
rename from isbn/be-x-old.json
rename to isbn/be-tarask.json
diff --git a/isbn/als.json b/isbn/gsw.json
similarity index 100%
rename from isbn/als.json
rename to isbn/gsw.json
diff --git a/isbn/no.json b/isbn/nb.json
similarity index 100%
rename from isbn/no.json
rename to isbn/nb.json
diff --git a/lonelypages/be-x-old.json b/lonelypages/be-tarask.json
similarity index 100%
rename from lonelypages/be-x-old.json
rename to lonelypages/be-tarask.json
diff --git a/lonelypages/als.json b/lonelypages/gsw.json
similarity index 100%
rename from lonelypages/als.json
rename to lonelypages/gsw.json
diff --git a/lonelypages/no.json b/lonelypages/nb.json
similarity index 100%
rename from lonelypages/no.json
rename to lonelypages/nb.json
diff --git a/makecat/be-x-old.json b/makecat/be-tarask.json
similarity index 100%
rename from makecat/be-x-old.json
rename to makecat/be-tarask.json
diff --git a/makecat/no.json b/makecat/nb.json
similarity index 100%
rename from makecat/no.json
rename to makecat/nb.json
diff --git a/misspelling/be-x-old.json b/misspelling/be-tarask.json
similarity index 100%
rename from misspelling/be-x-old.json
rename to misspelling/be-tarask.json
diff --git a/misspelling/no.json b/misspelling/nb.json
similarity index 100%
rename from misspelling/no.json
rename to misspelling/nb.json
diff --git a/movepages/be-x-old.json b/movepages/be-tarask.json
similarity index 100%
rename from movepages/be-x-old.json
rename to movepages/be-tarask.json
diff --git a/movepages/als.json b/movepages/gsw.json
similarity index 100%
rename from movepages/als.json
rename to movepages/gsw.json
diff --git a/movepages/no.json b/movepages/nb.json
similarity index 100%
rename from movepages/no.json
rename to movepages/nb.json
diff --git a/ndashredir/be-x-old.json b/ndashredir/be-tarask.json
similarity index 100%
rename from ndashredir/be-x-old.json
rename to ndashredir/be-tarask.json
diff --git a/ndashredir/als.json b/ndashredir/gsw.json
similarity index 100%
rename from ndashredir/als.json
rename to ndashredir/gsw.json
diff --git a/ndashredir/no.json b/ndashredir/nb.json
similarity index 100%
rename from ndashredir/no.json
rename to ndashredir/nb.json
diff --git a/noreferences/be-x-old.json b/noreferences/be-tarask.json
similarity index 100%
rename from noreferences/be-x-old.json
rename to noreferences/be-tarask.json
diff --git a/noreferences/als.json b/noreferences/gsw.json
similarity index 100%
rename from noreferences/als.json
rename to noreferences/gsw.json
diff --git a/noreferences/no.json b/noreferences/nb.json
similarity index 100%
rename from noreferences/no.json
rename to noreferences/nb.json
diff --git a/pagefromfile/be-x-old.json b/pagefromfile/be-tarask.json
similarity index 100%
rename from pagefromfile/be-x-old.json
rename to pagefromfile/be-tarask.json
diff --git a/pagefromfile/no.json b/pagefromfile/nb.json
similarity index 100%
rename from pagefromfile/no.json
rename to pagefromfile/nb.json
diff --git a/piper/be-x-old.json b/piper/be-tarask.json
similarity index 100%
rename from piper/be-x-old.json
rename to piper/be-tarask.json
diff --git a/protect/be-x-old.json b/protect/be-tarask.json
similarity index 100%
rename from protect/be-x-old.json
rename to protect/be-tarask.json
diff --git a/protect/als.json b/protect/gsw.json
similarity index 100%
rename from protect/als.json
rename to protect/gsw.json
diff --git a/protect/no.json b/protect/nb.json
similarity index 100%
rename from protect/no.json
rename to protect/nb.json
diff --git a/pywikibot/be-x-old.json b/pywikibot/be-tarask.json
similarity index 100%
rename from pywikibot/be-x-old.json
rename to pywikibot/be-tarask.json
diff --git a/pywikibot/als.json b/pywikibot/gsw.json
similarity index 100%
rename from pywikibot/als.json
rename to pywikibot/gsw.json
diff --git a/pywikibot/no.json b/pywikibot/nb.json
similarity index 100%
rename from pywikibot/no.json
rename to pywikibot/nb.json
diff --git a/redirect/be-x-old.json b/redirect/be-tarask.json
similarity index 100%
rename from redirect/be-x-old.json
rename to redirect/be-tarask.json
diff --git a/redirect/als.json b/redirect/gsw.json
similarity index 100%
rename from redirect/als.json
rename to redirect/gsw.json
diff --git a/redirect/zh-classical.json b/redirect/lzh.json
similarity index 100%
rename from redirect/zh-classical.json
rename to redirect/lzh.json
diff --git a/redirect/no.json b/redirect/nb.json
similarity index 100%
rename from redirect/no.json
rename to redirect/nb.json
diff --git a/redirect/bat-smg.json b/redirect/sgs.json
similarity index 100%
rename from redirect/bat-smg.json
rename to redirect/sgs.json
diff --git a/redirect/zh-yue.json b/redirect/yue.json
similarity index 100%
rename from redirect/zh-yue.json
rename to redirect/yue.json
diff --git a/reflinks/be-x-old.json b/reflinks/be-tarask.json
similarity index 100%
rename from reflinks/be-x-old.json
rename to reflinks/be-tarask.json
diff --git a/reflinks/als.json b/reflinks/gsw.json
similarity index 100%
rename from reflinks/als.json
rename to reflinks/gsw.json
diff --git a/reflinks/no.json b/reflinks/nb.json
similarity index 100%
rename from reflinks/no.json
rename to reflinks/nb.json
diff --git a/remove_edp_images/be-x-old.json b/remove_edp_images/be-tarask.json
similarity index 100%
rename from remove_edp_images/be-x-old.json
rename to remove_edp_images/be-tarask.json
diff --git a/replace/be-x-old.json b/replace/be-tarask.json
similarity index 100%
rename from replace/be-x-old.json
rename to replace/be-tarask.json
diff --git a/replace/als.json b/replace/gsw.json
similarity index 100%
rename from replace/als.json
rename to replace/gsw.json
diff --git a/replace/no.json b/replace/nb.json
similarity index 100%
rename from replace/no.json
rename to replace/nb.json
diff --git a/revertbot/be-x-old.json b/revertbot/be-tarask.json
similarity index 100%
rename from revertbot/be-x-old.json
rename to revertbot/be-tarask.json
diff --git a/revertbot/als.json b/revertbot/gsw.json
similarity index 100%
rename from revertbot/als.json
rename to revertbot/gsw.json
diff --git a/revertbot/no.json b/revertbot/nb.json
similarity index 100%
rename from revertbot/no.json
rename to revertbot/nb.json
diff --git a/selflink/be-x-old.json b/selflink/be-tarask.json
similarity index 100%
rename from selflink/be-x-old.json
rename to selflink/be-tarask.json
diff --git a/selflink/no.json b/selflink/nb.json
similarity index 100%
rename from selflink/no.json
rename to selflink/nb.json
diff --git a/solve_disambiguation/be-x-old.json b/solve_disambiguation/be-tarask.json
similarity index 100%
rename from solve_disambiguation/be-x-old.json
rename to solve_disambiguation/be-tarask.json
diff --git a/solve_disambiguation/als.json b/solve_disambiguation/gsw.json
similarity index 100%
rename from solve_disambiguation/als.json
rename to solve_disambiguation/gsw.json
diff --git a/solve_disambiguation/no.json b/solve_disambiguation/nb.json
similarity index 100%
rename from solve_disambiguation/no.json
rename to solve_disambiguation/nb.json
diff --git a/spamremove/be-x-old.json b/spamremove/be-tarask.json
similarity index 100%
rename from spamremove/be-x-old.json
rename to spamremove/be-tarask.json
diff --git a/spamremove/no.json b/spamremove/nb.json
similarity index 100%
rename from spamremove/no.json
rename to spamremove/nb.json
diff --git a/spellcheck/be-x-old.json b/spellcheck/be-tarask.json
similarity index 100%
rename from spellcheck/be-x-old.json
rename to spellcheck/be-tarask.json
diff --git a/spellcheck/als.json b/spellcheck/gsw.json
similarity index 100%
rename from spellcheck/als.json
rename to spellcheck/gsw.json
diff --git a/spellcheck/no.json b/spellcheck/nb.json
similarity index 100%
rename from spellcheck/no.json
rename to spellcheck/nb.json
diff --git a/table2wiki/be-x-old.json b/table2wiki/be-tarask.json
similarity index 100%
rename from table2wiki/be-x-old.json
rename to table2wiki/be-tarask.json
diff --git a/table2wiki/als.json b/table2wiki/gsw.json
similarity index 100%
rename from table2wiki/als.json
rename to table2wiki/gsw.json
diff --git a/table2wiki/no.json b/table2wiki/nb.json
similarity index 100%
rename from table2wiki/no.json
rename to table2wiki/nb.json
diff --git a/template/be-x-old.json b/template/be-tarask.json
similarity index 100%
rename from template/be-x-old.json
rename to template/be-tarask.json
diff --git a/template/als.json b/template/gsw.json
similarity index 100%
rename from template/als.json
rename to template/gsw.json
diff --git a/template/no.json b/template/nb.json
similarity index 100%
rename from template/no.json
rename to template/nb.json
diff --git a/thirdparty/be-x-old.json b/thirdparty/be-tarask.json
similarity index 100%
rename from thirdparty/be-x-old.json
rename to thirdparty/be-tarask.json
diff --git a/thirdparty/als.json b/thirdparty/gsw.json
similarity index 100%
rename from thirdparty/als.json
rename to thirdparty/gsw.json
diff --git a/thirdparty/no.json b/thirdparty/nb.json
similarity index 100%
rename from thirdparty/no.json
rename to thirdparty/nb.json
diff --git a/undelete/be-x-old.json b/undelete/be-tarask.json
similarity index 100%
rename from undelete/be-x-old.json
rename to undelete/be-tarask.json
diff --git a/undelete/no.json b/undelete/nb.json
similarity index 100%
rename from undelete/no.json
rename to undelete/nb.json
diff --git a/unlink/be-x-old.json b/unlink/be-tarask.json
similarity index 100%
rename from unlink/be-x-old.json
rename to unlink/be-tarask.json
diff --git a/unlink/als.json b/unlink/gsw.json
similarity index 100%
rename from unlink/als.json
rename to unlink/gsw.json
diff --git a/unlink/no.json b/unlink/nb.json
similarity index 100%
rename from unlink/no.json
rename to unlink/nb.json
diff --git a/unprotect/be-x-old.json b/unprotect/be-tarask.json
similarity index 100%
rename from unprotect/be-x-old.json
rename to unprotect/be-tarask.json
diff --git a/unprotect/no.json b/unprotect/nb.json
similarity index 100%
rename from unprotect/no.json
rename to unprotect/nb.json
diff --git a/weblinkchecker/be-x-old.json b/weblinkchecker/be-tarask.json
similarity index 100%
rename from weblinkchecker/be-x-old.json
rename to weblinkchecker/be-tarask.json
diff --git a/weblinkchecker/als.json b/weblinkchecker/gsw.json
similarity index 100%
rename from weblinkchecker/als.json
rename to weblinkchecker/gsw.json
diff --git a/weblinkchecker/no.json b/weblinkchecker/nb.json
similarity index 100%
rename from weblinkchecker/no.json
rename to weblinkchecker/nb.json
diff --git a/welcome/be-x-old.json b/welcome/be-tarask.json
similarity index 100%
rename from welcome/be-x-old.json
rename to welcome/be-tarask.json
diff --git a/welcome/als.json b/welcome/gsw.json
similarity index 100%
rename from welcome/als.json
rename to welcome/gsw.json
diff --git a/welcome/no.json b/welcome/nb.json
similarity index 100%
rename from welcome/no.json
rename to welcome/nb.json
diff --git a/welcome/zh-yue.json b/welcome/yue.json
similarity index 100%
rename from welcome/zh-yue.json
rename to welcome/yue.json
--
To view, visit https://gerrit.wikimedia.org/r/222757
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2e5feae49492a8adfcb12bf6bbacf541d847d384
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/i18n
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [BREAK][FEAT] Support strings in replace_links
......................................................................
[BREAK][FEAT] Support strings in replace_links
It breaks parts of replace_links that when it the replacement may be a string
and it will be replaced directly and not converted into a link. This only
happens when the replacement was a callable and not a sequence so that it's
still possible to quickly replace links by using a sequence. It won't support
bytes to avoid encoding issues.
On start of replace_links it'll convert the string into a link if it's using a
sequence and not a callable.
This change is necessary for selflink which also supports replacing a link with
any text (in that case the bold page title). It now subclasses the unlink script
as almost everything can be reused.
Change-Id: I54c4015795d8190606454200be23c07016459d26
---
M pywikibot/bot.py
M pywikibot/textlib.py
M scripts/selflink.py
M scripts/unlink.py
M tests/textlib_tests.py
M tox.ini
6 files changed, 151 insertions(+), 172 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 61b9ab0..53c9eb7 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1803,6 +1803,37 @@
**kwargs)
+class AutomaticTWSummaryBot(CurrentPageBot):
+
+ """
+ A class which automatically defines C{summary} for C{put_current}.
+
+ The class must defined a C{summary_key} string which contains the i18n key
+ for L{pywikibot.i18n.twtranslate}. It can also override the
+ C{summary_parameters} property to specify any parameters for the translated
+ message.
+ """
+
+ summary_key = None # must be defined in subclasses
+
+ @property
+ def summary_parameters(self):
+ """A dictionary of all parameters for i18n."""
+ return {}
+
+ def put_current(self, *args, **kwargs):
+ """Defining a summary if not already defined and then call original."""
+ if 'summary' not in kwargs:
+ from pywikibot import i18n
+ if self.summary_key is None:
+ raise ValueError('The summary_key must be set.')
+ summary = i18n.twtranslate(self.current_page.site, self.summary_key,
+ self.summary_parameters)
+ pywikibot.log('Use automatic summary message "{0}"'.format(summary))
+ kwargs['summary'] = summary
+ super(AutomaticTWSummaryBot, self).put_current(*args, **kwargs)
+
+
class ExistingPageBot(CurrentPageBot):
"""A CurrentPageBot class which only treats existing pages."""
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index d3ed4c6..32b38e7 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -459,8 +459,14 @@
depending on the result for that link. If the result is just None it skips
that link. When it's False it unlinks it and just inserts the label. When it
is a Link instance it'll use the target, section and label from that Link
- instance. If it's a string or Page instance it'll use just the target from
- the replacement and the section and label from the original link.
+ instance. If it's a Page instance it'll use just the target from the
+ replacement and the section and label from the original link.
+
+ If it's a string and the replacement was a sequence it converts it into a
+ Page instance. If the replacement is done via a callable it'll use it like
+ unlinking and directly replace the link with the text itself. It only
+ supports unicode when used by the callable and bytes (str in Python 2) are
+ not allowed.
If either the section or label should be used the replacement can be a
function which returns a Link instance and copies the value which should
@@ -476,10 +482,10 @@
the first pipe which might contain additional data which is used in File
namespace for example.
Alternatively it can be a sequence containing two items where the first
- must be a Link or Page and the second has the same meaning as the result
- by the callable. It'll convert that into a callable where the first item
- (the Link or Page) has to be equal to the found link and in that case it
- will apply the second value from the sequence.
+ must be a Link or Page and the second has almost the same meaning as the
+ result by the callable. It'll convert that into a callable where the
+ first item (the Link or Page) has to be equal to the found link and in
+ that case it will apply the second value from the sequence.
@type replace: sequence of pywikibot.Page/pywikibot.Link/str or
callable
@param site: a Site object to use if replace is not a sequence or the link
@@ -503,9 +509,7 @@
def check_replacement_class(replacement):
"""Normalize the replacement into a list."""
- # separate checks as basestring is a type in Python 2
- if (not isinstance(replacement, (pywikibot.Page, pywikibot.Link)) and
- not isinstance(replacement, basestring)):
+ if not isinstance(replacement, (pywikibot.Page, pywikibot.Link)):
raise ValueError('The replacement must be None, False, '
'a sequence, a Link or a basestring but '
'is "{0}"'.format(type(replacement)))
@@ -520,9 +524,10 @@
'The original value must be either basestring, Link or Page '
'but is "{0}"'.format(type(replace_items[0])))
if replace_items[1] is not False and replace_items[1] is not None:
+ if isinstance(replace_items[1], basestring):
+ replace_items[1] = pywikibot.Page(site, replace_items[1])
check_replacement_class(replace_items[0])
- if (not isinstance(replace_items[1], basestring) and
- replace_items[0].site != replace_items[1].site):
+ if replace_items[0].site != replace_items[1].site:
raise ValueError('Both pages in the "replace" argument '
'must belong to the same site.')
site = replace_items[0].site
@@ -602,10 +607,18 @@
if replacement is False:
# unlink - we remove the section if there's any
- text = text[:rng[0]] + link_text + text[rng[1]:]
+ assert isinstance(link_text, unicode), 'link text must be unicode.'
+ replacement = link_text
+ if isinstance(replacement, unicode):
+ # Nothing good can come out of the fact that bytes is returned so
+ # force unicode
+ text = text[:rng[0]] + replacement + text[rng[1]:]
# Make sure that next time around we will not find this same hit.
- curpos = rng[0] + len(link_text)
+ curpos = rng[0] + len(replacement)
continue
+ elif isinstance(replacement, bytes):
+ raise ValueError('The result must be unicode (str in Python 3) and '
+ 'not bytes (str in Python 2).')
# Verify that it's either Link, Page or basestring
check_replacement_class(replacement)
@@ -613,10 +626,7 @@
if isinstance(replacement, pywikibot.Link):
is_link = True
else:
- if isinstance(replacement, pywikibot.Page):
- replacement = replacement._link
- else:
- replacement = pywikibot.Link(replacement, site)
+ replacement = replacement._link
is_link = False
new_page_title = replacement.canonical_title()
diff --git a/scripts/selflink.py b/scripts/selflink.py
index f8de1b2..9502e8a 100755
--- a/scripts/selflink.py
+++ b/scripts/selflink.py
@@ -17,13 +17,13 @@
#
from __future__ import unicode_literals
-import re
import pywikibot
-from pywikibot import i18n
-from pywikibot.bot import SingleSiteBot
-from pywikibot.editor import TextEditor
+
+from pywikibot.bot import Choice, MultipleSitesBot
from pywikibot.pagegenerators import GeneratorFactory, PreloadingGenerator, \
parameterHelp
+
+from scripts.unlink import BaseUnlinkBot
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -32,146 +32,46 @@
}
-class SelflinkBot(SingleSiteBot):
+class _BoldChoice(Choice):
+
+ """A choice to make the title bold."""
+
+ def __init__(self, page, replacer):
+ super(_BoldChoice, self).__init__('make bold', 'b', replacer)
+ self._page = page
+
+ def handle(self):
+ return "'''{0}'''".format(self._page.title(withSection=False))
+
+
+class SelflinkBot(MultipleSitesBot, BaseUnlinkBot):
"""Self-link removal bot."""
+ summary_key = 'selflink-remove'
+
def __init__(self, generator, **kwargs):
+ """Constructor."""
super(SelflinkBot, self).__init__(**kwargs)
self.generator = generator
- linktrail = self.site.linktrail()
- # The regular expression which finds links. Results consist of four
- # groups:
- # group title is the target page title, everything before | or ].
- # group section is the page section. It'll include the # to make life
- # easier for us.
- # group label is the alternative link title, that's everything between
- # | and ].
- # group linktrail is the link trail, that's letters after ]] which are
- # part of the word.
- # note that the definition of 'letter' varies from language to
- # language.
- self.linkR = re.compile(
- r'\[\[(?P<title>[^\]\|#]*)'
- r'(?P<section>#[^\]\|]*)?'
- r'(\|(?P<label>[^\]]*))?\]\]'
- r'(?P<linktrail>' + linktrail + ')')
- def handleNextLink(self, page, match, context=100):
- """Process the next link on a page, offering the user choices.
+ def _create_callback(self):
+ """Create callback and add a choice to make the link bold."""
+ callback = super(SelflinkBot, self)._create_callback()
+ callback.additional_choices += [_BoldChoice(self.current_page, callback)]
+ return callback
- @param page: The page being edited
- @type page: pywikibot.Page
- @param match: The match object for the current link.
- @type match: re.MatchObject
- @param context: The amount of context around the link shown to the user
- @type context: int
- @return: jumpToBeginning, a boolean, which specifies if the cursor
- position should be reset to 0. This is required after the user has
- edited the article.
- """
- # ignore interwiki links and links to sections of the same page as well
- # as section links
- if not match.group('title') \
- or page.site.isInterwikiLink(match.group('title')) \
- or match.group('section'):
- return False
- try:
- linkedPage = pywikibot.Page(page.site, title=match.group('title'))
- except pywikibot.InvalidTitle as err:
- pywikibot.warning(u'%s' % err)
- return False
-
- # Check whether the link found is to the current page itself.
- if linkedPage != page:
- # not a self-link, nothing to do
- return False
-
- # at the beginning of the link, start red color.
- # at the end of the link, reset the color to default
- if self.getOption('always'):
- choice = 'a'
- else:
- pre = page.text[max(0, match.start() - context):match.start()]
- post = page.text[match.end():match.end() + context]
- matchText = match.group(0)
+ def treat_page(self):
+ """Unlink all links pointing to the current page."""
+ # Inside image maps, don't touch selflinks, as they're used
+ # to create tooltip labels. See for example:
+ # https://de.wikipedia.org/w/index.php?diff=next&oldid=35721641
+ if '<imagemap>' in self.current_page.text:
pywikibot.output(
- pre + '\03{lightred}' + matchText + '\03{default}' + post)
- choice = pywikibot.input_choice(
- u'\nWhat shall be done with this selflink?\n',
- [('unlink', 'u'), ('make bold', 'b'), ('skip', 's'),
- ('edit', 'e'), ('more context', 'm'), ('unlink all', 'a')], 'u')
- pywikibot.output(u'')
-
- if choice == 's':
- # skip this link
- return False
- elif choice == 'e':
- editor = TextEditor()
- newText = editor.edit(page.text, jumpIndex=match.start())
- # if user didn't press Cancel
- if newText:
- page.text = newText
- return True
- else:
- return True
- elif choice == 'm':
- # show more context by recursive self-call
- return self.handleNextLink(page, match, context=context + 100)
- elif choice == 'a':
- self.always = True
-
- # choice was 'U', 'b', or 'a'
- new = match.group('label') or match.group('title')
- new += match.group('linktrail')
- preMatch = page.text[:match.start()]
- postMatch = page.text[match.end():]
- if choice == 'b':
- # make bold
- page.text = preMatch + "'''" + new + "'''" + postMatch
- return False
- else:
- page.text = preMatch + new + postMatch
- return False
-
- def treat(self, page):
- self.current_page = page
- try:
- oldText = page.text
- # Inside image maps, don't touch selflinks, as they're used
- # to create tooltip labels. See for example:
- # https://de.wikipedia.org/w/index.php?diff=next&oldid=35721641
- if '<imagemap>' in page.text:
- pywikibot.output(
- u'Skipping page %s because it contains an image map.'
- % page.title(asLink=True))
- return
- curpos = 0
- while curpos < len(page.text):
- match = self.linkR.search(page.text, pos=curpos)
- if not match:
- break
- # Make sure that next time around we will not find this same
- # hit.
- curpos = match.start() + 1
- jumpToBeginning = self.handleNextLink(page, match)
- if jumpToBeginning:
- curpos = 0
-
- if oldText == page.text:
- pywikibot.output(u'No changes necessary.')
- else:
- pywikibot.showDiff(oldText, page.text)
- comment = i18n.twtranslate(page.site, "selflink-remove")
- page.save(async=True, summary=comment)
- except pywikibot.NoPage:
- pywikibot.output(u"Page %s does not exist."
- % page.title(asLink=True))
- except pywikibot.IsRedirectPage:
- pywikibot.output(u"Page %s is a redirect; skipping."
- % page.title(asLink=True))
- except pywikibot.LockedPage:
- pywikibot.output(u"Page %s is locked." % page.title(asLink=True))
+ u'Skipping page %s because it contains an image map.'
+ % self.current_page.title(asLink=True))
+ return
+ self.unlink(self.current_page)
def main(*args):
diff --git a/scripts/unlink.py b/scripts/unlink.py
index e1bd901..6672217 100755
--- a/scripts/unlink.py
+++ b/scripts/unlink.py
@@ -31,10 +31,9 @@
#
import pywikibot
-from pywikibot import i18n
from pywikibot.bot import (
- SingleSiteBot, ExistingPageBot, NoRedirectPageBot, InteractiveReplace,
- ChoiceException, UnhandledAnswer, AlwaysChoice,
+ SingleSiteBot, ExistingPageBot, NoRedirectPageBot, AutomaticTWSummaryBot,
+ InteractiveReplace, ChoiceException, UnhandledAnswer, AlwaysChoice,
)
from pywikibot.editor import TextEditor
from pywikibot.textlib import replace_links
@@ -74,38 +73,30 @@
return answer
-class UnlinkBot(SingleSiteBot, ExistingPageBot, NoRedirectPageBot):
+class BaseUnlinkBot(ExistingPageBot, NoRedirectPageBot, AutomaticTWSummaryBot):
- """Page unlinking bot."""
+ """A bot unlinking a given link from the current page."""
- def __init__(self, pageToUnlink, **kwargs):
- """Initialize a UnlinkBot instance with the given page to unlink."""
+ def __init__(self, **kwargs):
+ """Redirect all parameters and add namespace as an available option."""
self.availableOptions.update({
'namespaces': [],
# Which namespaces should be processed?
# default to [] which means all namespaces will be processed
})
-
- super(UnlinkBot, self).__init__(site=pageToUnlink.site, **kwargs)
- self.pageToUnlink = pageToUnlink
-
- self.generator = pageToUnlink.getReferences(
- namespaces=self.getOption('namespaces'), content=True)
- self.comment = i18n.twtranslate(self.pageToUnlink.site, 'unlink-unlinking',
- {'title': self.pageToUnlink.title()})
+ super(BaseUnlinkBot, self).__init__(**kwargs)
def _create_callback(self):
"""Create a new callback instance for replace_links."""
return InteractiveUnlink(self)
- def treat_page(self):
- """Remove links pointing to the configured page from the given page."""
+ def unlink(self, target_page):
+ """Unlink all links linking to the target page."""
text = self.current_page.text
while True:
unlink_callback = self._create_callback()
try:
- text = replace_links(text, unlink_callback,
- self.pageToUnlink.site)
+ text = replace_links(text, unlink_callback, target_page.site)
except EditReplacement:
new_text = TextEditor().edit(
unlink_callback.current_text,
@@ -118,7 +109,30 @@
else:
break
- self.put_current(text, summary=self.comment)
+ self.put_current(text)
+
+
+class UnlinkBot(SingleSiteBot, BaseUnlinkBot):
+
+ """A bot unlinking the given link from the current page."""
+
+ summary_key = 'unlink-unlinking'
+
+ @property
+ def summary_parameters(self):
+ """Return the title parameter."""
+ return {'title': self.pageToUnlink.title()}
+
+ def __init__(self, pageToUnlink, **kwargs):
+ """Initialize a UnlinkBot instance with the given page to unlink."""
+ super(UnlinkBot, self).__init__(**kwargs)
+ self.pageToUnlink = pageToUnlink
+ self.generator = pageToUnlink.getReferences(
+ namespaces=self.getOption('namespaces'), content=True)
+
+ def treat_page(self):
+ """Remove links pointing to the configured page from the given page."""
+ self.unlink(self.pageToUnlink)
def main(*args):
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 6dbc7d0..a08db27 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -707,6 +707,29 @@
textlib.replace_links('[[Talk:test]]s', ('Talk:Test', 'Project:Tests'), self.wp_site),
'[[Project:Tests|Talk:tests]]')
+ def test_unicode_callback(self):
+ """Test returning unicode in the callback."""
+ def callback(link, text, groups, rng):
+ self.assertEqual(link.site, self.wp_site)
+ if link.title == 'World':
+ # This must be a unicode instance not bytes
+ return 'homewörlder'
+ self.assertEqual(
+ textlib.replace_links(self.text, callback, self.wp_site),
+ 'Hello homewörlder, [[how|are]] [[you#section|you]]? Are [[you]] a '
+ '[[bug:1337]]?')
+
+ def test_bytes_callback(self):
+ """Test returning bytes in the callback."""
+ def callback(link, text, groups, rng):
+ self.assertEqual(link.site, self.wp_site)
+ if link.title == 'World':
+ # This must be a bytes instance not unicode
+ return b'homeworlder'
+ self.assertRaisesRegex(
+ ValueError, r'unicode \(str.*bytes \(str',
+ textlib.replace_links, self.text, callback, self.wp_site)
+
class TestLocalDigits(TestCase):
diff --git a/tox.ini b/tox.ini
index 5459eda..ebfd765 100644
--- a/tox.ini
+++ b/tox.ini
@@ -94,6 +94,7 @@
scripts/pagefromfile.py \
scripts/piper.py \
scripts/protect.py \
+ scripts/selflink.py \
scripts/shell.py \
scripts/spamremove.py \
scripts/states_redirect.py \
--
To view, visit https://gerrit.wikimedia.org/r/219626
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I54c4015795d8190606454200be23c07016459d26
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Elyashiv <elyashi.horovitz(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>