John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/151576

Change subject: Add  {{Filehistory}} support to imagetransfer
......................................................................

Add  {{Filehistory}} support to imagetransfer

Also fix the only flake in imagetransfer,
and fix getFileVersionHistory docstring.

Bug: 69067
Change-Id: I9b9a2f4b8a33785c92b5a0bf0acdb296cf3347e5
---
M pywikibot/page.py
M scripts/imagetransfer.py
2 files changed, 26 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/76/151576/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 2232a49..9ea40e5 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1855,23 +1855,37 @@
     def getFileVersionHistory(self):
         """Return the image file's version history.
 
-        @return: An iterator yielding tuples containing (timestamp,
-            username, resolution, filesize, comment).
+        @return: a list of dict
 
         """
         return self.site.loadimageinfo(self, history=True)
 
-    def getFileVersionHistoryTable(self):
-        """Return the version history in the form of a wiki table."""
+    def getFileVersionHistoryTable(self, use_template=True):
+        """Return the version history formatted as wiki text.
+
+        The history may be formatted as a wiki table using English,
+        or using the templates {{filehistory}} and {{filehistory-entry}}
+        which can be translated.
+
+        @param use_template: Use {{filehistory}}
+        @type use_template: bool
+        """
         lines = []
         for info in self.getFileVersionHistory():
-            datetime = info['timestamp']
-            username = info['user']
-            resolution = '%dx%d' % (info['height'], info['width'])
-            size = info['size']
-            comment = info['comment']
-            lines.append(u'| %s || %s || %s || %s || <nowiki>%s</nowiki>'
-                         % (datetime, username, resolution, size, comment))
+            info['resolution'] = u'%(height)d×%(width)d' % info
+            if use_template:
+                lines.append(
+                    u'{{filehistory-entry|date=%(timestamp)s|uploader=%(user)s'
+                    u'|resolution=%(resolution)s|size=%(size)s'
+                    u'|comment=<nowiki>%(comment)s</nowiki>}}'
+                    % info)
+            else:
+                lines.append(u'| %(timestamp)s || %(user)s || %(resolution)s '
+                             u'|| %(size)s || <nowiki>%(comment)s</nowiki>'
+                             % info)
+        if use_template:
+            return '{{filehistory|1=\n' + '\n'.join(lines) + '\n}}\n\n'
+
         return u'{| border="1"\n! date/time || username || resolution || size 
|| edit summary\n|----\n' + \
                u'\n|----\n'.join(lines) + '\n|}'
 
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py
index ee869f4..705ffd0 100644
--- a/scripts/imagetransfer.py
+++ b/scripts/imagetransfer.py
@@ -185,7 +185,7 @@
 
             description = i18n.translate(self.targetSite, copy_message,
                                          fallback=True) % (sourceSite, 
description)
-            description += '\n\n' + 
str(sourceImagePage.getFileVersionHistoryTable())
+            description += '\n\n' + 
sourceImagePage.getFileVersionHistoryTable()
             # add interwiki link
             if sourceSite.family == self.targetSite.family:
                 description += "\r\n\r\n" + unicode(sourceImagePage)
@@ -226,7 +226,6 @@
     def showImageList(self, imagelist):
         for i in range(len(imagelist)):
             image = imagelist[i]
-            #sourceSite = sourceImagePage.site
             print "-" * 60
             pywikibot.output(u"%s. Found image: %s"
                              % (i, image.title(asLink=True)))

-- 
To view, visit https://gerrit.wikimedia.org/r/151576
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9b9a2f4b8a33785c92b5a0bf0acdb296cf3347e5
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to