jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/348209 )
Change subject: [IMPR] Unify edit summary arguments
......................................................................
[IMPR] Unify edit summary arguments
- rename edit summary argument from 'comment' to 'summary' for
_cosmetic_changes_hook and change_category methods
- Now _cosmetic_changes_hook always returns the edit summary either modified
or unchanged. This is due to PEP8: "Either all return statements in a
function should return an expression, or none of them should."
- add doc string for _cosmetic_changes_hook method
Change-Id: I0ba98b74a2cc52af902cbe274fd7a7e8bd81626c
---
M pywikibot/page.py
1 file changed, 20 insertions(+), 12 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 60b7b7a..6295b21 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1260,7 +1260,7 @@
"""Helper function for save()."""
link = self.title(asLink=True)
if cc or cc is None and config.cosmetic_changes:
- summary = self._cosmetic_changes_hook(summary) or summary
+ summary = self._cosmetic_changes_hook(summary)
done = self.site.editpage(self, summary=summary, minor=minor,
watch=watch, bot=botflag, **kwargs)
@@ -1271,10 +1271,18 @@
if not quiet:
pywikibot.output('Page %s saved' % link)
- def _cosmetic_changes_hook(self, comment):
+ def _cosmetic_changes_hook(self, summary):
+ """The cosmetic changes hook.
+
+ @param summary: The current edit summary.
+ @type summary: str
+ @return: Modified edit summary if cosmetic changes has been done,
+ else the old edit summary.
+ @rtype: str
+ """
if self.isTalkPage() or \
pywikibot.calledModuleName() in config.cosmetic_changes_deny_script:
- return
+ return summary
family = self.site.family.name
if config.cosmetic_changes_mylang_only:
cc = ((family == config.family and
@@ -1287,7 +1295,7 @@
(family in list(config.cosmetic_changes_disable.keys()) and
self.site.lang in config.cosmetic_changes_disable[family]))
if not cc:
- return
+ return summary
old = self.text
pywikibot.log(u'Cosmetic changes for %s-%s enabled.'
@@ -1300,12 +1308,11 @@
pageTitle=self.title(),
ignore=CANCEL_MATCH)
self.text = ccToolkit.change(old)
- if comment and \
- old.strip().replace('\r\n',
- '\n') != self.text.strip().replace('\r\n', '\n'):
+ if summary and old.strip().replace(
+ '\r\n', '\n') != self.text.strip().replace('\r\n', '\n'):
from pywikibot import i18n
- comment += i18n.twtranslate(self.site, 'cosmetic_changes-append')
- return comment
+ summary += i18n.twtranslate(self.site, 'cosmetic_changes-append')
+ return summary
@deprecate_arg('async', 'asynchronous') # T106230
@deprecated_args(comment='summary')
@@ -2042,7 +2049,8 @@
if answer == 'y':
return self.site.protect(self, protections, reason, **kwargs)
- def change_category(self, oldCat, newCat, comment=None, sortKey=None,
+ @deprecated_args(comment='summary')
+ def change_category(self, oldCat, newCat, summary=None, sortKey=None,
inPlace=True, include=[]):
"""
Remove page from oldCat and add it to newCat.
@@ -2052,7 +2060,7 @@
@param newCat: category to be added, if any
@type newCat: Category or None
- @param comment: string to use as an edit summary
+ @param summary: string to use as an edit summary
@param sortKey: sortKey to use for the added category.
Unused if newCat is None, or if inPlace=True
@@ -2116,7 +2124,7 @@
if oldtext != newtext:
try:
- self.put(newtext, comment)
+ self.put(newtext, summary)
return True
except pywikibot.PageSaveRelatedError as error:
pywikibot.output(u'Page %s not saved: %s'
--
To view, visit https://gerrit.wikimedia.org/r/348209
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0ba98b74a2cc52af902cbe274fd7a7e8bd81626c
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/348700 )
Change subject: Update README.rst
......................................................................
Update README.rst
- table2wiki.py is already part of the framework
Change-Id: I1a156de35ca2d0f08f7f00006d7fddd37b343df3
---
M scripts/README.rst
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/scripts/README.rst b/scripts/README.rst
index 4483eeb..86f0bde 100644
--- a/scripts/README.rst
+++ b/scripts/README.rst
@@ -226,9 +226,9 @@
| #statistics_in_wikitable.py| This bot renders statistics provided by |
| | [[Special:Statistics]] in a table on a wiki page. |
| | Thus it creates and updates a statistics wikitable. |
- +----------------------------+-----------------------------------------------------+
- | #table2wiki.py | Semi-automatic converting HTML-tables to wiki-tables|
+------------------------+---+-----------------------------------------------------+
+ | table2wiki.py | Semi-automatic converting HTML-tables to wiki-tables |
+ +------------------------+---------------------------------------------------------+
| template.py | change one template (that is {{...}}) into another. |
+------------------------+---------------------------------------------------------+
| templatecount.py | Display the list of pages transcluding a given list |
--
To view, visit https://gerrit.wikimedia.org/r/348700
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1a156de35ca2d0f08f7f00006d7fddd37b343df3
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( 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(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/specialbots.py b/pywikibot/specialbots.py
index 4694857..72e079c 100644
--- a/pywikibot/specialbots.py
+++ b/pywikibot/specialbots.py
@@ -43,7 +43,7 @@
useFilename=None, keepFilename=False,
verifyDescription=True, ignoreWarning=False,
targetSite=None, uploadByUrl=False, aborts=[], chunk_size=0,
- **kwargs):
+ summary=None, **kwargs):
"""
Constructor.
@@ -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')
@@ -407,7 +410,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 +420,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..2d306e4 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'):
@@ -184,7 +188,8 @@
keepFilename=keepFilename,
verifyDescription=verifyDescription,
aborts=aborts, ignoreWarning=ignorewarn,
- chunk_size=chunk_size, always=always)
+ chunk_size=chunk_size, always=always,
+ summary=summary)
bot.run()
if __name__ == "__main__":
--
To view, visit https://gerrit.wikimedia.org/r/348448
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc3fc7cb853f81735d98e9fceef341f0df87d39e
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploader(a)gmail.com>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: Gerrit Patch Uploader <gerritpatchuploader(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>