Happy5214 has uploaded a new change for review.
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.
Change-Id: Ie0ba39c94b7804778c2becff866f0fbd27bed5ed
---
M scripts/unusedfiles.py
1 file changed, 22 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/37/232737/1
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index 30140aa..fb44b25 100755
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -21,8 +21,12 @@
__version__ = '$Id$'
#
+import re
+
import pywikibot
from pywikibot import i18n, pagegenerators, Bot
+from pywikibot.flow import Board
+from pywikibot.page import FilePage
comment = {
'ar': u'صور للاستبعاد',
@@ -36,11 +40,14 @@
template_to_the_image = {
'it': u'{{immagine orfana}}',
'fa': u'{{تصاویر بدون استفاده}}',
+ 'test': '{{User:Happy5214/Unused file notice (file)}}',
}
# This template message should use subst:
template_to_the_user = {
- 'fa': u'\n\n{{جا:اخطار به کاربر برای تصاویر بدون
استفاده|%(title)s}}--~~~~',
+ 'fa': u'{{جا:اخطار به کاربر برای تصاویر بدون استفاده|%(title)s}}--~~~~',
+ 'it': u'{{Utente:Filbot/Immagine orfana}}',
+ 'test': '{{User:Happy5214/Unused file notice (user)|%(title)s}}',
}
@@ -83,8 +90,12 @@
uploader = image.getFileVersionHistory().pop(0)['user']
user = pywikibot.User(image.site, uploader)
usertalkpage = user.getUserTalkPage()
- msg2uploader = template_user % {'title': image.title()}
- self.append_text(usertalkpage, msg2uploader)
+ template2uploader = 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."""
@@ -102,6 +113,14 @@
text += apptext
self.userPut(page, oldtext, text, summary=self.summary)
+ 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):
"""
--
To view, visit https://gerrit.wikimedia.org/r/232737
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie0ba39c94b7804778c2becff866f0fbd27bed5ed
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits