jenkins-bot has submitted this change and it was merged.
Change subject: Implement User.block() function
......................................................................
Implement User.block() function
Change-Id: Ic6d1bb17b82698869b63e8223cc2f5d24c0b7c27
---
M pywikibot/page.py
M pywikibot/site.py
2 files changed, 51 insertions(+), 0 deletions(-)
Approvals:
Ladsgroup: Verified; Looks good to me, approved
Merlijn van Deen: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 215b643..5f30436 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2178,6 +2178,34 @@
return True
return False
+ def block(self, expiry, reason, anononly=True, nocreate=True, autoblock=True,
+ noemail=False, reblock=False):
+ """
+ Blocks a user
+ @param expiry: When the block should expire
+ @type expiry: pywikibot.Timestamp|str
+ @param reason: Block reason
+ @type reason: basestring
+ @param anononly: Whether block should only affect anonymous users
+ @type anononly: bool
+ @param nocreate: Whether to block account creation
+ @type nocreate: bool
+ @param autoblock: Whether to enable autoblock
+ @type autoblock: bool
+ @param noemail: Whether to disable email access
+ @type noemail: bool
+ @param reblock: Whether to reblock if a block already is set
+ @type reblock: bool
+ @return: None
+ """
+ try:
+ self.site.blockuser(self, expiry, reason, anononly, nocreate, autoblock,
noemail, reblock)
+ except pywikibot.data.api.APIError, err:
+ if err.code == 'invalidrange':
+ raise ValueError("%s is not a valid IP range." %
self.username)
+ else:
+ raise err
+
@deprecated("contributions")
@deprecate_arg("limit", "total") # To be consistent with rest of
framework
def editedPages(self, total=500):
diff --git a/pywikibot/site.py b/pywikibot/site.py
index b4357d6..2b262f8 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -2901,6 +2901,29 @@
#TODO: implement patrol
+ @must_be(group='sysop')
+ def blockuser(self, user, expiry, reason, anononly=True, nocreate=True,
autoblock=True,
+ noemail=False, reblock=False):
+
+ token = self.token(user, 'block')
+ if isinstance(expiry, pywikibot.Timestamp):
+ expiry = expiry.toISOformat()
+ req = api.Request(site=self, action='block', user=user.username,
expiry=expiry,
+ reason=reason, token=token)
+ if anononly:
+ req['anononly'] = ''
+ if nocreate:
+ req['nocreate'] = ''
+ if autoblock:
+ req['autoblock'] = ''
+ if noemail:
+ req['noemail'] = ''
+ if reblock:
+ req['reblock'] = ''
+
+ data = req.submit()
+ return data
+
def watchpage(self, page, unwatch=False):
"""Add or remove page from watchlist.
--
To view, visit
https://gerrit.wikimedia.org/r/78218
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic6d1bb17b82698869b63e8223cc2f5d24c0b7c27
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot