jenkins-bot has submitted this change and it was merged.
Change subject: Support initial text separate from summary ......................................................................
Support initial text separate from summary
When a new file is uploaded, the page text defaults to the summary, or vice versa. This change should provide the ability to have them different.
Change-Id: Idd927c0e3256ca610ae418afdfbbaa3afb5ba9d9 --- M pywikibot/site.py 1 file changed, 10 insertions(+), 3 deletions(-)
Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index 1c0b144..59eebf5 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3037,7 +3037,7 @@ return self.getFilesFromAnHash(hash_found)
def upload(self, imagepage, source_filename=None, source_url=None, - comment=None, watch=False, ignore_warnings=False): + comment=None, text=None, watch=False, ignore_warnings=False): """Upload a file to the wiki.
Either source_filename or source_url, but not both, must be provided. @@ -3048,6 +3048,9 @@ @param source_url: URL of the file to be uploaded @param comment: Edit summary; if this is not provided, then imagepage.text will be used. An empty summary is not permitted. + This may also serve as the initial page text (see below). + @param text: Initial page text; if this is not set, then + imagepage.text will be used, or comment. @param watch: If true, add imagepage to the bot user's watchlist @param ignore_warnings: if true, ignore API warnings and force upload (for example, to overwrite an existing file); default False @@ -3089,6 +3092,10 @@ raise ValueError( "APISite.upload: cannot upload file without a summary/description." ) + if text is None: + text = imagepage.text + if not text: + text = comment token = self.token(imagepage, "edit") if source_filename: # upload local file @@ -3102,7 +3109,7 @@ req = api.Request(site=self, action="upload", token=token, filename=imagepage.title(withNamespace=False), file=source_filename, comment=comment, - mime=True) + text=text, mime=True) else: # upload by URL if "upload_by_url" not in self.userinfo["rights"]: @@ -3111,7 +3118,7 @@ % (self.user(), self)) req = api.Request(site=self, action="upload", token=token, filename=imagepage.title(withNamespace=False), - url=source_url, comment=comment) + url=source_url, comment=comment, text=text) if watch: req["watch"] = "" if ignore_warnings: