Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1054503?usp=email )
Change subject: [fix] Ignore extension check in delinker.py scripts/delinker.py
......................................................................
[fix] Ignore extension check in delinker.py scripts/delinker.py
- add ignore_extension parameter to FilePage initializer to instantiate
a FilePage object without file extensions check
Bug: T352237
Change-Id: Ic7fe1750113047654c5660ff2de245a0a37279da
---
M pywikibot/page/_filepage.py
M scripts/delinker.py
2 files changed, 16 insertions(+), 9 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/page/_filepage.py b/pywikibot/page/_filepage.py
index eaed3dd..d91c181 100644
--- a/pywikibot/page/_filepage.py
+++ b/pywikibot/page/_filepage.py
@@ -38,25 +38,33 @@
Supports the same interface as Page except *ns*; some added methods.
"""
- def __init__(self, source, title: str = '') -> None:
+ def __init__(self, source, title: str = '', *,
+ ignore_extension: bool = False) -> None:
"""Initializer.
.. versionchanged:: 8.4
check for valid extensions.
+ .. versionchanged:: 9.3
+ *ignore_extension* parameter was added
:param source: the source of the page
:type source: pywikibot.page.BaseLink (or subclass),
pywikibot.page.Page (or subclass), or pywikibot.page.Site
:param title: normalized title of the page; required if source is a
Site, ignored otherwise
+ :param ignore_extension: prevent extension check
:raises ValueError: Either the title is not in the file
- namespace or does not have a valid extension.
+ namespace or does not have a valid extension and
+ *ignore_extension* was not set.
"""
self._file_revisions = {} # dictionary to cache File history.
super().__init__(source, title, 6)
if self.namespace() != 6:
raise ValueError(f"'{self.title()}' is not in the file namespace!")
+ if ignore_extension:
+ return
+
title = self.title(with_ns=False, with_section=False)
_, sep, extension = title.rpartition('.')
if not sep or extension.lower() not in self.site.file_extensions:
diff --git a/scripts/delinker.py b/scripts/delinker.py
index cb78714..13513ac 100755
--- a/scripts/delinker.py
+++ b/scripts/delinker.py
@@ -19,12 +19,11 @@
stops, the last timestamp is written to the settings file and
the next script call starts there if no `-since` is given.
-.. note:: This sample script is a
- :class:`ConfigParserBot <bot.ConfigParserBot>`. All
- settings can be made either by giving option with the command line or
- with a settings file which is scripts.ini by default. If you don't
- want the default values you can add any option you want to change to
- that settings file below the [delinker] section like.
+.. note:: This script is a :class:`ConfigParserBot <bot.ConfigParserBot>`.
+ All settings can be made either by giving option with the command
+ line or with a settings file which is scripts.ini by default. If you
+ don't want the default values you can add any option you want to
+ change to that settings file below the [delinker] section like.
.. versionadded:: 7.2
This script is completely rewriten from compat branch.
@@ -89,7 +88,7 @@
def init_page(self, item) -> pywikibot.page.FilePage:
"""Upcast logevent to FilePage and combine edit summary."""
self.summary_parameters = dict(item)
- return pywikibot.FilePage(self.site, item['title'])
+ return pywikibot.FilePage(item.page(), ignore_extension=True)
def skip_page(self, page) -> bool:
"""Skip pages which neither exists locally nor on shared repository."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1054503?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic7fe1750113047654c5660ff2de245a0a37279da
Gerrit-Change-Number: 1054503
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Aram <arambakr1620(a)gmail.com>
Gerrit-Reviewer: D3r1ck01 <dalangi-ctr(a)wikimedia.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1054341?usp=email )
Change subject: [cleanup]] deprecate BasePage.userName() and BasePage(isIpEdit)
......................................................................
[cleanup]] deprecate BasePage.userName() and BasePage(isIpEdit)
BasePage.userName() is too similar with User.username and can easily
replaced by latest_revision.user.
BasePage.isIpEdit() can easily be replaced by latest_revision.anon.
BasePage.editTime() is already deprecated and can be replaced by
latest_revision.timestamp.
Update scripts and tests
Change-Id: Ib0ec97de6b166668d92b0c2dd7bb29479d342a9b
---
M pywikibot/page/_basepage.py
M scripts/clean_sandbox.py
M scripts/noreferences.py
M tests/page_tests.py
4 files changed, 27 insertions(+), 8 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index 596bacc..aba8ab5 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -743,12 +743,24 @@
includecomments=includecomments)
return self._expanded_text
+ @deprecated('latest_revision.user', since='9.3.0')
def userName(self) -> str:
- """Return name or IP address of last user to edit page."""
+ """Return name or IP address of last user to edit page.
+
+ .. deprecated:: 9.3
+ Use :attr:`latest_revision.user<latest_revision>`
+ instead.
+ """
return self.latest_revision.user # type: ignore[attr-defined]
+ @deprecated('latest_revision.anon', since='9.3.0')
def isIpEdit(self) -> bool:
- """Return True if last editor was unregistered."""
+ """Return True if last editor was unregistered.
+
+ .. deprecated:: 9.3
+ Use :attr:`latest_revision.anon<latest_revision>`
+ instead.
+ """
return self.latest_revision.anon # type: ignore[attr-defined]
@cached
diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py
index 6b450cb..44fb69d 100755
--- a/scripts/clean_sandbox.py
+++ b/scripts/clean_sandbox.py
@@ -248,12 +248,14 @@
else:
translated_msg = i18n.twtranslate(
self.site, 'clean_sandbox-cleaned')
+
subst = 'subst:' in self.translated_content
pos = text.find(self.translated_content.strip())
+ latest_user = sandbox_page.latest_revision.user
if text.strip() == self.translated_content.strip():
pywikibot.info(
'The sandbox is still clean, no change necessary.')
- elif subst and sandbox_page.userName() == self.site.user():
+ elif subst and latest_user == self.site.user():
pywikibot.info(
'The sandbox might be clean, no change necessary.')
elif pos != 0 and not subst:
diff --git a/scripts/noreferences.py b/scripts/noreferences.py
index 5ad450b..a13a1dc 100755
--- a/scripts/noreferences.py
+++ b/scripts/noreferences.py
@@ -775,7 +775,7 @@
if super().skip_page(page):
return True
- if self.site.sitename == 'wikipedia:en' and page.isIpEdit():
+ if self.site.sitename == 'wikipedia:en' and page.latest_revision.anon:
pywikibot.warning(
f'Page {page} is edited by IP. Possible vandalized')
return True
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 0df6d1a..c4bcd8c 100755
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -464,15 +464,20 @@
# we only check that the returned objects are of correct type.
self.assertIsInstance(mainpage.get(), str)
self.assertIsInstance(mainpage.latest_revision_id, int)
- self.assertIsInstance(mainpage.userName(), str)
- self.assertIsInstance(mainpage.isIpEdit(), bool)
+
+ with suppress_warnings(
+ r'pywikibot\.page\._basepage.BasePage\.\w+ is deprecated since '
+ r'release [89]\.[03]\.0; use latest_revision\..+ instead\.',
+ FutureWarning):
+ self.assertIsInstance(mainpage.userName(), str)
+ self.assertIsInstance(mainpage.isIpEdit(), bool)
+ self.assertIsInstance(mainpage.editTime(), pywikibot.Timestamp)
+
self.assertIsInstance(mainpage.exists(), bool)
self.assertIsInstance(mainpage.isRedirectPage(), bool)
self.assertIsInstance(mainpage.isDisambig(), bool)
self.assertIsInstance(mainpage.has_permission(), bool)
self.assertIsInstance(mainpage.botMayEdit(), bool)
- self.assertIsInstance(mainpage.latest_revision.timestamp,
- pywikibot.Timestamp)
self.assertIsInstance(mainpage.permalink(), str)
def test_talk_page(self):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1054341?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib0ec97de6b166668d92b0c2dd7bb29479d342a9b
Gerrit-Change-Number: 1054341
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <dalangi-ctr(a)wikimedia.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/i18n/+/1055910?usp=email )
Change subject: Localisation updates from https://translatewiki.net.
......................................................................
Localisation updates from https://translatewiki.net.
Change-Id: I3c61808a840536dc819d965cfec7b6008f29bfb6
---
M redirect/it.json
1 file changed, 3 insertions(+), 3 deletions(-)
Approvals:
L10n-bot: Looks good to me, approved
jenkins-bot: Verified
diff --git a/redirect/it.json b/redirect/it.json
index 14b2d39..1864963 100644
--- a/redirect/it.json
+++ b/redirect/it.json
@@ -8,9 +8,9 @@
]
},
"redirect-broken-redirect-template": "{{Cancella subito|9}}",
- "redirect-fix-broken-moved": "Correggo reindirizzamento interrotto alla pagina spostata %(to)s",
- "redirect-fix-double": "Sistemo i redirect doppi a %(to)s",
- "redirect-fix-loop": "Correggo ciclo di reindirizzamento a %(to)s",
+ "redirect-fix-broken-moved": "Correggo reindirizzamento interrotto da %(from)s alla pagina spostata %(to)s",
+ "redirect-fix-double": "Sistemo i reindirizzamenti doppi da %(from)s a %(to)s",
+ "redirect-fix-loop": "Correggo ciclo di reindirizzamento da %(from)s a %(to)s",
"redirect-remove-broken": "Reindirizzamento a una pagina cancellata o inesistente",
"redirect-remove-loop": "La destinazione del reindirizzamento rimanda alla pagina di partenza"
}
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/i18n/+/1055910?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/i18n
Gerrit-Branch: master
Gerrit-Change-Id: I3c61808a840536dc819d965cfec7b6008f29bfb6
Gerrit-Change-Number: 1055910
Gerrit-PatchSet: 1
Gerrit-Owner: L10n-bot <l10n-bot(a)translatewiki.net>
Gerrit-Reviewer: L10n-bot <l10n-bot(a)translatewiki.net>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1055599?usp=email )
Change subject: [tests] skip connected page within unconnected_pages tests
......................................................................
[tests] skip connected page within unconnected_pages tests
The connection can be established in meantime.
Bug: T370596
Change-Id: I182dd058d36b87ecf5baed1e3721c5b7e6530482
---
M tests/pagegenerators_tests.py
M tests/site_generators_tests.py
2 files changed, 29 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 7efd78f..7d1aaa1 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -28,7 +28,7 @@
WikibaseItemFilterPageGenerator,
)
from pywikibot.tools import has_module
-from tests import join_data_path
+from tests import join_data_path, unittest_print
from tests.aspects import (
DefaultSiteTestCase,
DeprecationTestCase,
@@ -1699,10 +1699,21 @@
pattern = (fr'Page \[\[({site.sitename}:|{site.code}:)-1\]\]'
r" doesn't exist\.")
+ found = []
for page in pages:
- with self.subTest(page=page), self.assertRaisesRegex(
- NoPageError, pattern):
- page.data_item()
+ with self.subTest(page=page):
+ try:
+ page.data_item()
+ except NoPageError as e:
+ self.assertRegex(str(e), pattern)
+ else:
+ found.append(page)
+ if found:
+ unittest_print('connection found for ',
+ ', '.join(str(p) for p in found))
+
+ # assume that we have at least one unconnected page
+ self.assertLess(len(found), 3)
def test_unconnected_without_repo(self):
"""Test that it raises a ValueError on sites without repository."""
diff --git a/tests/site_generators_tests.py b/tests/site_generators_tests.py
index 86c98e0..75bd805 100755
--- a/tests/site_generators_tests.py
+++ b/tests/site_generators_tests.py
@@ -690,10 +690,21 @@
pattern = (fr'Page \[\[({site.sitename}:|{site.code}:)-1\]\]'
r" doesn't exist\.")
+ found = []
for page in pages:
- with self.subTest(page=page), self.assertRaisesRegex(
- NoPageError, pattern):
- page.data_item()
+ with self.subTest(page=page):
+ try:
+ page.data_item()
+ except NoPageError as e:
+ self.assertRegex(str(e), pattern)
+ else:
+ found.append(page)
+ if found:
+ unittest_print('connection found for ',
+ ', '.join(str(p) for p in found))
+
+ # assume that we have at least one unconnected page
+ self.assertLess(len(found), 3)
class TestSiteGeneratorsUsers(DefaultSiteTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1055599?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I182dd058d36b87ecf5baed1e3721c5b7e6530482
Gerrit-Change-Number: 1055599
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/i18n/+/1055597?usp=email )
Change subject: [IMPR] expand redirect messages to show the old redirect target
......................................................................
[IMPR] expand redirect messages to show the old redirect target
Bug: T254839
Change-Id: I27d8a3f4febe87ca89c88297da0a34c9815ca790
---
M redirect/en.json
M redirect/qqq.json
2 files changed, 6 insertions(+), 6 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/redirect/en.json b/redirect/en.json
index 9bf65ea..ace067d 100644
--- a/redirect/en.json
+++ b/redirect/en.json
@@ -5,9 +5,9 @@
]
},
"redirect-broken-redirect-template": "{{db-r1}}",
- "redirect-fix-broken-moved": "Fixing broken redirect to moved target page %(to)s",
- "redirect-fix-double": "Fixing double redirect to %(to)s",
- "redirect-fix-loop": "Fixing redirect loop to %(to)s",
+ "redirect-fix-broken-moved": "Fixing broken redirect from %(from)s to moved target page %(to)s",
+ "redirect-fix-double": "Fixing double redirect from %(from)s to %(to)s",
+ "redirect-fix-loop": "Fixing redirect loop from %(from)s to %(to)s",
"redirect-remove-broken": "Redirect to a deleted or non-existent page",
"redirect-remove-loop": "Redirect target forms a redirect loop"
}
diff --git a/redirect/qqq.json b/redirect/qqq.json
index ed793f7..4ced5b2 100644
--- a/redirect/qqq.json
+++ b/redirect/qqq.json
@@ -9,9 +9,9 @@
]
},
"redirect-broken-redirect-template": "{{doc-important|Only use your deletion template like <code><nowiki>{{delete}}</nowiki></code> which exist on your local project.}}\n\nNOTE TO TRANSLATOR: This should only be translated by someone on the Wikipedia of your language code. Thank you.\n\nTemplate for speedy deletion of broken redirect or redirect loops which the bot tags onto the redirect page. This message may contain additional informations like template parameters or reasons for the deletion request.\n\nNOTE: If this system message is not given for a language code, speedy deletion request by a bot is not supported on your site except there is a bot with sysop flag.",
- "redirect-fix-broken-moved": "Edit summary when the bot fixes a broken redirect to a moved page whose origin has been deleted.\nParameters:\n* <code>%(to)s</code>: the new redirect target, as a wiki link.",
- "redirect-fix-double": "Edit summary when the bot fixes double redirects. <code>%(to)s</code> displays the new redirect target as a wiki link.",
- "redirect-fix-loop": "Edit summary when the bot fixes redirect loops. <code>%(to)s</code> displays the new redirect target as a wiki link.",
+ "redirect-fix-broken-moved": "Edit summary when the bot fixes a broken redirect to a moved page whose origin has been deleted.\nParameters:\n* <code>%(from)s: the old redirect target\n* <code>%(to)s</code>: the new redirect target, as a wiki link.",
+ "redirect-fix-double": "Edit summary when the bot fixes double redirects.\nParameters:\n* <code>%(from)s: the old redirect target as wiki link\n* <code>%(to)s</code> displays the new redirect target as a wiki link.",
+ "redirect-fix-loop": "Edit summary when the bot fixes redirect loops.\nParameters:\n* <code>%(from)s: the old redirect target as wiki link\n* <code>%(to)s</code> displays the new redirect target as a wiki link.",
"redirect-remove-broken": "Edit summary when the bot tags a deleted or non-existent page for speedy deletion.",
"redirect-remove-loop": "Edit summary when the bot tags a redirect loop for speedy deletion."
}
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/i18n/+/1055597?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/i18n
Gerrit-Branch: master
Gerrit-Change-Id: I27d8a3f4febe87ca89c88297da0a34c9815ca790
Gerrit-Change-Number: 1055597
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1055576?usp=email )
Change subject: [tests] Skip TestShortLink tests if urlshortener-ratelimit was exceeded
......................................................................
[tests] Skip TestShortLink tests if urlshortener-ratelimit was exceeded
- add code parameter to utils.skipping decorator to specify the
APIError code to determine which specific APIError is to be skipped
- update documentations
Bug: T370596
Change-Id: Ie085e1f46522e1d090f63c2ee0517af8b9fd329e
---
M pywikibot/page/_basepage.py
M tests/page_tests.py
M tests/utils.py
3 files changed, 32 insertions(+), 13 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index 21181ba..e564b72 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -2303,18 +2303,18 @@
def create_short_link(self,
permalink: bool = False,
with_protocol: bool = True) -> str:
- """
- Return a shortened link that points to that page.
+ """Return a shortened link that points to that page.
- If shared_urlshortner_wiki is defined in family config, it'll use
- that site to create the link instead of the current wiki.
+ If shared_urlshortner_wiki is defined in family config, it'll
+ use that site to create the link instead of the current wiki.
- :param permalink: If true, the link will point to the actual revision
- of the page.
+ :param permalink: If true, the link will point to the actual
+ revision of the page.
:param with_protocol: If true, and if it's not already included,
- the link will have http(s) protocol prepended. On Wikimedia wikis
- the protocol is already present.
+ the link will have http(s) protocol prepended. On Wikimedia
+ wikis the protocol is already present.
:return: The reduced link.
+ :raises APIError: urlshortener-ratelimit exceeded
"""
wiki = self.site
if self.site.family.shared_urlshortner_wiki:
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 0df6d1a..7a19e16 100755
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -17,6 +17,7 @@
import pywikibot.page
from pywikibot import config
from pywikibot.exceptions import (
+ APIError,
Error,
InvalidTitleError,
IsNotRedirectPageError,
@@ -1267,12 +1268,16 @@
site = self.get_site()
p1 = pywikibot.Page(site, 'User:Framawiki/pwb_tests/shortlink')
- with self.subTest(parameters='defaulted'):
+
+ with self.subTest(parameters='defaulted'), \
+ skipping(APIError, code='urlshortener-ratelimit'):
self.assertEqual(p1.create_short_link(), 'https://w.wiki/3Cy')
- with self.subTest(with_protocol=True):
+ with self.subTest(with_protocol=True), \
+ skipping(APIError, code='urlshortener-ratelimit'):
self.assertEqual(p1.create_short_link(with_protocol=True),
'https://w.wiki/3Cy')
- with self.subTest(permalink=True):
+ with self.subTest(permalink=True), \
+ skipping(APIError, code='urlshortener-ratelimit'):
self.assertEqual(p1.create_short_link(permalink=True,
with_protocol=False),
'w.wiki/3Cz')
diff --git a/tests/utils.py b/tests/utils.py
index 053743f..341cb47 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -553,7 +553,9 @@
@contextmanager
-def skipping(*exceptions: BaseException, msg: str | None = None):
+def skipping(*exceptions: BaseException,
+ msg: str | None = None,
+ code: str | None = None):
"""Context manager to skip test on specified exceptions.
For example Eventstreams raises ``NotImplementedError`` if no
@@ -581,13 +583,25 @@
.. note:: The last sample uses Python 3.10 syntax.
.. versionadded:: 6.2
+ .. versionchanged:: 9.3
+ *code* parameter was added
- :param msg: Optional skipping reason
:param exceptions: Exceptions to let test skip
+ :param msg: Optional skipping reason
+ :param code: if *exceptions* is a single :exc:`APIError` you can
+ specify the :attr:`APIError.code` for the right match to be
+ skipped.
"""
try:
yield
except exceptions as e:
+ if code:
+ if len(exceptions) != 1 \
+ or not hasattr(e, 'code') \
+ or e.code != code:
+ raise
+ msg = e.info
+
if msg is None:
msg = e
raise unittest.SkipTest(msg)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1055576?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie085e1f46522e1d090f63c2ee0517af8b9fd329e
Gerrit-Change-Number: 1055576
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Meno25 has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1055536?usp=email )
Change subject: [fix] Use an asterisk as sort key in ar-wiki
......................................................................
[fix] Use an asterisk as sort key in ar-wiki
- add a new dict main_sortkey to cosmetic_changes to determine the sort
key for main articles
- don't the sort key from main_sortkey if the main article already has one
- raise a ValueError if main_sortkey is missconfigured
- update documentation
Bug: T370536
Change-Id: I2852baba6c9cebbcd209258388da85abc540d814
---
M pywikibot/cosmetic_changes.py
1 file changed, 43 insertions(+), 14 deletions(-)
Approvals:
Meno25: Verified; Looks good to me, approved
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 3000a0d..d4b4def 100644
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -64,7 +64,7 @@
from urllib.parse import urlparse, urlunparse
import pywikibot
-from pywikibot import exceptions, textlib
+from pywikibot import exceptions, i18n, textlib
from pywikibot.backports import Callable, Match, Pattern
from pywikibot.site import Namespace
from pywikibot.textlib import (
@@ -173,6 +173,20 @@
}
}
+main_sortkey = {
+ '_default': ' ',
+ 'ar': '*',
+}
+"""Sort key to specify the main article within a category.
+
+The sort key must be one of ``' '``, ``'!'``, ``'*'``, ``'#'`` and is
+used like a pipe link but sorts the page in front of the alphabetical
+order. This dict is used in
+:meth:`CosmeticChangesToolkit.standardizePageFooter`.
+
+.. versionadded:: 9.3
+"""
+
class CANCEL(IntEnum):
@@ -327,22 +341,27 @@
return text
def standardizePageFooter(self, text: str) -> str:
- """
- Standardize page footer.
+ """Standardize page footer.
- Makes sure that interwiki links and categories are put
- into the correct position and into the right order. This
- combines the old instances of standardizeInterwiki
- and standardizeCategories.
+ Makes sure that interwiki links and categories are put into the
+ correct position and into the right order.
- The page footer consists of the following parts
- in that sequence:
+ The page footer consists of the following parts in that sequence:
+
1. categories
2. additional information depending on the local site policy
3. interwiki
- """
- assert self.title is not None
+ .. versionchanged:: 9.3
+ uses :attr:`main_sortkey` to determine the sort key for the
+ main article within a category. If the main article has a
+ sort key already, it will not be changed any longer.
+
+ :param text: text to be modified
+ :return: the modified *text*
+ :raises ValueError: wrong value of sortkey in
+ :attr:`main_sortkey` for the given site
+ """
categories = []
interwiki_links = {}
@@ -373,11 +392,21 @@
# TODO: Sort categories in alphabetic order, e.g. using
# categories.sort()? (T100265)
# TODO: Get main categories from Wikidata?
- main = pywikibot.Category(self.site, 'Category:' + self.title,
- sort_key=' ')
+ main = pywikibot.Category(self.site, 'Category:' + self.title)
if main in categories:
- categories.pop(categories.index(main))
+ main = categories.pop(categories.index(main))
+ if main.sortKey:
+ sortkey = main.sortKey
+ else:
+ sortkey = i18n.translate(self.site, main_sortkey,
+ fallback=['_default'])
+ if sortkey not in [' ', '*', '!', '#']:
+ raise ValueError(
+ f'sort key for {self.site} is {sortkey} but must'
+ "be one of ' ', '*', '!', '#'")
+ main = pywikibot.Category(main, sort_key=sortkey)
categories.insert(0, main)
+
text = textlib.replaceCategoryLinks(text, categories,
site=self.site)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1055536?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I2852baba6c9cebbcd209258388da85abc540d814
Gerrit-Change-Number: 1055536
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Alaa <ala201041(a)hotmail.com>
Gerrit-Reviewer: Meno25 <meno25mail(a)gmail.com>
Gerrit-Reviewer: jenkins-bot