Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/78218
Change subject: Implement User.block() function
......................................................................
Implement User.block() function
Change-Id: Ic6d1bb17b82698869b63e8223cc2f5d24c0b7c27
---
M pywikibot/page.py
M pywikibot/site.py
2 files changed, 33 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/18/78218/1
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 215b643..c605c8d 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2178,6 +2178,16 @@
return True
return False
+ def block(self, expiry, reason, anononly=True, nocreate=True,
autoblock=True,
+ noemail=False, reblock=False):
+ 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: newchange
Gerrit-Change-Id: Ic6d1bb17b82698869b63e8223cc2f5d24c0b7c27
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits