jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/361390 )
Change subject: [bugfix] Add colon when replacing category and file weblinks
......................................................................
[bugfix] Add colon when replacing category and file weblinks
External links to wiki categories are replaced by internal ones without
a colon before link target. This behavior is wrong as those internal
links to categories without a preleading colon are used for a different
approach.
In addition the problem involves also links to files.
Bug: T127745
Change-Id: If07182a6476498ad71ced821000bf91df2516cd8
---
M pywikibot/cosmetic_changes.py
M tests/cosmetic_changes_tests.py
2 files changed, 30 insertions(+), 1 deletion(-)
Approvals:
Dvorapa: Looks good to me, but someone else must approve
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index e160467..0ae1ccf 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -688,7 +688,12 @@
"""Convert weblinks to wikilink, fix link
syntax."""
def replace_link(match):
"""Create a string to replace a single
link."""
- replacement = '[[' + match.group('link')
+ replacement = '[['
+ if re.match(r'(?:' + '|'.join(list(self.site.namespaces[6])
+
+ list(self.site.namespaces[14])) + '):',
+ match.group('link')):
+ replacement += ':'
+ replacement += match.group('link')
if match.group('title'):
replacement += '|' + match.group('title')
return replacement + ']]'
diff --git a/tests/cosmetic_changes_tests.py b/tests/cosmetic_changes_tests.py
index c5a6397..d8cc01c 100644
--- a/tests/cosmetic_changes_tests.py
+++ b/tests/cosmetic_changes_tests.py
@@ -120,6 +120,10 @@
# necessary as the fixer needs the article path to fix it
self.cct.site._siteinfo._cache['general'] = (
{'articlepath': '/wiki/$1'}, True)
+ self.cct.site._namespaces = {
+ 6: ['Datei', 'File'],
+ 14: ['Kategorie', 'Category'],
+ }
self.assertEqual(
'[[Example|Page]]\n[[Example|Page]]\n[[Example|Page]]\n'
'[[Example]]\n[[Example]]\n[[Example]]\n'
@@ -180,6 +184,26 @@
self.assertEqual(
'[https://de.wikipedia.org/w/api.php API]',
self.cct.fixSyntaxSave('[https://de.wikipedia.org/w/api.php|API]'))
+ self.assertEqual(
+ '[[:Kategorie:Example]]\n'
+ '[[:Category:Example|Description]]\n'
+ '[[:Datei:Example.svg]]\n'
+ '[[:File:Example.svg|Description]]\n'
+ '[[:Category:Example]]\n'
+ '[[:Kategorie:Example|Description]]\n'
+ '[[:File:Example.svg]]\n'
+ '[[:Datei:Example.svg|Description]]\n',
+ self.cct.fixSyntaxSave(
+ '[https://de.wikipedia.org/wiki/Kategorie:Example]\n'
+ '[https://de.wikipedia.org/wiki/Category:Example Description]\n'
+ '[https://de.wikipedia.org/wiki/Datei:Example.svg]\n'
+ '[https://de.wikipedia.org/wiki/File:Example.svg Description]\n'
+ '[[https://de.wikipedia.org/wiki/Category:Example]]\n'
+ '[[https://de.wikipedia.org/wiki/Kategorie:Example
Description]]\n'
+ '[[https://de.wikipedia.org/wiki/File:Example.svg]]\n'
+ '[[https://de.wikipedia.org/wiki/Datei:Example.svg
Description]]\n'
+ ))
+ del self.cct.site._namespaces
def test_fixHtml(self):
"""Test fixHtml method."""
--
To view, visit
https://gerrit.wikimedia.org/r/361390
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If07182a6476498ad71ced821000bf91df2516cd8
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Hashar <hashar(a)free.fr>
Gerrit-Reviewer: JAn Dudík <jan.dudik(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Maven-release-user <maven-release-user(a)wikimedia.org>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>