jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/507838 )
Change subject: [IMPR] Derive CommonscatBot from ExistingPageBot and NoRedirectPageBot ......................................................................
[IMPR] Derive CommonscatBot from ExistingPageBot and NoRedirectPageBot
- Use ExistingPageBot and NoRedirectPageBot instead of skipping inside treat method - use skip_page method for skipping category redirects and disambiguation pages - use treat_page instead of treat method
Change-Id: I775b55ce7b5dedfa34c9b04d95ec52ceb7661100 --- M scripts/commonscat.py 1 file changed, 18 insertions(+), 18 deletions(-)
Approvals: D3r1ck01: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/commonscat.py b/scripts/commonscat.py index 1be4a49..33ff6ea 100755 --- a/scripts/commonscat.py +++ b/scripts/commonscat.py @@ -64,7 +64,7 @@ import pywikibot
from pywikibot import i18n, pagegenerators -from pywikibot.bot import SingleSiteBot +from pywikibot.bot import SingleSiteBot, ExistingPageBot, NoRedirectPageBot
from scripts.add_text import add_text
@@ -227,7 +227,7 @@ }
-class CommonscatBot(SingleSiteBot): +class CommonscatBot(SingleSiteBot, ExistingPageBot, NoRedirectPageBot):
"""Commons categorisation bot."""
@@ -238,22 +238,23 @@ }) super(CommonscatBot, self).__init__(**kwargs)
- def treat(self, page): + def skip_page(self, page): + """Skip category redirects or disambigs.""" + if page.isCategoryRedirect(): + pywikibot.warning( + 'Page {page} on {page.site} is a category redirect. ' + 'Skipping.'.format(page=page)) + return True + if page.isDisambig(): + pywikibot.warning( + 'Page {page} on {page.site} is a disambiguation. ' + 'Skipping.'.format(page=page)) + return True + return super(CommonscatBot, self).skip_page(page) + + def treat_page(self): """Load the given page, do some changes, and save it.""" - if not page.exists(): - pywikibot.output('Page {} does not exist. Skipping.' - .format(page.title(as_link=True))) - elif page.isRedirectPage(): - pywikibot.output('Page {} is a redirect. Skipping.' - .format(page.title(as_link=True))) - elif page.isCategoryRedirect(): - pywikibot.output('Page {} is a category redirect. Skipping.' - .format(page.title(as_link=True))) - elif page.isDisambig(): - pywikibot.output('Page {} is a disambiguation. Skipping.' - .format(page.title(as_link=True))) - else: - self.addCommonscat(page) + self.addCommonscat(self.current_page)
@classmethod def getCommonscatTemplate(cls, code=None): @@ -293,7 +294,6 @@ category is found add it to the page.
""" - self.current_page = page # Get the right templates for this page primaryCommonscat, commonscatAlternatives = self.getCommonscatTemplate( page.site.code)
pywikibot-commits@lists.wikimedia.org