jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] Handle abusefilter-{disallow,warning} codes

- abusefilter-disallow: raise AbuseFilterDisallowedError
- abusefilter-warning: warn and retry

Bug: T85656
Change-Id: Ic2367f7c29540b35b86c700e3da9a2a7eb2c3d47
---
M pywikibot/exceptions.py
M pywikibot/site/_apisite.py
2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index cc9bb9f..e57fc21 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -35,6 +35,7 @@
| | +-- OtherPageSaveError
| | +-- SpamblacklistError
| | +-- TitleblacklistError
+ | | +-- AbuseFilterDisallowedError
| +-- UnsupportedPageError
+-- SectionError
+-- ServerError
@@ -106,6 +107,7 @@

PageSaveRelatedError: page exceptions within the save operation on a Page

+ - AbuseFilterDisallowedError: AbuseFilter disallowed
- SpamblacklistError: MediaWiki spam filter detected a blacklisted URL
- TitleblacklistError: MediaWiki detected a blacklisted page title
- OtherPageSaveError: misc. other save related exception.
@@ -534,6 +536,20 @@
'to the source article')


+class AbuseFilterDisallowedError(PageSaveRelatedError):
+
+ """Page save failed because the AbuseFilter disallowed it."""
+
+ message = ('Edit to page %(title)s disallowed by the AbuseFilter.\n'
+ '%(info)s\n%(warning)s')
+
+ def __init__(self, page, info, warning):
+ """Initializer."""
+ self.info = info
+ self.warning = warning
+ super().__init__(page)
+
+
class SpamblacklistError(PageSaveRelatedError):

"""Page save failed because MediaWiki detected a blacklisted spam URL."""
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 5f4a5c9..d5aa452 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -22,6 +22,7 @@
from pywikibot.comms.http import get_authentication
from pywikibot.data import api
from pywikibot.exceptions import (
+ AbuseFilterDisallowedError,
APIError,
ArticleExistsConflictError,
CaptchaError,
@@ -1525,6 +1526,7 @@
'cascadeprotected': CascadeLockedPageError,
'titleblacklist-forbidden': TitleblacklistError,
'spamblacklist': SpamblacklistError,
+ 'abusefilter-disallowed': AbuseFilterDisallowedError,
}
_ep_text_overrides = {'appendtext', 'prependtext', 'undo'}

@@ -1640,6 +1642,12 @@
"editpage: received '%s' even though bot is "
'logged in' % err.code,
_logger)
+ if err.code == 'abusefilter-warning':
+ pywikibot.warning('{info}\n{warning}\nRetrying.'
+ .format(info=err.info,
+ warning=err.other['warning'],
+ ))
+ continue
if err.code in self._ep_errors:
exception = self._ep_errors[err.code]
if isinstance(exception, str):
@@ -1650,6 +1658,12 @@
'info': err.info
}
raise Error(exception % errdata)
+ if issubclass(exception, AbuseFilterDisallowedError):
+ errdata = {
+ 'info': err.info,
+ 'warning': err.other['warning'],
+ }
+ raise exception(page, **errdata) from None
if issubclass(exception, SpamblacklistError):
urls = ', '.join(err.other[err.code]['matches'])
raise exception(page, url=urls) from None

To view, visit change 680768. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic2367f7c29540b35b86c700e3da9a2a7eb2c3d47
Gerrit-Change-Number: 680768
Gerrit-PatchSet: 4
Gerrit-Owner: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: DannyS712 <dannys712.wiki@gmail.com>
Gerrit-MessageType: merged