jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1019070?usp=email )
Change subject: [doc] Update ROADMAP.rst, CHANGELOG.rst and AUTHORS.rst
......................................................................
[doc] Update ROADMAP.rst, CHANGELOG.rst and AUTHORS.rst
Change-Id: I51c37a19ea24d979ca1c997766719a87495d8c43
---
M AUTHORS.rst
M ROADMAP.rst
M scripts/CHANGELOG.rst
3 files changed, 26 insertions(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 1fad649..fa3654e 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -93,6 +93,7 @@
Egon
Enag2000
Eranroz
+ Eric Pien
Erwin
Evrifaessa
diff --git a/ROADMAP.rst b/ROADMAP.rst
index 850f0a3..e0cecfc 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,6 +1,7 @@
Current release
---------------
+* Skip process that requires login to logout (:phab:`T326614`)
* File title of :class:`specialbots.UploadRobot` must have a valid file extension (:phab:`T345786`)
* Add a :attr:`post_processor<specialbots.UploadRobot.post_processor>` attribute to :class:`specialbots.UploadRobot`
which can be called after each upload (:phab:`T359766`)
@@ -9,6 +10,7 @@
* Show upload count with :class:`specialbots.UploadRobot`
* Use the same ``iiprop`` properties in :class:`data.api.PageGenerator` as in
:meth:`APISite.loadimageinfo<pywikibot.site._apisite.APISite.loadimageinfo>` (:phab:`T360093`)
+* i18n updates
Deprecations
------------
diff --git a/scripts/CHANGELOG.rst b/scripts/CHANGELOG.rst
index 975b13a..98733d3 100644
--- a/scripts/CHANGELOG.rst
+++ b/scripts/CHANGELOG.rst
@@ -1,6 +1,20 @@
Scripts Changelog
=================
+9.1.0
+-----
+
+colors
+^^^^^^
+
+* Fix TypeError with :func:`backports.batched` (:phab:`T362035`)
+
+noreferences
+^^^^^^^^^^^^
+
+* Show an error message and leave if script is not localized (:phab:`T362103`)
+
+
9.0.0
-----
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1019070?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I51c37a19ea24d979ca1c997766719a87495d8c43
Gerrit-Change-Number: 1019070
Gerrit-PatchSet: 1
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
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1018821?usp=email )
Change subject: [FIX] Skip process that requires login to logout
......................................................................
[FIX] Skip process that requires login to logout
Getting self.tokens['crsf'] triggers a login when not already logged in.
Checks LoginStatus and only continue the steps if still logged in.
Bug: T326614
Change-Id: I50e49e9ea8dbf2ef29c7606b4cd318ac02f8c33c
---
M pywikibot/site/_apisite.py
1 file changed, 19 insertions(+), 4 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 340d82e..4924b60 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -471,10 +471,12 @@
if self.is_oauth_token_available():
pywikibot.warning('Using OAuth suppresses logout function')
- req_params = {'action': 'logout', 'token': self.tokens['csrf']}
- uirequest = self.simple_request(**req_params)
- uirequest.submit()
- self._loginstatus = login.LoginStatus.NOT_LOGGED_IN
+ # check if already logged out to avoid requiring logging in
+ if not self._loginstatus == login.LoginStatus.NOT_LOGGED_IN:
+ req_params = {'action': 'logout', 'token': self.tokens['csrf']}
+ uirequest = self.simple_request(**req_params)
+ uirequest.submit()
+ self._loginstatus = login.LoginStatus.NOT_LOGGED_IN
# Reset tokens and user properties
del self.userinfo
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1018821?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I50e49e9ea8dbf2ef29c7606b4cd318ac02f8c33c
Gerrit-Change-Number: 1018821
Gerrit-PatchSet: 1
Gerrit-Owner: Ericpien <eric.hs.pien(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1018643?usp=email )
Change subject: [IMPR] Show an error message and leave if script is not localized
......................................................................
[IMPR] Show an error message and leave if script is not localized
If this script is not localized for a given site
- raise TranslationError in createReferenceSection()
- catch TranslationError in treat_page, print the error message and
close the generator
Also ignore if referencesSections or placeBeforeSections is missing and
place the references section before interwiki links, categories, and
bottom templates in such case.
Bug: T362103
Change-Id: I308be486356ec86d8475a3b841e8c0f219643d40
---
M scripts/noreferences.py
1 file changed, 58 insertions(+), 18 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/scripts/noreferences.py b/scripts/noreferences.py
index a0cc0e8..e1313da 100755
--- a/scripts/noreferences.py
+++ b/scripts/noreferences.py
@@ -29,7 +29,7 @@
a list of affected articles
"""
#
-# (C) Pywikibot team, 2007-2023
+# (C) Pywikibot team, 2007-2024
#
# Distributed under the terms of the MIT license.
#
@@ -37,11 +37,12 @@
import re
from functools import partial
+from pathlib import Path
import pywikibot
from pywikibot import i18n, pagegenerators, textlib
from pywikibot.bot import AutomaticTWSummaryBot, ExistingPageBot, SingleSiteBot
-from pywikibot.exceptions import LockedPageError
+from pywikibot.exceptions import LockedPageError, TranslationError
from pywikibot.pagegenerators import XMLDumpPageGenerator
@@ -611,7 +612,7 @@
# Is there an existing section where we can add the references tag?
# Set the edit summary key for this case
self.summary_key = 'noreferences-add-tag'
- for section in i18n.translate(self.site, referencesSections):
+ for section in i18n.translate(self.site, referencesSections) or []:
sectionR = re.compile(fr'\r?\n=+ *{section} *=+ *\r?\n')
index = 0
while index < len(oldText):
@@ -637,7 +638,7 @@
break
# Create a new section for the references tag
- for section in i18n.translate(self.site, placeBeforeSections):
+ for section in i18n.translate(self.site, placeBeforeSections) or []:
# Find out where to place the new section
sectionR = re.compile(r'\r?\n(?P<ident>=+) *{} *(?P=ident) *\r?\n'
.format(section))
@@ -699,24 +700,34 @@
index = len(tmpText)
return self.createReferenceSection(oldText, index)
- def createReferenceSection(self, oldText, index, ident: str = '==') -> str:
+ def createReferenceSection(self,
+ oldText: str,
+ index: int,
+ ident: str = '==') -> str:
"""Create a reference section and insert it into the given text.
+ .. versionchanged:: 9.1
+ raise :exc:`exceptions.TranslationError` if script is not
+ localized for the current site.
+
:param oldText: page text that is going to be be amended
- :type oldText: str
- :param index: the index of oldText where the reference section should
- be inserted at
- :type index: int
- :param ident: symbols to be inserted before and after reference section
- title
+ :param index: the index of oldText where the reference section
+ should be inserted at
+ :param ident: symbols to be inserted before and after reference
+ section title
:return: the amended page text with reference section added
+ :raises TranslationError: script is not localized for the
+ current site
"""
+ title = i18n.translate(self.site, referencesSections)
if self.site.code in noTitleRequired:
ref_section = f'\n\n{self.referencesText}\n'
+ elif title:
+ ref_section = (f'\n\n{ident} {title[0]} {ident}\n'
+ f'{self.referencesText}\n')
else:
- ref_section = '\n\n{ident} {title} {ident}\n{text}\n'.format(
- title=i18n.translate(self.site, referencesSections)[0],
- ident=ident, text=self.referencesText)
+ raise TranslationError(f'{Path(__file__).name} script is not '
+ f'localized for {self.site}')
return oldText[:index].rstrip() + ref_section + oldText[index:]
def skip_page(self, page):
@@ -726,14 +737,18 @@
if self.site.sitename == 'wikipedia:en' and page.isIpEdit():
pywikibot.warning(
- 'Page {} is edited by IP. Possible vandalized'
- .format(page.title(as_link=True)))
+ f'Page {page} is edited by IP. Possible vandalized')
return True
return False
def treat_page(self) -> None:
- """Run the bot."""
+ """Run the bot.
+
+ .. versionchanged:: 9.1
+ print error message and close :attr:`bot.BaseBot.generator`
+ if :exc:`exceptions.TranslationError` was raised.
+ """
page = self.current_page
try:
text = page.text
@@ -742,7 +757,13 @@
return
if self.lacksReferences(text):
- self.put_current(self.addReferences(text))
+ try:
+ newtext = self.addReferences(text)
+ except TranslationError as e:
+ pywikibot.error(e)
+ self.generator.close()
+ else:
+ self.put_current(newtext)
def main(*args: str) -> None:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1018643?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I308be486356ec86d8475a3b841e8c0f219643d40
Gerrit-Change-Number: 1018643
Gerrit-PatchSet: 4
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
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/904743?usp=email )
Change subject: [IMPR] Improve api._generators and avoid similar code
......................................................................
[IMPR] Improve api._generators and avoid similar code
Change-Id: I5959bfe9686d918774529b98d45a3ac084848366
---
M pywikibot/data/api/_generators.py
1 file changed, 39 insertions(+), 34 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api/_generators.py b/pywikibot/data/api/_generators.py
index e32ed2e..de6f011 100644
--- a/pywikibot/data/api/_generators.py
+++ b/pywikibot/data/api/_generators.py
@@ -19,7 +19,7 @@
import pywikibot
from pywikibot import config
-from pywikibot.backports import Callable
+from pywikibot.backports import Callable, Iterable
from pywikibot.exceptions import Error, InvalidTitleError, UnsupportedPageError
from pywikibot.site import Namespace
from pywikibot.tools import deprecated
@@ -963,25 +963,42 @@
page._coords = coords
-def update_page(page, pagedict: dict, props=None):
- """Update attributes of Page object page, based on query data in pagedict.
+def update_page(page: pywikibot.Page,
+ pagedict: dict[str, Any],
+ props: Iterable[str] | None = None) -> None:
+ """
+ Update attributes of Page object *page*, based on query data in *pagedict*.
:param page: object to be updated
- :type page: pywikibot.page.Page
- :param pagedict: the contents of a "page" element of a query response
- :param props: the property names which resulted in pagedict. If a missing
- value in pagedict can indicate both 'false' and 'not present' the
- property which would make the value present must be in the props
- parameter.
- :type props: iterable of string
- :raises pywikibot.exceptions.InvalidTitleError: Page title is invalid
- :raises pywikibot.exceptions.UnsupportedPageError: Page with namespace < 0
- is not supported yet
+ :param pagedict: the contents of a *page* element of a query
+ response
+ :param props: the property names which resulted in *pagedict*. If a
+ missing value in *pagedict* can indicate both 'false' and
+ 'not present' the property which would make the value present
+ must be in the *props* parameter.
+ :raises InvalidTitleError: Page title is invalid
+ :raises UnsupportedPageError: Page with namespace < 0 is not
+ supported yet
"""
_update_pageid(page, pagedict)
_update_contentmodel(page, pagedict)
props = props or []
+
+ # test for pagedict content only and call updater function
+ for element in ('coordinates', 'revisions'):
+ if element in pagedict:
+ updater = globals()['_update_' + element]
+ updater(page, pagedict[element])
+
+ # test for pagedict and props contents, call updater or set attribute
+ for element in ('categories', 'langlinks', 'templates'):
+ if element in pagedict:
+ updater = globals()['_update_' + element]
+ updater(page, pagedict[element])
+ elif element in props:
+ setattr(page, '_' + element, set())
+
if 'info' in props:
page._isredir = 'redirect' in pagedict
@@ -991,9 +1008,6 @@
if 'protection' in pagedict:
_update_protection(page, pagedict)
- if 'revisions' in pagedict:
- _update_revisions(page, pagedict['revisions'])
-
if 'lastrevid' in pagedict:
page.latest_revision_id = pagedict['lastrevid']
@@ -1006,24 +1020,6 @@
if 'categoryinfo' in pagedict:
page._catinfo = pagedict['categoryinfo']
- if 'templates' in pagedict:
- _update_templates(page, pagedict['templates'])
- elif 'templates' in props:
- page._templates = set()
-
- if 'categories' in pagedict:
- _update_categories(page, pagedict['categories'])
- elif 'categories' in props:
- page._categories = set()
-
- if 'langlinks' in pagedict:
- _update_langlinks(page, pagedict['langlinks'])
- elif 'langlinks' in props:
- page._langlinks = set()
-
- if 'coordinates' in pagedict:
- _update_coordinates(page, pagedict['coordinates'])
-
if 'pageimage' in pagedict:
page._pageimage = pywikibot.FilePage(page.site, pagedict['pageimage'])
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/904743?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5959bfe9686d918774529b98d45a3ac084848366
Gerrit-Change-Number: 904743
Gerrit-PatchSet: 12
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged