jenkins-bot has submitted this change and it was merged.
Change subject: Use set_redirect_target method in scripts ......................................................................
Use set_redirect_target method in scripts
Change-Id: I767dd8336fc465244fd4d8742da931c7b92993b0 --- M scripts/redirect.py M scripts/states_redirect.py 2 files changed, 9 insertions(+), 29 deletions(-)
Approvals: John Vandenberg: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/redirect.py b/scripts/redirect.py index bcb316e..0560204 100755 --- a/scripts/redirect.py +++ b/scripts/redirect.py @@ -453,19 +453,15 @@ {'to': movedTarget.title( asLink=True)}) content = redir_page.get(get_redirect=True) - text = self.site.redirectRegex().sub( - '#%s %s' % (self.site.redirect(), - movedTarget.title(asLink=True, - textlink=True)), - content) - pywikibot.showDiff(content, text) + redir_page.set_redirect_target( + movedTarget, keep_section=True) + pywikibot.showDiff(content, redir_page.text) pywikibot.output(u'Summary - %s' % reason) if self.user_confirm( u'Redirect target %s has been moved to %s.\n' u'Do you want to fix %s?' % (targetPage, movedTarget, redir_page)): try: - redir_page.text = text redir_page.save(reason) except pywikibot.NoUsername: pywikibot.output(u"Page [[%s]] not saved; " @@ -642,31 +638,14 @@ except pywikibot.BadTitle: pywikibot.output(u"Bad Title Error") break - oldlink = self.site.redirectRegex().search(oldText).group(1) - if "#" in oldlink and targetPage.section() is None: - sectionlink = oldlink[oldlink.index("#"):] - targetlink = pywikibot.Page( - self.site, - targetPage.title() + sectionlink - ).title(asLink=True, textlink=True) - else: - targetlink = targetPage.title(asLink=True, textlink=True) - - text = self.site.redirectRegex().sub( - '#%s %s' % (self.site.redirect(), - targetlink), - oldText, 1) - if redir.title() == targetPage.title() or text == oldText: - pywikibot.output(u"Note: Nothing left to do on %s" - % redir.title(asLink=True)) - break + redir.set_redirect_target(targetPage, keep_section=True) summary = i18n.twtranslate(self.site, 'redirect-fix-double', {'to': targetPage.title(asLink=True)} ) - pywikibot.showDiff(oldText, text) + pywikibot.showDiff(oldText, redir.text) if self.user_confirm(u'Do you want to accept the changes?'): try: - redir.put(text, summary) + redir.save(summary) except pywikibot.LockedPage: pywikibot.output(u'%s is locked.' % redir.title()) except pywikibot.SpamfilterError as error: diff --git a/scripts/states_redirect.py b/scripts/states_redirect.py index 879df31..702d89c 100644 --- a/scripts/states_redirect.py +++ b/scripts/states_redirect.py @@ -116,8 +116,9 @@ u'Create redirect %s?' % pl.title(), (('yes', 'y'), ('no', 'n'))) if change == 'y': - pl.text = '#REDIRECT [[%s]]' % p2.title() - pl.save(i18n.translate(self.site, msg)) + pl.set_redirect_target( + p2, create=True, + summary=i18n.translate(self.site, msg))
def main():
pywikibot-commits@lists.wikimedia.org