jenkins-bot has submitted this change and it was merged. Change subject: Use 'summary' instead of 'comment' in page.save() ......................................................................
Use 'summary' instead of 'comment' in page.save() This change is necessary because firstly 'summary' is being used in mediawiki's API and so people tend to use summary more than comment. Secondly since currently summary is automatically being passed to API, using summary instead of comment currently can cause odd behavior. [1] Thirdly comment is not a correct word (or the best word) to describe an edit summary. All usages of Page.save(), Page.put(), Bot.userPut(), Bot.put_current() Page.put_async() should change this argument. [1]: >>> page.save(summary='ok') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pywikibot/tools/__init__.py", line 949, in wrapper return obj(*__args, **__kw) File "pywikibot/page.py", line 1042, in save **kwargs) File "pywikibot/page.py", line 1048, in _save err = None TypeError: editpage() got multiple values for keyword argument 'summary' Change-Id: Ib5fde07a587f82a11dd1fd1e8c326883cd6616ea --- M pywikibot/bot.py M pywikibot/page.py M scripts/basic.py M scripts/blockreview.py M scripts/catall.py M scripts/category.py M scripts/checkimages.py M scripts/commons_link.py M scripts/commonscat.py M scripts/cosmetic_changes.py M scripts/create_categories.py M scripts/editarticle.py M scripts/imagetransfer.py M scripts/interwiki.py M scripts/isbn.py M scripts/lonelypages.py M scripts/noreferences.py M scripts/pagefromfile.py M scripts/piper.py M scripts/reflinks.py M scripts/selflink.py M scripts/solve_disambiguation.py M scripts/transferbot.py M scripts/unusedfiles.py M scripts/welcome.py M tests/api_tests.py 26 files changed, 54 insertions(+), 50 deletions(-) Approvals: XZise: Looks good to me, but someone else must approve Mpaa: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 446e8e1..4088f06 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -40,7 +40,7 @@ from pywikibot import backports from pywikibot import config from pywikibot import version -from pywikibot.tools import deprecated +from pywikibot.tools import deprecated, deprecated_args if sys.version_info[0] > 2: unicode = str @@ -1092,6 +1092,7 @@ return True + @deprecated_args(comment='summary') def userPut(self, page, oldtext, newtext, **kwargs): """ Save a new revision of a page, with user confirmation as required. @@ -1104,7 +1105,7 @@ Keyword args used: * 'async' - passed to page.save - * 'comment' - passed to page.save + * 'summary' - passed to page.save * 'show_diff' - show changes between oldtext and newtext (enabled) * 'ignore_save_related_errors' - report and ignore (disabled) * 'ignore_server_errors' - report and ignore (disabled) @@ -1121,8 +1122,8 @@ if show_diff: pywikibot.showDiff(oldtext, newtext) - if 'comment' in kwargs: - pywikibot.output(u'Comment: %s' % kwargs['comment']) + if 'summary' in kwargs: + pywikibot.output(u'Edit summary: %s' % kwargs['summary']) page.text = newtext self._save_page(page, page.save, **kwargs) @@ -1291,6 +1292,7 @@ self.current_page = page self.treat_page() + @deprecated_args(comment='summary') def put_current(self, new_text, ignore_save_related_errors=None, ignore_server_errors=None, **kwargs): """ diff --git a/pywikibot/page.py b/pywikibot/page.py index 5f58dee..781c3a0 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -993,14 +993,14 @@ # no restricting template found return True - @deprecate_arg('sysop', None) - def save(self, comment=None, watch=None, minor=True, botflag=None, + @deprecated_args(comment='summary', sysop=None) + def save(self, summary=None, watch=None, minor=True, botflag=None, force=False, async=False, callback=None, **kwargs): """Save the current contents of page's text to the wiki. - @param comment: The edit summary for the modification (optional, but + @param summary: The edit summary for the modification (optional, but most wikis strongly encourage its use) - @type comment: unicode + @type summary: unicode @param watch: if True, add or if False, remove this Page to/from bot user's watchlist; if None (default), follow bot account's default settings @@ -1021,8 +1021,8 @@ successful. """ - if not comment: - comment = config.default_edit_summary + if not summary: + summary = config.default_edit_summary if watch is None: watchval = None elif watch: @@ -1033,23 +1033,23 @@ raise pywikibot.OtherPageSaveError( self, "Editing restricted by {{bots}} template") if async: - pywikibot.async_request(self._save, comment=comment, minor=minor, + pywikibot.async_request(self._save, summary=summary, minor=minor, watchval=watchval, botflag=botflag, async=async, callback=callback, **kwargs) else: - self._save(comment=comment, minor=minor, watchval=watchval, + self._save(summary=summary, minor=minor, watchval=watchval, botflag=botflag, async=async, callback=callback, **kwargs) - def _save(self, comment, minor, watchval, botflag, async, callback, + def _save(self, summary, minor, watchval, botflag, async, callback, **kwargs): """Helper function for save().""" err = None link = self.title(asLink=True) if config.cosmetic_changes: - comment = self._cosmetic_changes_hook(comment) or comment + summary = self._cosmetic_changes_hook(summary) or summary try: - done = self.site.editpage(self, summary=comment, minor=minor, + done = self.site.editpage(self, summary=summary, minor=minor, watch=watchval, bot=botflag, **kwargs) if not done: pywikibot.warning(u"Page %s not saved" % link) @@ -1106,7 +1106,8 @@ comment += i18n.twtranslate(self.site, 'cosmetic_changes-append') return comment - def put(self, newtext, comment=u'', watchArticle=None, minorEdit=True, + @deprecated_args(comment='summary') + def put(self, newtext, summary=u'', watchArticle=None, minorEdit=True, botflag=None, force=False, async=False, callback=None, **kwargs): """Save the page with the contents of the first argument as the text. @@ -1119,11 +1120,12 @@ """ self.text = newtext - self.save(comment=comment, watch=watchArticle, minor=minorEdit, + self.save(summary=summary, watch=watchArticle, minor=minorEdit, botflag=botflag, force=force, async=async, callback=callback, **kwargs) - def put_async(self, newtext, comment=u'', watchArticle=None, + @deprecated_args(comment='summary') + def put_async(self, newtext, summary=u'', watchArticle=None, minorEdit=True, botflag=None, force=False, callback=None, **kwargs): """Put page on queue to be saved to wiki asynchronously. @@ -1134,7 +1136,7 @@ backwards-compatibility. """ - self.put(newtext, comment=comment, watchArticle=watchArticle, + self.put(newtext, summary=summary, watchArticle=watchArticle, minorEdit=minorEdit, botflag=botflag, force=force, async=True, callback=callback, **kwargs) @@ -1566,7 +1568,7 @@ if answer == 'y': template = '{{delete|1=%s}}\n' % reason self.text = template + self.text - return self.save(comment=reason) + return self.save(summary=reason) def loadDeletedRevisions(self, step=None, total=None): """Retrieve deleted revisions for this Page. diff --git a/scripts/basic.py b/scripts/basic.py index b6d73be..23dac2b 100755 --- a/scripts/basic.py +++ b/scripts/basic.py @@ -119,7 +119,7 @@ try: page.text = text # Save the page - page.save(comment=comment or self.comment, + page.save(summary=comment or self.comment, minor=minorEdit, botflag=botflag) except pywikibot.LockedPage: pywikibot.output(u"Page %s is locked; skipping." diff --git a/scripts/blockreview.py b/scripts/blockreview.py index d78c9f9..1de8930 100755 --- a/scripts/blockreview.py +++ b/scripts/blockreview.py @@ -277,7 +277,7 @@ page.text = text try: # Save the page - page.save(comment=comment, minorEdit=minorEdit, + page.save(summary=comment, minorEdit=minorEdit, botflag=botflag) except pywikibot.LockedPage: pywikibot.output(u"Page %s is locked; skipping." diff --git a/scripts/catall.py b/scripts/catall.py index 9fd468c..29bb9a5 100755 --- a/scripts/catall.py +++ b/scripts/catall.py @@ -76,7 +76,7 @@ pllist.append(pywikibot.Page(site, cattitle)) page.put_async(textlib.replaceCategoryLinks(page.get(), pllist, site=page.site), - comment=i18n.twtranslate(site.code, 'catall-changing')) + summary=i18n.twtranslate(site.code, 'catall-changing')) def main(*args): diff --git a/scripts/category.py b/scripts/category.py index dd8fe46..0360760 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -376,7 +376,7 @@ {'newcat': catpl.title(withNamespace=False)}) try: self.userPut(self.current_page, old_text, text, - comment=comment, minor=True, botflag=True) + summary=comment, minor=True, botflag=True) except pywikibot.PageSaveRelatedError as error: pywikibot.output(u'Page %s not saved: %s' % (self.current_page.title(asLink=True), @@ -807,7 +807,7 @@ pywikibot.output(u'Page %s already exists, aborting.' % self.list.title()) else: - self.list.put(listString, comment=self.editSummary) + self.list.put(listString, summary=self.editSummary) class CategoryTidyRobot(pywikibot.Bot): diff --git a/scripts/checkimages.py b/scripts/checkimages.py index a477953..13e06a3 100755 --- a/scripts/checkimages.py +++ b/scripts/checkimages.py @@ -735,7 +735,7 @@ pywikibot.output(self.commImage) try: reportPageObject.put(self.newtext + "\n" + reportPageText, - comment=self.commImage) + summary=self.commImage) except pywikibot.LockedPage: pywikibot.output(u'File is locked. Skipping.') return @@ -815,7 +815,7 @@ newText = testoattuale + self.head + self.notification try: - self.talk_page.put(newText, comment=commentox, minorEdit=False) + self.talk_page.put(newText, summary=commentox, minorEdit=False) except pywikibot.LockedPage: pywikibot.output(u'Talk page blocked, skip.') @@ -1165,7 +1165,7 @@ if addings: # Adding the name of the image in the report if not done already rep_text = rep_text % image_to_report - another_page.put(text_get + rep_text, comment=com, force=True, + another_page.put(text_get + rep_text, summary=com, force=True, minorEdit=False) pywikibot.output(u"...Reported...") reported = True diff --git a/scripts/commons_link.py b/scripts/commons_link.py index c8ca521..17ed26f 100755 --- a/scripts/commons_link.py +++ b/scripts/commons_link.py @@ -91,7 +91,7 @@ 'commons_link%s-template-added' % ('', '-cat')[catmode]) try: - self.userPut(page, oldText, text, comment=comment) + self.userPut(page, oldText, text, summary=comment) except pywikibot.EditConflict: pywikibot.output( u'Skipping %s because of edit conflict' diff --git a/scripts/commonscat.py b/scripts/commonscat.py index 75beea1..c921e7e 100755 --- a/scripts/commonscat.py +++ b/scripts/commonscat.py @@ -369,7 +369,7 @@ 'commonscat-msg_change', {'oldcat': oldcat, 'newcat': newcat}) - self.userPut(page, page.text, newtext, comment=comment, + self.userPut(page, page.text, newtext, summary=comment, ignore_save_related_errors=True) def findCommonscatLink(self, page=None): diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py index f58985f..970cfbc 100755 --- a/scripts/cosmetic_changes.py +++ b/scripts/cosmetic_changes.py @@ -977,7 +977,7 @@ changedText = ccToolkit.change(self.current_page.get()) if changedText is not False: self.put_current(new_text=changedText, - comment=self.getOption('comment'), + summary=self.getOption('comment'), async=self.getOption('async')) except pywikibot.LockedPage: pywikibot.output("Page %s is locked?!" diff --git a/scripts/create_categories.py b/scripts/create_categories.py index ac6f4e4..0981776 100755 --- a/scripts/create_categories.py +++ b/scripts/create_categories.py @@ -67,7 +67,7 @@ if not newpage.exists(): pywikibot.output(newpage.title()) try: - self.userPut(newpage, '', newtext, comment=self.comment) + self.userPut(newpage, '', newtext, summary=self.comment) except pywikibot.EditConflict: pywikibot.output(u'Skipping %s due to edit conflict' % newpage.title()) except pywikibot.ServerError: diff --git a/scripts/editarticle.py b/scripts/editarticle.py index ca7b850..db48b77 100755 --- a/scripts/editarticle.py +++ b/scripts/editarticle.py @@ -105,7 +105,7 @@ comment = i18n.twtranslate(pywikibot.Site(), 'editarticle-edit', {'description': changes}) try: - self.page.put(new, comment=comment, minorEdit=False, + self.page.put(new, summary=comment, minorEdit=False, watchArticle=self.options.watch) except pywikibot.EditConflict: self.handle_edit_conflict(new) diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py index 1761790..c88d07e 100755 --- a/scripts/imagetransfer.py +++ b/scripts/imagetransfer.py @@ -227,7 +227,7 @@ sourceImagePage.put(sourceImagePage.get() + '\n\n' + nowCommonsTemplate[sourceSite.lang] % targetFilename, - comment=nowCommonsMessage[sourceSite.lang]) + summary=nowCommonsMessage[sourceSite.lang]) def showImageList(self, imagelist): for i in range(len(imagelist)): diff --git a/scripts/interwiki.py b/scripts/interwiki.py index f98d9a6..1985406 100755 --- a/scripts/interwiki.py +++ b/scripts/interwiki.py @@ -2006,9 +2006,9 @@ while True: try: if globalvar.async: - page.put_async(newtext, comment=mcomment) + page.put_async(newtext, summary=mcomment) else: - page.put(newtext, comment=mcomment) + page.put(newtext, summary=mcomment) except pywikibot.LockedPage: pywikibot.output(u'Page %s is locked. Skipping.' % page) raise SaveError(u'Locked') diff --git a/scripts/isbn.py b/scripts/isbn.py index 721ed2e..1ddbe2e 100755 --- a/scripts/isbn.py +++ b/scripts/isbn.py @@ -1498,7 +1498,7 @@ if self.getOption('format'): new_text = self.isbnR.sub(_hyphenateIsbnNumber, new_text) try: - self.userPut(page, page.text, new_text, comment=self.comment) + self.userPut(page, page.text, new_text, summary=self.comment) except pywikibot.EditConflict: pywikibot.output(u'Skipping %s because of edit conflict' % page.title()) diff --git a/scripts/lonelypages.py b/scripts/lonelypages.py index 72b06fb..d3ec6e4 100755 --- a/scripts/lonelypages.py +++ b/scripts/lonelypages.py @@ -189,7 +189,7 @@ # Ok, the page need the template. Let's put it there! # Adding the template in the text newtxt = u"%s\n%s" % (self.template, oldtxt) - self.userPut(page, oldtxt, newtxt, comment=self.comment) + self.userPut(page, oldtxt, newtxt, summary=self.comment) def main(*args): diff --git a/scripts/noreferences.py b/scripts/noreferences.py index 3fa562a..24f3669 100755 --- a/scripts/noreferences.py +++ b/scripts/noreferences.py @@ -663,7 +663,7 @@ if self.lacksReferences(text): newText = self.addReferences(text) try: - self.userPut(page, page.text, newText, comment=self.comment) + self.userPut(page, page.text, newText, summary=self.comment) except pywikibot.EditConflict: pywikibot.output(u'Skipping %s because of edit conflict' % page.title()) diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py index 94cd310..209355a 100755 --- a/scripts/pagefromfile.py +++ b/scripts/pagefromfile.py @@ -160,7 +160,7 @@ config.default_edit_summary = '' self.userPut(page, page.text, contents, - comment=comment, + summary=comment, minor=self.getOption('minor'), show_diff=False, ignore_save_related_errors=True) diff --git a/scripts/piper.py b/scripts/piper.py index b015a0c..eb0c431 100755 --- a/scripts/piper.py +++ b/scripts/piper.py @@ -105,7 +105,7 @@ text = self.pipe(program, text) # only save if something was changed - self.put_current(text, comment=self.getOption('comment')) + self.put_current(text, summary=self.getOption('comment')) def main(*args): diff --git a/scripts/reflinks.py b/scripts/reflinks.py index 009e808..197c445 100755 --- a/scripts/reflinks.py +++ b/scripts/reflinks.py @@ -758,7 +758,7 @@ new_text = self.deduplicator.process(new_text) - self.userPut(page, page.text, new_text, comment=self.msg, + self.userPut(page, page.text, new_text, summary=self.msg, ignore_save_related_errors=True, ignore_server_errors=True) diff --git a/scripts/selflink.py b/scripts/selflink.py index bcd284c..b577d9f 100755 --- a/scripts/selflink.py +++ b/scripts/selflink.py @@ -162,7 +162,7 @@ else: pywikibot.showDiff(oldText, page.text) comment = i18n.twtranslate(page.site, "selflink-remove") - page.save(async=True, comment=comment) + page.save(async=True, summary=comment) except pywikibot.NoPage: pywikibot.output(u"Page %s does not exist." % page.title(asLink=True)) diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index b91f0b3..846f1a6 100755 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -578,7 +578,7 @@ redir_text = '#%s [[%s]]' \ % (self.mysite.redirect(), target) try: - refPage.put_async(redir_text, comment=self.comment) + refPage.put_async(redir_text, summary=self.comment) except pywikibot.PageNotSaved as error: pywikibot.output(u'Page not saved: %s' % error.args) else: @@ -843,7 +843,7 @@ self.setSummaryMessage(disambPage, new_targets, unlink_counter, dn) try: - refPage.put_async(text, comment=self.comment) + refPage.put_async(text, summary=self.comment) except pywikibot.LockedPage: pywikibot.output(u'Page not saved: page is locked') except pywikibot.PageNotSaved as error: diff --git a/scripts/transferbot.py b/scripts/transferbot.py index 61dfbfd..1a2129f 100755 --- a/scripts/transferbot.py +++ b/scripts/transferbot.py @@ -160,10 +160,10 @@ historytable = page.getVersionHistoryTable() pywikibot.log("Putting page text.") - targetpage.put(text, comment=summary) + targetpage.put(text, summary=summary) pywikibot.log("Putting edit history.") - edithistpage.put(historytable, comment=summary) + edithistpage.put(historytable, summary=summary) if __name__ == "__main__": diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py index 61957a1..1db7922 100755 --- a/scripts/unusedfiles.py +++ b/scripts/unusedfiles.py @@ -101,7 +101,7 @@ oldtext = text text += apptext - self.userPut(page, oldtext, text, comment=self.summary) + self.userPut(page, oldtext, text, summary=self.summary) def main(*args): diff --git a/scripts/welcome.py b/scripts/welcome.py index cefbf93..cbd3dca 100755 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -625,7 +625,7 @@ com = i18n.twtranslate(self.site, 'welcome-bad_username') if rep_text != '': - rep_page.put(text_get + rep_text, comment=com, force=True, + rep_page.put(text_get + rep_text, summary=com, force=True, minorEdit=True) showStatus(5) pywikibot.output(u'Reported') diff --git a/tests/api_tests.py b/tests/api_tests.py index 59c20dc..b0f88af 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -700,7 +700,7 @@ page = pywikibot.Page(site, 'Pywikibot bad token test') page.text = ('This page is testing whether pywikibot-core rerequests ' 'a token when a badtoken error was received.') - page.save(comment='Bad token test') + page.save(summary='Bad token test') if __name__ == '__main__': -- To view, visit https://gerrit.wikimedia.org/r/208026 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib5fde07a587f82a11dd1fd1e8c326883cd6616ea Gerrit-PatchSet: 4 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl> Gerrit-Reviewer: Mpaa <mpaa.w...@gmail.com> Gerrit-Reviewer: Russell Blau <russb...@imapmail.org> Gerrit-Reviewer: XZise <commodorefabia...@gmx.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits