jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/697178 )
Change subject: [IMPR] check bot/nobots templates for cosmetic_changes ......................................................................
[IMPR] check bot/nobots templates for cosmetic_changes
Bug: T283989 Change-Id: Ie2f39115a4bbcbab43989718deff8f1aca020866 --- M pywikibot/page/__init__.py 1 file changed, 12 insertions(+), 3 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py index ccd8f41..9aa6a09 100644 --- a/pywikibot/page/__init__.py +++ b/pywikibot/page/__init__.py @@ -1038,8 +1038,12 @@ self._bot_may_edit = self._check_bot_may_edit() return self._bot_may_edit
- def _check_bot_may_edit(self) -> bool: - """A botMayEdit helper method.""" + def _check_bot_may_edit(self, module: Optional[str] = None) -> bool: + """A botMayEdit helper method. + + @param module: The module name to be restricted. Defaults to + pywikibot.calledModuleName(). + """ if not hasattr(self, 'templatesWithParams'): return True
@@ -1047,7 +1051,6 @@ return True
username = self.site.username() - module = pywikibot.calledModuleName() try: templates = self.templatesWithParams() except (NoPageError, IsRedirectPageError, SectionError): @@ -1056,6 +1059,9 @@ # go through all templates and look for any restriction restrictions = set(self.site.get_edit_restricted_templates())
+ if module is None: + module = pywikibot.calledModuleName() + # also add archive templates for non-archive bots if module != 'archivebot': restrictions.update(self.site.get_archived_page_templates()) @@ -1222,6 +1228,8 @@ if self.isTalkPage() or self.content_model != 'wikitext' or \ pywikibot.calledModuleName() in config.cosmetic_changes_deny_script: return summary + + # check if cosmetic_changes is enabled for this page family = self.site.family.name if config.cosmetic_changes_mylang_only: cc = ((family == config.family and self.site.lang == config.mylang) @@ -1231,6 +1239,7 @@ cc = True cc = cc and self.site.lang not in config.cosmetic_changes_disable.get( family, []) + cc = cc and self._check_bot_may_edit('cosmetic_changes') if not cc: return summary
pywikibot-commits@lists.wikimedia.org