Nullzero has uploaded a new change for review. https://gerrit.wikimedia.org/r/180729
Change subject: [WIP] Introduce appendtext / prependtext ...................................................................... [WIP] Introduce appendtext / prependtext Bug: T57054 Change-Id: I811b019523f21b014d78b514cbbac11573346e5f --- M pywikibot/site.py M scripts/i18n 2 files changed, 51 insertions(+), 29 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/29/180729/1 diff --git a/pywikibot/site.py b/pywikibot/site.py index 8f82568..3d7f36e 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3792,9 +3792,7 @@ } @must_be(group='user') - def editpage(self, page, summary, minor=True, notminor=False, - bot=True, recreate=True, createonly=False, nocreate=False, - watch=None): + def editpage(self, page, summary, **kwargs): """Submit an edited Page object to be saved to the wiki. @param page: The Page to be saved; its .text property will be used @@ -3818,42 +3816,66 @@ @return: True if edit succeeded, False if it failed """ - text = page.text - if text is None: + kwargs['text'] = page.text + kwargs['recreate'] = kwargs.get('recreate', True) + if kwargs['text'] is None: raise Error("editpage: no text to be saved") try: lastrev = page.latestRevision() except NoPage: lastrev = None - if not recreate: + if not kwargs['recreate']: raise - token = self.tokens['edit'] - self.lock_page(page) - params = dict(action="edit", - title=page.title(withSection=False), - text=text, token=token, summary=summary) - if bot: - params['bot'] = "" if lastrev is not None: if lastrev not in page._revisions: self.loadrevisions(page) - params['basetimestamp'] = page._revisions[lastrev].timestamp - if minor: + kwargs['basetimestamp'] = page._revisions[lastrev].timestamp + return self.editpage_submit('edit', page, summary, **kwargs) + + def prependpage(self, page, text, summary, **kwargs): + kwargs['prependtext'] = text + return self.editpage_submit('prepend', page, summary, **kwargs) + + def appendpage(self, page, text, summary, **kwargs): + kwargs['appendtext'] = text + return self.editpage_submit('append', page, summary, **kwargs) + + def editpage_submit(self, meth, page, summary, **kwargs): + token = self.tokens['edit'] + params = dict(action="edit", + title=page.title(withSection=False), + token=token, summary=summary) + if 'text' in kwargs: + params['text'] = kwargs['text'] + if 'prependtext' in kwargs: + params['prependtext'] = kwargs['prependtext'] + if 'appendtext' in kwargs: + params['appendtext'] = kwargs['appendtext'] + if 'basetimestamp' in kwargs: + params['basetimestamp'] = kwargs['basetimestamp'] + if kwargs.get('bot', True): + params['bot'] = "" + if kwargs.get('minor', True): params['minor'] = "" - elif notminor: + elif kwargs.get('notminor', False): params['notminor'] = "" - if recreate: + if kwargs.get('recreate', True): params['recreate'] = "" - if createonly: + if kwargs.get('createonly', False): params['createonly'] = "" - if nocreate: + if kwargs.get('nocreate', False): params['nocreate'] = "" + # Note: the default of this parameter is set in editpage() as well + # If it needs to be changed, don't forget to change editpage() + watch = kwargs.get('watch', None) if watch in ["watch", "unwatch", "preferences", "nochange"]: params['watchlist'] = watch elif watch: pywikibot.warning( u"editpage: Invalid watch value '%(watch)s' ignored." % locals()) + + self.lock_page(page) req = api.Request(site=self, **params) while True: try: @@ -3864,8 +3886,8 @@ self.unlock_page(page) if err.code.endswith("anon") and self.logged_in(): pywikibot.debug( - u"editpage: received '%s' even though bot is logged in" - % err.code, + u"%spage: received '%s' even though bot is logged in" + % (meth, err.code), _logger) if err.code in self._ep_errors: if isinstance(self._ep_errors[err.code], basestring): @@ -3879,8 +3901,8 @@ else: raise self._ep_errors[err.code](page) pywikibot.debug( - u"editpage: Unexpected error code '%s' received." - % err.code, + u"%spage: Unexpected error code '%s' received." + % (meth, err.code), _logger) raise assert ("edit" in result and "result" in result["edit"]), result @@ -3917,22 +3939,22 @@ else: self.unlock_page(page) pywikibot.error( - u"editpage: unknown CAPTCHA response %s, " + u"%spage: unknown CAPTCHA response %s, " u"page not saved" - % captcha) + % (meth, captcha)) return False elif 'spamblacklist' in result['edit']: raise SpamfilterError(page, result['edit']['spamblacklist']) else: self.unlock_page(page) - pywikibot.error(u"editpage: unknown failure reason %s" - % str(result)) + pywikibot.error(u"%spage: unknown failure reason %s" + % (meth, str(result))) return False else: self.unlock_page(page) pywikibot.error( - u"editpage: Unknown result code '%s' received; " - u"page not saved" % result["edit"]["result"]) + u"%spage: Unknown result code '%s' received; " + u"page not saved" % (meth, result["edit"]["result"])) pywikibot.log(str(result)) return False diff --git a/scripts/i18n b/scripts/i18n index 4fb2f0d..3b1a255 160000 --- a/scripts/i18n +++ b/scripts/i18n -Subproject commit 4fb2f0d76bdd0a9106f5a8aa6ec95d59c1ba7a74 +Subproject commit 3b1a25590c496ebb5501d27d00dff7f970b5513f -- To view, visit https://gerrit.wikimedia.org/r/180729 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I811b019523f21b014d78b514cbbac11573346e5f Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Nullzero <nullzero.f...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits