jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/725405 )
Change subject: [IMPR] use different edit comments when adding, changeing or removing
templates
......................................................................
[IMPR] use different edit comments when adding, changeing or removing templates
- add the msgtype attribute to ParsedTemplate namedtuple to hold the
i18n message key
- return either "modifying" or "adding" message key with
understand_block function
- return the message key with remove_templates coroutine
- early return in CheckerBot.treat_page if the message key retrieved
from coroutine is None
- also do not assume that the first line of the page's text is empty
Bug: T291345
Change-Id: I0616e98528273944646eb12377301b82db646d85
---
M scripts/blockpageschecker.py
1 file changed, 22 insertions(+), 8 deletions(-)
Approvals:
Meno25: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py
index 5896566..e1b8846 100755
--- a/scripts/blockpageschecker.py
+++ b/scripts/blockpageschecker.py
@@ -49,6 +49,7 @@
from collections import namedtuple
from itertools import chain
+from typing import Optional
import pywikibot
@@ -165,7 +166,7 @@
project_inserted = ['ar', 'cs', 'fr', 'it', 'ja',
'pt', 'sr', 'ur', 'zh']
# END PREFERENCES
-ParsedTemplate = namedtuple('ParsedTemplate', 'blocktype, regex')
+ParsedTemplate = namedtuple('ParsedTemplate', 'blocktype, regex,
msgtype')
class CheckerBot(ExistingPageBot, SingleSiteBot):
@@ -207,12 +208,15 @@
self.invoke_editor(page)
return
- newtext = self.parse_tempates.send((page.text, page.protection()))
+ newtext, key = self.parse_tempates.send((page.text, page.protection()))
next(self.parse_tempates)
+ if not key:
+ return
+
try:
commentUsed = i18n.twtranslate(self.site,
- 'blockpageschecker-deleting')
+ 'blockpageschecker-' + key)
except TranslationError:
commentUsed = i18n.twtranslate(self.site,
'blockpageschecker-summary')
@@ -251,22 +255,25 @@
for catchRegex in template:
resultCatch = re.findall(catchRegex, text)
if resultCatch:
- return ParsedTemplate(results[index], catchRegex)
+ return ParsedTemplate(
+ results[index], catchRegex, 'modifying')
if TSMP and TTMP and TTP != TTMP and TSP != TSMP:
for catchRegex in TTMP:
resultCatch = re.findall(catchRegex, text)
if resultCatch:
- return ParsedTemplate('sysop-move', catchRegex)
+ return ParsedTemplate(
+ 'sysop-move', catchRegex, 'modifying')
for catchRegex in TSMP:
resultCatch = re.findall(catchRegex, text)
if resultCatch:
- return ParsedTemplate('autoconfirmed-move', catchRegex)
+ return ParsedTemplate(
+ 'autoconfirmed-move', catchRegex,
'modifying')
# If editable means that we have no regex, won't change anything
# with this regex
- return ParsedTemplate('editable', r'\A\n')
+ return ParsedTemplate('editable', r'\A', 'adding')
TSP = i18n.translate(self.site, templateSemiProtection)
TTP = i18n.translate(self.site, templateTotalProtection)
@@ -289,6 +296,7 @@
# keep track of the changes for each step (edit then move)
changes = -1
+ msg_type = None # type: Optional[str]
editRestr = restrictions.get('edit')
if not editRestr:
# page is not edit-protected
@@ -313,6 +321,7 @@
if not self.opt.move:
msg += ', deleting the template..'
pywikibot.output(msg + '.')
+ msg_type = 'deleting'
elif editRestr[0] == 'sysop':
# total edit protection
@@ -338,6 +347,7 @@
else:
text, changes = re.subn(
TemplateInThePage.regex, TNR[1], text)
+ msg_type = TemplateInThePage.msgtype
elif TSP or TU:
# implicitly
@@ -364,6 +374,7 @@
else:
text, changes = re.subn(
TemplateInThePage.regex, TNR[0], text)
+ msg_type = TemplateInThePage.msgtype
if not changes:
# We tried to fix edit-protection templates, but it did
@@ -389,6 +400,7 @@
if not changes:
text, changes = re.subn(
'({})'.format(replaceToPerform), '', text)
+ msg_type = 'deleting'
elif moveRestr[0] == 'sysop':
# move-total-protection
if TemplateInThePage.blocktype == 'sysop-move' and TTMP \
@@ -408,6 +420,7 @@
else:
text, changes = re.subn(
TemplateInThePage.regex, TNR[3], text)
+ msg_type = TemplateInThePage.msgtype
elif TSMP or TU:
# implicitly
@@ -430,6 +443,7 @@
else:
text, changes = re.subn(
TemplateInThePage.regex, TNR[2], text)
+ msg_type = TemplateInThePage.msgtype
if not changes:
# We tried to fix move-protection templates
@@ -437,7 +451,7 @@
pywikibot.warning(
'No move-protection template could be found')
- yield text
+ yield text, msg_type
def main(*args: str) -> None:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/725405
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I0616e98528273944646eb12377301b82db646d85
Gerrit-Change-Number: 725405
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Meno25 <meno25mail(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged