jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/407186 )
Change subject: [IMPR] Make page.py skip pages with in use templates ......................................................................
[IMPR] Make page.py skip pages with in use templates
Bug: T186170 Change-Id: I2316b56ee7922a34754fab6d2d7b34730e2b3a1c --- M pywikibot/families/wikipedia_family.py M pywikibot/family.py M pywikibot/page.py M tests/page_tests.py 4 files changed, 34 insertions(+), 5 deletions(-)
Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/families/wikipedia_family.py b/pywikibot/families/wikipedia_family.py index a3c17df..f6707e4 100644 --- a/pywikibot/families/wikipedia_family.py +++ b/pywikibot/families/wikipedia_family.py @@ -198,6 +198,19 @@ 'uk': (u'/Документація', ), }
+ # Templates that indicate an edit should be avoided + self.edit_restricted_templates = { + 'ar': ('تحرر',), + 'bs': ('Izmjena u toku',), + 'cs': ('Pracuje se',), + 'de': ('Inuse', 'In use', 'In bearbeitung', 'Inbearbeitung',), + 'en': ('Inuse', 'In use'), + 'fa': ('ویرایش',), + 'hr': ('Radovi',), + 'sr': ('Радови у току', 'Рут',), + 'zh': ('Inuse',), + } + def get_known_families(self, site): """Override the family interwiki prefixes for each site.""" # In Swedish Wikipedia 's:' is part of page title not a family diff --git a/pywikibot/family.py b/pywikibot/family.py index a4c49f0..4be15e5 100644 --- a/pywikibot/family.py +++ b/pywikibot/family.py @@ -728,6 +728,10 @@ '_default': [] }
+ # A dict of tuples for different sites with names of templates + # that indicate an edit should be avoided + self.edit_restricted_templates = {} + # A list of projects that share cross-project sessions. if not hasattr(self, 'cross_projects'): self.cross_projects = [] diff --git a/pywikibot/page.py b/pywikibot/page.py index b2f1888..68b71b5 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -1145,9 +1145,10 @@ """ Determine whether the active bot is allowed to edit the page.
- This will be True if the page doesn't contain {{bots}} or - {{nobots}}, or it contains them and the active bot is allowed to - edit this page. (This method is only useful on those sites that + This will be True if the page doesn't contain {{bots}} or {{nobots}} + or any other template from edit_restricted_templates list + in x_family.py file, or it contains them and the active bot is allowed + to edit this page. (This method is only useful on those sites that recognize the bot-exclusion protocol; on other sites, it will always return True.)
@@ -1175,8 +1176,13 @@
# go through all templates and look for any restriction # multiple bots/nobots templates are allowed + restrictions = self.family.edit_restricted_templates.get( + self.site.code) for template, params in templates: title = template.title(withNamespace=False) + if restrictions: + if title in restrictions: + return False if title == 'Nobots': if not params: return False @@ -1258,7 +1264,8 @@ watch = 'unwatch' if not force and not self.botMayEdit(): raise pywikibot.OtherPageSaveError( - self, "Editing restricted by {{bots}} template") + self, 'Editing restricted by {{bots}}, {{nobots}} ' + 'or site's equivalent of {{in use}} template') self._save(summary=summary, watch=watch, minor=minor, botflag=botflag, asynchronous=asynchronous, callback=callback, cc=apply_cosmetic_changes, quiet=quiet, **kwargs) diff --git a/tests/page_tests.py b/tests/page_tests.py index 8fd2a08..b404028 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the page module.""" # -# (C) Pywikibot team, 2008-2017 +# (C) Pywikibot team, 2008-2018 # # Distributed under the terms of the MIT license. # @@ -817,6 +817,11 @@ u'%s: %s but user=%s' % (page.text, page.botMayEdit(), user))
+ # Ban all users including bots. + page.text = '{{in use}}' + page._templates = [pywikibot.Page(site, 'Template:In use')] + self.assertFalse(page.botMayEdit()) +
class TestPageHistory(DefaultSiteTestCase):
pywikibot-commits@lists.wikimedia.org