Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion scripts/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
-undelete Actually undelete pages instead of deleting. Obviously
makes sense only with -page and -file.

-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
only the summary per namespace is be given. If given as
Expand Down Expand Up @@ -131,6 +135,7 @@ class DeletionRobot(CurrentPageBot):
'undelete': False,
'isorphan': 0,
'orphansonly': [],
'ignoreusage': False,
}

def __init__(self, summary: str, **kwargs) -> None:
Expand Down Expand Up @@ -178,6 +183,15 @@ 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
# 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
Expand Down Expand Up @@ -240,7 +254,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(
Expand Down