jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1055439?usp=email )
Change subject: [IMPR] Ignore SectionError in fixing_redirects.py script
......................................................................
[IMPR] Ignore SectionError in fixing_redirects.py script
- Add ignore_section parameter to APISite.getredirtarget and
getRedirectTarget method of BasePage and ItemPage; if not set, raise
SectionError if the section was not found on target page. The
ignore_section parameter is set by default.
- Use ignore_section=False within FixingRedirectBot.get_target() and
catch the SectionError to be ignored
Bug: T370295
Change-Id: I1d3f0a9bd8c14ddd087d2199e334be37f8988316
---
M pywikibot/page/_basepage.py
M pywikibot/page/_wikibase.py
M pywikibot/site/_apisite.py
M scripts/fixing_redirects.py
4 files changed, 75 insertions(+), 40 deletions(-)
Approvals:
Meno25: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index 596bacc..21181ba 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -1798,16 +1798,28 @@
return self._pageimage
- def getRedirectTarget(self):
- """
- Return a Page object for the target this Page redirects to.
+ def getRedirectTarget(self, *,
+ ignore_section: bool = True) -> pywikibot.Page:
+ """Return a Page object for the target this Page redirects to.
- If this page is not a redirect page, will raise an
- IsNotRedirectPageError. This method also can raise a NoPageError.
+ .. versionadded:: 9.3
+ *ignore_section* parameter
- :rtype: pywikibot.Page
+ .. seealso:: :meth:`Site.getredirtarget()
+ <pywikibot.site._apisite.APISite.getredirtarget>`
+
+ :param ignore_section: do not include section to the target even
+ the link has one
+
+ :raises CircularRedirectError: page is a circular redirect
+ :raises InterwikiRedirectPageError: the redirect target is on
+ another site
+ :raises IsNotRedirectPageError: page is not a redirect
+ :raises RuntimeError: no redirects found
+ :raises SectionError: the section is not found on target page
+ and *ignore_section* is not set
"""
- return self.site.getredirtarget(self)
+ return self.site.getredirtarget(self, ignore_section=ignore_section)
def moved_target(self):
"""
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index b00e5ce..951f89a 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -1170,14 +1170,31 @@
return data
- def getRedirectTarget(self):
- """Return the redirect target for this page."""
- target = super().getRedirectTarget()
+ def getRedirectTarget(self, *, ignore_section: bool = True):
+ """Return the redirect target for this page.
+
+ .. versionadded:: 9.3
+ *ignore_section* parameter
+
+ .. seealso:: :meth:`page.BasePage.getRedirectTarget`
+
+ :param ignore_section: do not include section to the target even
+ the link has one
+
+ :raises CircularRedirectError: page is a circular redirect
+ :raises InterwikiRedirectPageError: the redirect target is on
+ another site
+ :raises Error: target page has wrong content model
+ :raises IsNotRedirectPageError: page is not a redirect
+ :raises RuntimeError: no redirects found
+ :raises SectionError: the section is not found on target page
+ and *ignore_section* is not set
+ """
+ target = super().getRedirectTarget(ignore_section=ignore_section)
cmodel = target.content_model
if cmodel != 'wikibase-item':
- raise Error('{} has redirect target {} with content model {} '
- 'instead of wikibase-item'
- .format(self, target, cmodel))
+ raise Error(f'{self} has redirect target {target} with content '
+ f'model {cmodel} instead of wikibase-item')
return self.__class__(target.site, target.title(), target.namespace())
def iterlinks(self, family=None):
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index abca600..8f07e39 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -1594,20 +1594,28 @@
def getredirtarget(
self,
page: BasePage,
+ *,
+ ignore_section: bool = True
) -> pywikibot.page.Page:
- """
- Return page object for the redirect target of page.
+ """Return page object for the redirect target of page.
+
+ .. versionadded:: 9.3
+ *ignore_section* parameter
+
+ .. seealso:: :meth:`page.BasePage.getRedirectTarget`
:param page: page to search redirects for
+ :param ignore_section: do not include section to the target even
+ the link has one
:return: redirect target of page
- :raises pywikibot.exceptions.IsNotRedirectPageError: page is not a
- redirect
+ :raises CircularRedirectError: page is a circular redirect
+ :raises InterwikiRedirectPageError: the redirect target is on
+ another site
+ :raises IsNotRedirectPageError: page is not a redirect
:raises RuntimeError: no redirects found
- :raises pywikibot.exceptions.CircularRedirectError: page is a circular
- redirect
- :raises pywikibot.exceptions.InterwikiRedirectPageError: the redirect
- target is on another site
+ :raises SectionError: the section is not found on target page
+ and *ignore_section* is not set
"""
if not self.page_isredirect(page):
raise IsNotRedirectPageError(page)
@@ -1626,13 +1634,14 @@
raise RuntimeError(
f"getredirtarget: No 'redirects' found for page {title}.")
- redirmap = {item['from']: {'title': item['to'],
- 'section': '#'
- + item['tofragment']
- if 'tofragment' in item
- and item['tofragment']
- else ''}
- for item in result['query']['redirects']}
+ redirmap = {
+ item['from']: {
+ 'title': item['to'],
+ 'section': '#' + item['tofragment']
+ if 'tofragment' in item and item['tofragment'] else ''
+ }
+ for item in result['query']['redirects']
+ }
# Normalize title
for item in result['query'].get('normalized', []):
@@ -1687,6 +1696,11 @@
target = pywikibot.FilePage(target)
elif ns == Namespace.CATEGORY:
target = pywikibot.Category(target)
+
+ if not ignore_section:
+ # get the content; this raises SectionError if section is not found
+ target.text
+
page._redirtarget = target
return page._redirtarget
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index 4774b1a..55fc3f8 100755
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -41,8 +41,9 @@
InvalidPageError,
InvalidTitleError,
NoMoveTargetError,
+ SectionError,
)
-from pywikibot.textlib import does_text_contain_section, isDisabled
+from pywikibot.textlib import isDisabled
from pywikibot.tools import first_lower
from pywikibot.tools import first_upper as firstcap
@@ -169,22 +170,13 @@
target = page.moved_target()
elif page.isRedirectPage():
try:
- target = page.getRedirectTarget()
+ target = page.getRedirectTarget(ignore_section=False)
except (CircularRedirectError,
InvalidTitleError,
InterwikiRedirectPageError):
pass
- except RuntimeError as e:
+ except (RuntimeError, SectionError) as e:
pywikibot.error(e)
- else:
- section = target.section()
- if section and not does_text_contain_section(target.text,
- section):
- pywikibot.warning(
- f'Section #{section} not found on page '
- f'{target.title(as_link=True, with_section=False)}'
- )
- target = None
if target is not None \
and target.namespace() in [2, 3] and page.namespace() not in [2, 3]:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1055439?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: I1d3f0a9bd8c14ddd087d2199e334be37f8988316
Gerrit-Change-Number: 1055439
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <dalangi-ctr(a)wikimedia.org>
Gerrit-Reviewer: Meno25 <meno25mail(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1053359?usp=email )
Change subject: [IMPR] use Page.text instead of Page.get() to get the page content.
......................................................................
[IMPR] use Page.text instead of Page.get() to get the page content.
Page.text already gives an emtpy string if the page does not exists.
Change-Id: I4c2848cae22df5304f937ce438e9887171e92e16
---
M pywikibot/page/_page.py
1 file changed, 8 insertions(+), 14 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_page.py b/pywikibot/page/_page.py
index 2154ea9..991a985 100644
--- a/pywikibot/page/_page.py
+++ b/pywikibot/page/_page.py
@@ -125,21 +125,20 @@
@deprecated_args(botflag='bot') # since 9.3.0
def set_redirect_target(
self,
- target_page,
+ target_page: pywikibot.Page | str,
create: bool = False,
force: bool = False,
keep_section: bool = False,
save: bool = True,
**kwargs
):
- """
- Change the page's text to point to the redirect page.
+ """Change the page's text to point to the redirect page.
.. versionchanged:: 9.3
*botflag* keyword parameter was renamed to *bot*.
- :param target_page: target of the redirect, this argument is required.
- :type target_page: pywikibot.Page or string
+ :param target_page: target of the redirect, this argument is
+ required.
:param create: if true, it creates the redirect even if the page
doesn't exist.
:param force: if true, it set the redirect target even the page
@@ -147,8 +146,8 @@
:param keep_section: if the old redirect links to a section
and the new one doesn't it uses the old redirect's section.
:param save: if true, it saves the page immediately.
- :param kwargs: Arguments which are used for saving the page directly
- afterwards, like 'summary' for edit summary.
+ :param kwargs: Arguments which are used for saving the page
+ directly afterwards, like *summary* for edit summary.
"""
if isinstance(target_page, str):
target_page = pywikibot.Page(self.site, target_page)
@@ -161,13 +160,8 @@
if self.exists() and not self.isRedirectPage() and not force:
raise IsNotRedirectPageError(self)
- redirect_regex = self.site.redirect_regex
- if self.exists():
- old_text = self.get(get_redirect=True)
- else:
- old_text = ''
-
- result = redirect_regex.search(old_text)
+ old_text = self.text
+ result = self.site.redirect_regex.search(old_text)
if result:
oldlink = result[1]
if (keep_section and '#' in oldlink
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1053359?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: I4c2848cae22df5304f937ce438e9887171e92e16
Gerrit-Change-Number: 1053359
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: AnotherLadsgroup <ladsgroup(a)gmail.com>
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1054011?usp=email )
Change subject: [9.2.1] Add support for aewikimedia wiki and publish Pywikibot 9.2.1
......................................................................
[9.2.1] Add support for aewikimedia wiki and publish Pywikibot 9.2.1
Bug: T362529
Change-Id: I487954d81cf38e3b53b2de6ac5d5b01417681566
---
M HISTORY.rst
M ROADMAP.rst
M pywikibot/__metadata__.py
M pywikibot/families/wikimediachapter_family.py
4 files changed, 38 insertions(+), 29 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/HISTORY.rst b/HISTORY.rst
index 1a23884..a6167ed 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,13 +1,44 @@
Release History
===============
+9.2.0
+-----
+*22 June 2024*
+
+* Add support for ``btmwiki`` to Pywikibot (:phab:`T368069`)
+* Include image repository extensions in :attr:`site.APISite.file_extensions
+ <pywikibot.site._apisite.APISite.file_extensions>`
+* Ignore :exc:`ValueError` durig upcast of :class:`FilePage<pywikibot.page.FilePage>` due to invalid file extension
+ (:phab:`T367777`)
+* Add :func:`pagegenerators.SupersetPageGenerator` pagegenerator (:phab:`T367684`)
+* No longer wait in :meth:`data.api.Request._http_request` for ``ImportError`` and ``NameError``
+* Replace ``requests.utils.urlparse`` with ``urllib.parse.urlparse`` in
+ :func:`comms.http.get_authentication` (:phab:`T367649`)
+* Show an appropiate message if ``requests_oauthlib`` package is required but missing (:phab:`T353387`)
+* Retry ``DBUnexpectedError`` in :meth:`data.api.Request._internal_api_error` (:phab:`T367383`)
+* Duplicated entries found in :mod:`pywikibot` were removed
+* Pass ``None`` instead of an empty string as *expiry* argument in
+ :meth:`site.APISite.protect()<pywikibot.site._apisite.APISite.protect>` (:phab:`T367176`)
+* Fix keyword argument in :meth:`Page.undelete()<page.BasePage.undelete>` when
+ calling :meth:`site.APISite.undelete()<pywikibot.site._apisite.APISite.undelete>` (:phab:`T367037`)
+* Check whether :attr:`BaseBot.generator<bot.BaseBot.generator>` is None in :meth:`run()<bot.BaseBot.run>` method
+* Add *namespaces* parameter to :meth:`Page.templates()<page.BasePage.templates>` and
+ :meth:`Page.itertemplates()<page.BasePage.itertemplates>` and require keyword arguments;
+ only use TEMPLATE namespace for meth:`Page.isDisambig()<page.BasePage.isDisambig>` (:phab:`T365199`)
+* Drop pheetools support for :mod:`proofreadpage` which is no longer available upstreams (:phab:`T366036`)
+* Raise :exc:`exceptions.SectionError` if a section does not exists on a page (:phab:`T107141`)
+* Retry api request on ServerError (:phab:`T364275`, :phab:`T364393`)
+* i18n updates
+
+
9.1.3
-----
-*28.05.2024*
+*28 May 2024*
* Add support for dtpwiki (:phab:`T365232`)
* i18n updates
+
9.1.2
-----
*03 May 2024*
diff --git a/ROADMAP.rst b/ROADMAP.rst
index b956e38..1ae85ee 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,29 +1,7 @@
Current Release Changes
=======================
-* Add support for ``btmwiki`` to Pywikibot (:phab:`T368069`)
-* Include image repository extensions in :attr:`site.APISite.file_extensions
- <pywikibot.site._apisite.APISite.file_extensions>`
-* Ignore :exc:`ValueError` durig upcast of :class:`FilePage<pywikibot.page.FilePage>` due to invalid file extension
- (:phab:`T367777`)
-* Add :func:`pagegenerators.SupersetPageGenerator` pagegenerator (:phab:`T367684`)
-* No longer wait in :meth:`data.api.Request._http_request` for ``ImportError`` and ``NameError``
-* Replace ``requests.utils.urlparse`` with ``urllib.parse.urlparse`` in
- :func:`comms.http.get_authentication` (:phab:`T367649`)
-* Show an appropiate message if ``requests_oauthlib`` package is required but missing (:phab:`T353387`)
-* Retry ``DBUnexpectedError`` in :meth:`data.api.Request._internal_api_error` (:phab:`T367383`)
-* Duplicated entries found in :mod:`pywikibot` were removed
-* Pass ``None`` instead of an empty string as *expiry* argument in
- :meth:`site.APISite.protect()<pywikibot.site._apisite.APISite.protect>` (:phab:`T367176`)
-* Fix keyword argument in :meth:`Page.undelete()<page.BasePage.undelete>` when
- calling :meth:`site.APISite.undelete()<pywikibot.site._apisite.APISite.undelete>` (:phab:`T367037`)
-* Check whether :attr:`BaseBot.generator<bot.BaseBot.generator>` is None in :meth:`run()<bot.BaseBot.run>` method
-* Add *namespaces* parameter to :meth:`Page.templates()<page.BasePage.templates>` and
- :meth:`Page.itertemplates()<page.BasePage.itertemplates>` and require keyword arguments;
- only use TEMPLATE namespace for meth:`Page.isDisambig()<page.BasePage.isDisambig>` (:phab:`T365199`)
-* Drop pheetools support for :mod:`proofreadpage` which is no longer available upstreams (:phab:`T366036`)
-* Raise :exc:`exceptions.SectionError` if a section does not exists on a page (:phab:`T107141`)
-* Retry api request on ServerError (:phab:`T364275`, :phab:`T364393`)
+* Add support for ``aewikimedia`` to Pywikibot (:phab:`T362529`)
* i18n updates
Current Deprecations
diff --git a/pywikibot/__metadata__.py b/pywikibot/__metadata__.py
index be801c8..577d0fa 100644
--- a/pywikibot/__metadata__.py
+++ b/pywikibot/__metadata__.py
@@ -12,6 +12,6 @@
from time import strftime
-__version__ = '9.2.0'
+__version__ = '9.2.1'
__url__ = 'https://www.mediawiki.org/wiki/Manual:Pywikibot'
__copyright__ = f'2003-{strftime("%Y")}, Pywikibot team'
diff --git a/pywikibot/families/wikimediachapter_family.py b/pywikibot/families/wikimediachapter_family.py
index e217010..e595a95 100644
--- a/pywikibot/families/wikimediachapter_family.py
+++ b/pywikibot/families/wikimediachapter_family.py
@@ -21,8 +21,8 @@
closed_wikis = ['cn', 'nz', 'pa-us']
codes = {
- 'am', 'ar', 'az', 'bd', 'be', 'br', 'ca', 'co', 'dk', 'ec', 'ee', 'fi',
- 'ge', 'gr', 'hi', 'id', 'id-internal', 'il', 'mai', 'mk', 'mx', 'ng',
- 'nl', 'no', 'nyc', 'pl', 'pt', 'punjabi', 'romd', 'rs', 'ru', 'se',
- 'tr', 'ua', 'uk', 've', 'wb',
+ 'ae', 'am', 'ar', 'az', 'bd', 'be', 'br', 'ca', 'co', 'dk', 'ec', 'ee',
+ 'fi', 'ge', 'gr', 'hi', 'id', 'id-internal', 'il', 'mai', 'mk', 'mx',
+ 'ng', 'nl', 'no', 'nyc', 'pl', 'pt', 'punjabi', 'romd', 'rs', 'ru',
+ 'se', 'tr', 'ua', 'uk', 've', 'wb',
}
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1054011?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: stable
Gerrit-Change-Id: I487954d81cf38e3b53b2de6ac5d5b01417681566
Gerrit-Change-Number: 1054011
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Meno25 <meno25mail(a)gmail.com>