jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/232737 )
Change subject: [POC] Enable Flow support in unusedfiles.py ......................................................................
[POC] Enable Flow support in unusedfiles.py
This change adds Flow support to unusedfiles.py. The script now creates a new Flow topic if the user talk page it is posting to is a Flow board. Template definitions for the testwiki were also added.
Bug: T108969 Change-Id: Ie0ba39c94b7804778c2becff866f0fbd27bed5ed --- M scripts/unusedfiles.py 1 file changed, 18 insertions(+), 5 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py index 2801f5b..86ad136 100755 --- a/scripts/unusedfiles.py +++ b/scripts/unusedfiles.py @@ -25,6 +25,7 @@ from pywikibot import i18n, pagegenerators from pywikibot.bot import SingleSiteBot, AutomaticTWSummaryBot, ExistingPageBot from pywikibot.exceptions import ArgumentDeprecationWarning +from pywikibot.flow import Board from pywikibot.tools import issue_deprecation_warning
template_to_the_image = { @@ -35,10 +36,10 @@ 'ur': '{{غیر مستعمل تصاویر}}', }
-# This template message should use subst: template_to_the_user = { - 'fa': '\n\n{{جا:اخطار به کاربر برای تصاویر بدون استفاده|%(title)s}}--~~~~', - 'ur': '\n\n{{جا:اطلاع برائے غیر مستعمل تصاویر}}--~~~~', + 'fa': '{{جا:اخطار به کاربر برای تصاویر بدون استفاده|%(title)s}}', + 'ur': '{{جا:اطلاع برائے غیر مستعمل تصاویر}}', + 'test': '{{User:Happy5214/Unused file notice (user)|%(title)s}}', }
@@ -81,8 +82,12 @@ uploader = image.get_file_history().pop(0)['user'] user = pywikibot.User(image.site, uploader) usertalkpage = user.getUserTalkPage() - msg2uploader = self.template_user % {'title': image.title()} - self.append_text(usertalkpage, msg2uploader) + template2uploader = self.template_user % {'title': image.title()} + msg2uploader = self.site.expand_text(template2uploader) + if usertalkpage.is_flow_page(): + self.post_to_flow_board(usertalkpage, msg2uploader) + else: + self.append_text(usertalkpage, '\n\n' + msg2uploader + ' ~~~~')
def append_text(self, page, apptext): """Append apptext to the page.""" @@ -100,6 +105,14 @@ self.current_page = page self.put_current(text)
+ def post_to_flow_board(self, page, post): + """Post message as a Flow topic.""" + board = Board(page) + header, rest = post.split('\n', 1) + title = header.strip('=') + content = rest.lstrip() + board.new_topic(title, content) +
def main(*args): """