22import ipaddress
33import logging
44from datetime import datetime , timezone
5- from typing import Dict , List
5+ from typing import Any , Dict , List , Optional
66
77import mwparserfromhell
88import pywikibot
@@ -77,7 +77,9 @@ def __init__(self, number, name, site, family):
7777 )
7878 self .supports_manual_run = True
7979
80- def get_steward_who_gblocked_ip (self , api : MediawikiApi , ip_or_range ):
80+ def get_steward_who_gblocked_ip (
81+ self , api : MediawikiApi , ip_or_range
82+ ) -> Optional [str ]:
8183 try :
8284 data = QueryGenerator (
8385 site = api .get_site (),
@@ -99,21 +101,22 @@ def get_steward_who_gblocked_ip(self, api: MediawikiApi, ip_or_range):
99101
100102 return data [0 ]["by" ]
101103
102- def get_steward_who_locked_account (self , api : MediawikiApi , account_name ):
103- data = QueryGenerator (
104- site = api .get_site (),
105- list = "logevents" ,
106- letype = "globalauth" ,
107- letitle = "User:" + account_name + "@global" ,
108- ).request .submit ()["query" ]["logevents" ]
109-
110- if len (data ) == 0 :
104+ def _get_steward_who_blocked_account_global_block (
105+ self , entry : Dict [str , Any ]
106+ ) -> Optional [str ]:
107+ if not was_enough_time_ago (
108+ entry ["timestamp" ], self .get_task_configuration ("mark_done_min_time" )
109+ ):
111110 return None
112111
113- entry = data [0 ]
112+ return entry ["by" ]
113+
114+ def _get_steward_who_blocked_account_lock (
115+ self , entry : Dict [str , Any ]
116+ ) -> Optional [str ]:
114117 params = entry ["params" ]
115118
116- if entry ["action" ] = = "delete" :
119+ if entry ["action" ] ! = "delete" :
117120 return None
118121
119122 if "added" in params :
@@ -129,7 +132,32 @@ def get_steward_who_locked_account(self, api: MediawikiApi, account_name):
129132 ):
130133 return None
131134
132- return data [0 ]["user" ]
135+ return entry ["user" ]
136+
137+ def get_steward_who_blocked_account (
138+ self , api : MediawikiApi , account_name
139+ ) -> Optional [str ]:
140+ data = QueryGenerator (
141+ site = api .get_site (),
142+ list = "globalblocks|logevents" ,
143+ bgtargets = account_name ,
144+ letype = "globalauth" ,
145+ letitle = "User:" + account_name + "@global" ,
146+ ).request .submit ()["query" ]
147+
148+ if len (data ["globalblocks" ]) >= 1 :
149+ user = self ._get_steward_who_blocked_account_global_block (
150+ data ["globalblocks" ][0 ]
151+ )
152+ if user :
153+ return user
154+
155+ if len (data ["logevents" ]) >= 1 :
156+ user = self ._get_steward_who_blocked_account_lock (data ["logevents" ][0 ])
157+ if user :
158+ return user
159+
160+ return None
133161
134162 def process_srp_section (self , api , section ):
135163 header = section .filter_headings ()[0 ]
@@ -201,7 +229,7 @@ def process_srp_section(self, api, section):
201229 awesome_people .add (steward )
202230
203231 for account in accounts :
204- steward = self .get_steward_who_locked_account (api , account )
232+ steward = self .get_steward_who_blocked_account (api , account )
205233 if steward is None :
206234 mark_done = False
207235 else :
0 commit comments