Hazard-SJ has uploaded a new change for review.
https://gerrit.wikimedia.org/r/82560
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, 11 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/60/82560/1
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 1c0b144..4afabf7 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,10 @@
@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 also serves as the initial page text if neither
+ imagepage.text nor text is provided.
+ @param text: Initial page text; if this is not provided, then
+ imagepage.text will be used if provided, else 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 +3093,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 +3110,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 +3119,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:
--
To view, visit https://gerrit.wikimedia.org/r/82560
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd927c0e3256ca610ae418afdfbbaa3afb5ba9d9
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Hazard-SJ <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits