From 12c1c5cf67e6a7b84881cff2f5c2ced7afc126ce Mon Sep 17 00:00:00 2001 From: xqt Date: Tue, 25 Feb 2025 07:12:06 +0100 Subject: [PATCH] [bugfix] ensure that -from and -to arguments are not equal verify that -from and -to arguments are not equal for move action. otherwise ask for new values. If the given answer for -from is empty, leave the script. Bug: T384753 Change-Id: Ib23dba9d8e69571b272ce460312c7ca79baa3922 --- scripts/category.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/category.py b/scripts/category.py index 15200be104..9b758c6e99 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -153,7 +153,7 @@ :mod:`pagegenerators` are supported with "move" and "remove" action. """ # -# (C) Pywikibot team, 2004-2024 +# (C) Pywikibot team, 2004-2025 # # Distributed under the terms of the MIT license. # @@ -1638,12 +1638,24 @@ def main(*args: str) -> None: deletion_comment=use_deletion_summary, generator=gen) elif action == 'move': - if 'from' not in options: - options['from'] = pywikibot.input( - 'Please enter the old name of the category:') - if 'to' not in options: - options['to'] = pywikibot.input( - 'Please enter the new name of the category:') + while True: + if 'from' not in options: + options['from'] = pywikibot.input( + 'Please enter the old name of the category:') + if not options['from']: + return + + if 'to' not in options: + options['to'] = pywikibot.input( + 'Please enter the new name of the category:') + + if options['from'] != options['to']: + break + + pywikibot.error('-from and -to arguments are equal, please retry.') + del options['from'] + del options['to'] + if use_deletion_summary: deletion_comment = \ CategoryMoveRobot.DELETION_COMMENT_SAME_AS_EDIT_COMMENT