Gerrit Patch Uploader has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/348448 )

Change subject: upload.py + specialbots.py: Authorize the use of an edit summary
......................................................................

upload.py + specialbots.py: Authorize the use of an edit summary

Adds an option to enter a specific upload summary (edit summary for the upload 
action).
It uses the "comment" argument of site.upload() instead of using page.text.
I added a "summary" argument for UploadRobot of specialbots to do this.

Bug: T162527
Change-Id: Ifc3fc7cb853f81735d98e9fceef341f0df87d39e
---
M pywikibot/specialbots.py
M scripts/upload.py
2 files changed, 15 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/48/348448/1

diff --git a/pywikibot/specialbots.py b/pywikibot/specialbots.py
index 4694857..c914e2f 100644
--- a/pywikibot/specialbots.py
+++ b/pywikibot/specialbots.py
@@ -40,7 +40,7 @@
     """Upload bot."""
 
     def __init__(self, url, urlEncoding=None, description=u'',
-                 useFilename=None, keepFilename=False,
+                 useFilename=None, keepFilename=False, summary=None,
                  verifyDescription=True, ignoreWarning=False,
                  targetSite=None, uploadByUrl=False, aborts=[], chunk_size=0,
                  **kwargs):
@@ -60,6 +60,8 @@
         @param keepFilename: Set to True to keep original names of urls and
             files, otherwise it will ask to enter a name for each file.
         @type keepFilename: bool
+        @param summary: Summary of the upload
+        @type summary: string
         @param verifyDescription: Set to False to not proofread the 
description.
         @type verifyDescription: bool
         @param ignoreWarning: Set this to True to upload even if another file
@@ -91,7 +93,7 @@
             raise ValueError('When always is set to True, either ignoreWarning 
'
                              'or aborts must be set to True.')
         if always and not description:
-            raise ValueError('When always is set to True the description must '
+            raise ValueError('When always is set to True, the description must 
'
                              'be set.')
         self.url = url
         if isinstance(self.url, basestring):
@@ -105,6 +107,7 @@
         self.ignoreWarning = ignoreWarning
         self.aborts = aborts
         self.chunk_size = chunk_size
+        self.summary = summary
         if config.upload_to_commons:
             self.targetSite = targetSite or pywikibot.Site('commons',
                                                            'commons')
@@ -395,6 +398,7 @@
         site = self.targetSite
         imagepage = pywikibot.FilePage(site, filename)  # normalizes filename
         imagepage.text = self.description
+        if not self.summary: self.summary = self.description
 
         pywikibot.output(u'Uploading file to %s via API...' % site)
 
@@ -407,7 +411,8 @@
             if self.uploadByUrl:
                 success = site.upload(imagepage, source_url=file_url,
                                       ignore_warnings=apiIgnoreWarnings,
-                                      _file_key=_file_key, _offset=_offset)
+                                      _file_key=_file_key, _offset=_offset,
+                                      comment=self.summary)
             else:
                 if "://" in file_url:
                     temp = self.read_file_content(file_url)
@@ -416,7 +421,8 @@
                 success = site.upload(imagepage, source_filename=temp,
                                       ignore_warnings=apiIgnoreWarnings,
                                       chunk_size=self.chunk_size,
-                                      _file_key=_file_key, _offset=_offset)
+                                      _file_key=_file_key, _offset=_offset,
+                                      comment=self.summary)
 
         except pywikibot.data.api.APIError as error:
             if error.code == u'uploaddisabled':
diff --git a/scripts/upload.py b/scripts/upload.py
index 0eee51d..26fc5e0 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -29,6 +29,7 @@
                 the 'exists' warning.
   -recursive    When the filename is a directory it also uploads the files from
                 the subdirectories.
+  -summary      Pick a custom edit summary for the bot.
 
 It is possible to combine -abortonwarn and -ignorewarn so that if the specific
 warning is given it won't apply the general one but more specific one. So if it
@@ -75,6 +76,7 @@
     """
     url = u''
     description = []
+    summary = None
     keepFilename = False
     always = False
     useFilename = None
@@ -100,6 +102,8 @@
                 keepFilename = True
             elif arg.startswith('-filename:'):
                 useFilename = arg[10:]
+            elif arg.startswith('-summary'):
+                summary = arg[9:]
             elif arg.startswith('-noverify'):
                 verifyDescription = False
             elif arg.startswith('-abortonwarn'):
@@ -181,7 +185,7 @@
     else:
         url = [url]
     bot = UploadRobot(url, description=description, useFilename=useFilename,
-                      keepFilename=keepFilename,
+                      keepFilename=keepFilename, summary=summary,
                       verifyDescription=verifyDescription,
                       aborts=aborts, ignoreWarning=ignorewarn,
                       chunk_size=chunk_size, always=always)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifc3fc7cb853f81735d98e9fceef341f0df87d39e
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploa...@gmail.com>
Gerrit-Reviewer: Framawiki <framaw...@tools.wmflabs.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to