jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] Enable iprange with site.blocks generator
......................................................................
[FEAT] Enable iprange with site.blocks generator
- mw API provides bkip parameter to filter an ip address or
an ip range block. Enable this feature with pywikibot.
- Add 'userid' to the list of retrieved properties for mw 1.18+.
- Also add some additional documentations.
Bug: T125303
Change-Id: I9f4698a0b8319f8fb869c46c7d82e8d25a189822
---
M pywikibot/site.py
1 file changed, 30 insertions(+), 7 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 5b3183d..9d16233 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -4129,19 +4129,34 @@
@deprecated_args(step=None)
def blocks(self, starttime=None, endtime=None, reverse=False,
- blockids=None, users=None, total=None):
+ blockids=None, users=None, iprange=None, total=None):
"""Iterate all current blocks, in order of creation.
- Note that logevents only logs user blocks, while this method
- iterates all blocks including IP ranges. The iterator yields dicts
- containing keys corresponding to the block properties
- (see
L{https://www.mediawiki.org/wiki/API:Blocks}).
+ The iterator yields dicts containing keys corresponding to the
+ block properties.
+ @see:
L{https://www.mediawiki.org/wiki/API:Blocks})
+
+ @note: logevents only logs user blocks, while this method
+ iterates all blocks including IP ranges.
+ @note: C{userid} key will be given for mw 1.18+ only
+ @note: C{iprange} parameter cannot be used together with C{users}.
@param starttime: start iterating at this Timestamp
+ @type starttime: pywikibot.Timestamp
@param endtime: stop iterating at this Timestamp
+ @type endtime: pywikibot.Timestamp
@param reverse: if True, iterate oldest blocks first (default: newest)
- @param blockids: only iterate blocks with these id numbers
+ @type reverse: bool
+ @param blockids: only iterate blocks with these id numbers. Numbers
+ must be separated by '|' if given by a basestring.
+ @type blockids: basestring, tuple or list
@param users: only iterate blocks affecting these usernames or IPs
+ @type users: basestring, tuple or list
+ @param iprange: a single IP or an IP range. Ranges broader than
+ IPv4/16 or IPv6/19 are not accepted.
+ @type iprange: str
+ @param total: total amount of block entries
+ @type total: int
"""
if starttime and endtime:
if reverse:
@@ -4156,7 +4171,10 @@
"endtime must be before starttime with reverse=False")
bkgen = self._generator(api.ListGenerator, type_arg="blocks",
total=total)
- bkgen.request["bkprop"] =
"id|user|by|timestamp|expiry|reason|range|flags"
+ bkgen.request['bkprop'] = ['id', 'user', 'by',
'timestamp', 'expiry',
+ 'reason', 'range', 'flags']
+ if MediaWikiVersion(self.version()) >= MediaWikiVersion('1.18'):
+ bkgen.request['bkprop'] += ['userid']
if starttime:
bkgen.request["bkstart"] = starttime
if endtime:
@@ -4173,6 +4191,8 @@
users = [user.upper() if is_IP(user) and '::' not in user else user
for user in users]
bkgen.request["bkusers"] = users
+ elif iprange:
+ bkgen.request['bkip'] = iprange
return bkgen
@deprecated_args(step=None)
@@ -4226,6 +4246,9 @@
start=None, end=None, reverse=False, tag=None, total=None):
"""Iterate all log entries.
+ @note: logevents with logtype='block' only logs user blocks whereas
+ site.blocks iterates all blocks including IP ranges.
+
@param logtype: only iterate entries of this type (see wiki
documentation for available types, which will include "block",
"protect", "rights", "delete",
"upload", "move", "import",
--
To view, visit
https://gerrit.wikimedia.org/r/267434
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9f4698a0b8319f8fb869c46c7d82e8d25a189822
Gerrit-PatchSet: 9
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>