From 7d123517790b1cd18e8e935141ba49a31dd9acd5 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Fri, 25 Jul 2025 08:52:12 +0200 Subject: [PATCH 1/3] Check for global usage with delete runs split it up a bit - restrict to files or commons - don't check dev stuff for global usage (files with `/dev/` in the title) - check for non files not yet working! --- scripts/delete.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/delete.py b/scripts/delete.py index bc9ae09807..0d7698cb0e 100755 --- a/scripts/delete.py +++ b/scripts/delete.py @@ -16,6 +16,9 @@ -undelete Actually undelete pages instead of deleting. Obviously makes sense only with -page and -file. +-ignoreusage By default deletion will skip pages that have global usage. + Setting this param will ignore that check and delete them anyways. + -isorphan Alert if there are pages that link to page to be deleted (check 'What links here'). By default it is active and only the summary per namespace is be given. If given as @@ -131,6 +134,7 @@ class DeletionRobot(CurrentPageBot): 'undelete': False, 'isorphan': 0, 'orphansonly': [], + 'ignoreusage': False, } def __init__(self, summary: str, **kwargs) -> None: @@ -178,6 +182,17 @@ def display_references(self) -> None: def skip_page(self, page) -> bool: """Skip the page under some conditions.""" + """Skip files with global usage""" + if not self.opt.undelete and page.exists() and not self.opt.ignoreusage: + if page.namespace() == Namespace.FILE: + global_usage = page.site.simple_request(action='query', prop='globalusage', titles=page.title()).submit() + if len(global_usage['query']['pages'][str(page.pageid)]['globalusage']) > 0: + pywikibot.info(f'Skipping: {page} has global usage.') + return True + if str(page.site) == 'liquipedia:commons' and '/dev/' not in str(page.title()): + # do the check here too ... just working for non files ... + pywikibot.info(f'Skipping: {page} has global usage.') + return True if self.opt.undelete and page.exists(): pywikibot.info(f'Skipping: {page} already exists.') return True @@ -240,7 +255,7 @@ def main(*args: str) -> None: for arg in local_args: opt, _, value = arg.partition(':') - if opt in ('-always', '-undelete'): + if opt in ('-always', '-undelete', '-ignoreusage'): options[opt[1:]] = True elif opt == '-summary': summary = value or pywikibot.input( From 3f803dec0a0ac290e0795a0056aaf817db930c3a Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Mon, 24 Nov 2025 02:44:34 +0100 Subject: [PATCH 2/3] no check possible for non files Corrected a typo in the -ignoreusage option description and removed unnecessary checks for global usage on non-file pages. --- scripts/delete.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/delete.py b/scripts/delete.py index 0d7698cb0e..901b94c4b0 100755 --- a/scripts/delete.py +++ b/scripts/delete.py @@ -16,7 +16,7 @@ -undelete Actually undelete pages instead of deleting. Obviously makes sense only with -page and -file. --ignoreusage By default deletion will skip pages that have global usage. +-ignoreusage By default deletion will skipfiles that have global usage. Setting this param will ignore that check and delete them anyways. -isorphan Alert if there are pages that link to page to be deleted @@ -189,10 +189,8 @@ def skip_page(self, page) -> bool: if len(global_usage['query']['pages'][str(page.pageid)]['globalusage']) > 0: pywikibot.info(f'Skipping: {page} has global usage.') return True - if str(page.site) == 'liquipedia:commons' and '/dev/' not in str(page.title()): - # do the check here too ... just working for non files ... - pywikibot.info(f'Skipping: {page} has global usage.') - return True + # for non files there is no api endpoint to check global usage + # if such an endpoint gets added in the future we should add an according check here too if self.opt.undelete and page.exists(): pywikibot.info(f'Skipping: {page} already exists.') return True From df67645a2603e8057ab9875b595b376a62a945be Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Mon, 24 Nov 2025 10:35:26 +0100 Subject: [PATCH 3/3] Update scripts/delete.py Co-authored-by: SyntacticSalt --- scripts/delete.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/delete.py b/scripts/delete.py index 901b94c4b0..260b548ce5 100755 --- a/scripts/delete.py +++ b/scripts/delete.py @@ -16,8 +16,9 @@ -undelete Actually undelete pages instead of deleting. Obviously makes sense only with -page and -file. --ignoreusage By default deletion will skipfiles that have global usage. +-ignoreusage By default deletion will skip files that have global usage. Setting this param will ignore that check and delete them anyways. + For non-file pages, no check is performed. -isorphan Alert if there are pages that link to page to be deleted (check 'What links here'). By default it is active and