jenkins-bot merged this change.
Add TitleblacklistError for API error 'titleblacklist-forbidden'
It is made a subclass of PageSaveRelatedError so scripts like replace.py
will not crash upon this error.
Bug: T185825
Change-Id: I47917ff9387d3e416f43c0666f07786cb4455634
---
M pywikibot/__init__.py
M pywikibot/exceptions.py
M pywikibot/site.py
M tests/edit_failure_tests.py
4 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 508f8ba..3350be8 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -57,8 +57,9 @@
LockedPage, CascadeLockedPage, LockedNoPage, NoCreateError,
EditConflict, PageDeletedConflict, PageCreatedConflict,
ServerError, FatalServerError, Server504Error,
- CaptchaError, SpamfilterError, CircularRedirect, InterwikiRedirectPage,
- WikiBaseError, CoordinateGlobeUnknownException,
+ CaptchaError, SpamfilterError, TitleblacklistError,
+ CircularRedirect, InterwikiRedirectPage, WikiBaseError,
+ CoordinateGlobeUnknownException,
DeprecatedPageNotFoundError as _DeprecatedPageNotFoundError,
_EmailUserError,
)
@@ -113,8 +114,8 @@
'EditConflict', 'PageDeletedConflict', 'PageCreatedConflict',
'UploadWarning',
'ServerError', 'FatalServerError', 'Server504Error',
- 'CaptchaError', 'SpamfilterError', 'CircularRedirect',
- 'InterwikiRedirectPage',
+ 'CaptchaError', 'SpamfilterError', 'TitleblacklistError',
+ 'CircularRedirect', 'InterwikiRedirectPage',
'WikiBaseError', 'CoordinateGlobeUnknownException',
'QuitKeyboardInterrupt',
)
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 2e456fb..864d44d 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -40,6 +40,7 @@
(alias: PageNotSaved).
- SpamfilterError: MediaWiki spam filter detected a blacklisted URL
+ - TitleblacklistError: MediaWiki detected a blacklisted page title
- OtherPageSaveError: misc. other save related exception.
- LockedPage: Page is locked
- LockedNoPage: Title is locked against creation
@@ -459,6 +460,15 @@
super(SpamfilterError, self).__init__(page)
+class TitleblacklistError(PageSaveRelatedError):
+
+ """Page save failed because MediaWiki detected a blacklisted page title."""
+
+ message = 'Page %s is title-blacklisted.'
+
+ pass
+
+
class ServerError(Error): # noqa
"""Got unexpected server response"""
diff --git a/pywikibot/site.py b/pywikibot/site.py
index c174f1d..b57f26f 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -55,6 +55,7 @@
FamilyMaintenanceWarning,
NoUsername,
SpamfilterError,
+ TitleblacklistError,
NoCreateError,
UserBlocked,
EntityTypeUnknownException,
@@ -5042,6 +5043,7 @@
"protectedpage": LockedPage,
"protectedtitle": LockedNoPage,
"cascadeprotected": CascadeLockedPage,
+ 'titleblacklist-forbidden': TitleblacklistError,
}
_ep_text_overrides = set(['appendtext', 'prependtext', 'undo'])
diff --git a/tests/edit_failure_tests.py b/tests/edit_failure_tests.py
index 237fa57..68bda27 100644
--- a/tests/edit_failure_tests.py
+++ b/tests/edit_failure_tests.py
@@ -20,6 +20,7 @@
NoPage,
LockedPage,
SpamfilterError,
+ TitleblacklistError,
OtherPageSaveError,
NoCreateError,
PageCreatedConflict,
@@ -51,6 +52,11 @@
page.text = 'http://badsite.com'
self.assertRaisesRegex(SpamfilterError, 'badsite.com', page.save)
+ def test_titleblacklist(self):
+ """Test that title blacklist raise the appropriate exception."""
+ page = pywikibot.Page(self.site, 'User:UpsandDowns1234/Blacklisttest')
+ self.assertRaises(TitleblacklistError, page.save)
+
def test_nobots(self):
"""Test that {{nobots}} raise the appropriate exception."""
page = pywikibot.Page(self.site, 'User:John Vandenberg/nobots')
To view, visit change 406777. To unsubscribe, visit settings.