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:
--
To view, visit https://gerrit.wikimedia.org/r/82560
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idd927c0e3256ca610ae418afdfbbaa3afb5ba9d9
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Hazard-SJ <hazard_sj(a)yahoo.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot
Xqt has submitted this change and it was merged.
Change subject: Fix auto-summary in delete.py
......................................................................
Fix auto-summary in delete.py
mysite was not defined. pywikibot.handleArgs is guaranteed to return
a list (as opposed to a generator) after parsing all global arguments
(such as -lang and -family). This means it's safe to call
pywikibot.getSite immediately after handleArgs, but before handling
local arguments.
Change-Id: I0bd76806e460fec200973a712370e459c9189ea7
Fixes-Change-Id: I386328c62b1bbeb7022a620f8e95d25a67686371
---
M delete.py
1 file changed, 6 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/delete.py b/delete.py
index d1e2c13..b51a594 100644
--- a/delete.py
+++ b/delete.py
@@ -75,7 +75,10 @@
generator = None
# read command line parameters
- for arg in pywikibot.handleArgs():
+ localargs = pywikibot.handleArgs()
+ mysite = pywikibot.getSite()
+
+ for arg in localargs:
if arg == '-always':
always = True
elif arg.startswith('-summary'):
@@ -105,7 +108,7 @@
summary = i18n.twtranslate(mysite, 'delete-referring-pages', {'page': pageName})
elif arg.startswith('-file'):
summary = i18n.twtranslate(mysite, 'delete-from-file')
- mysite = pywikibot.getSite()
+
if doImages:
if not summary:
summary = i18n.twtranslate(mysite, 'delete-images',
@@ -131,4 +134,4 @@
try:
main()
finally:
- pywikibot.stopme()
\ No newline at end of file
+ pywikibot.stopme()
--
To view, visit https://gerrit.wikimedia.org/r/83808
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0bd76806e460fec200973a712370e459c9189ea7
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Update Wikibase tests for upcoming API change
......................................................................
Update Wikibase tests for upcoming API change
Do not merge until Wikibase has been updated to use upper case IDs.
Change-Id: I086b2ca3ec15aed4a8bf9a0fbda88b91c5fce5a1
---
M tests/wikibase_tests.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 3896392..ef39990 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -28,7 +28,7 @@
repo = site.data_repository()
item = pywikibot.ItemPage.fromPage(mainpage)
self.assertType(item, pywikibot.ItemPage)
- self.assertEqual(item.getID(), 'q5296')
+ self.assertEqual(item.getID(), 'Q5296')
self.assertEqual(item.title(), 'Q5296')
self.assertTrue('en' in item.labels)
self.assertEqual(item.labels['en'], 'Main Page')
--
To view, visit https://gerrit.wikimedia.org/r/83663
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I086b2ca3ec15aed4a8bf9a0fbda88b91c5fce5a1
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Use the language of the page, not necessarily the general site
......................................................................
Use the language of the page, not necessarily the general site
It's possible that the user specificies a generator like
-cat:zh:Category:Blah", in which case the value of
pywikibot.Site().language() may not be "zh", depending
on the user's config. It's also possible that in the future
a generator will yield pages on multiple projects, so this
guards against that as well.
Change-Id: Ic1f10118a2dff93b71861b7ea97f7da22908cb04
---
M scripts/claimit.py
M scripts/harvest_template.py
2 files changed, 46 insertions(+), 29 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/claimit.py b/scripts/claimit.py
index 0f50db0..e72e804 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -33,23 +33,29 @@
self.generator = generator
self.claims = claims
self.repo = pywikibot.Site().data_repository()
- self.source = None
- self.setSource(pywikibot.Site().language())
+ self.cacheSources()
- def setSource(self, lang):
+ def getSource(self, lang):
"""
- Get the source
+ Get the source for the specified language,
+ if possible
"""
- page = pywikibot.Page(self.repo, 'Wikidata:List of wikis/python')
- source_values = json.loads(page.get())
- source_values = source_values['wikipedia']
- for source_lang in source_values:
- source_values[source_lang] = pywikibot.ItemPage(self.repo,
- source_values[source_lang])
+ if lang in self.source_values:
+ source = pywikibot.Claim(self.repo, 'p143')
+ source.setTarget(self.source_values.get(lang))
+ return source
- if lang in source_values:
- self.source = pywikibot.Claim(self.repo, 'p143')
- self.source.setTarget(source_values.get(lang))
+ def cacheSources(self):
+ """
+ Fetches the sources from the onwiki list
+ and stores it internally
+ """
+ page = pywikibot.Page(self.repo, u'Wikidata:List of wikis/python')
+ self.source_values = json.loads(page.get())
+ self.source_values = self.source_values['wikipedia']
+ for source_lang in self.source_values:
+ self.source_values[source_lang] = pywikibot.ItemPage(self.repo,
+ self.source_values[source_lang])
def run(self):
"""
@@ -72,8 +78,10 @@
pywikibot.output('Adding %s --> %s'
% (claim.getID(), claim.getTarget()))
item.addClaim(claim)
- if self.source:
- claim.addSource(self.source, bot=True)
+ # A generator might yield pages from multiple languages
+ source = self.getSource(page.site.language())
+ if source:
+ claim.addSource(source, bot=True)
# TODO FIXME: We need to check that we aren't adding a
# duplicate
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 2bc5ace..40e43a3 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -45,22 +45,29 @@
# TODO: Make it a list which also includes the redirects to the template
self.fields = fields
self.repo = pywikibot.Site().data_repository()
- self.source = None
- self.setSource(pywikibot.Site().language())
+ self.cacheSources()
- def setSource(self, lang):
+ def getSource(self, lang):
"""
- Get the source
+ Get the source for the specified language,
+ if possible
"""
- page = pywikibot.Page(self.repo, 'Wikidata:List of wikis/python')
- source_values = json.loads(page.get())
- source_values = source_values['wikipedia']
- for source_lang in source_values:
- source_values[source_lang] = pywikibot.ItemPage(self.repo, source_values[source_lang])
+ if lang in self.source_values:
+ source = pywikibot.Claim(self.repo, 'p143')
+ source.setTarget(self.source_values.get(lang))
+ return source
- if lang in source_values:
- self.source = pywikibot.Claim(self.repo, 'p143')
- self.source.setTarget(source_values.get(lang))
+ def cacheSources(self):
+ """
+ Fetches the sources from the onwiki list
+ and stores it internally
+ """
+ page = pywikibot.Page(self.repo, u'Wikidata:List of wikis/python')
+ self.source_values = json.loads(page.get())
+ self.source_values = self.source_values['wikipedia']
+ for source_lang in self.source_values:
+ self.source_values[source_lang] = pywikibot.ItemPage(self.repo,
+ self.source_values[source_lang])
def run(self):
"""
@@ -135,8 +142,10 @@
pywikibot.output('Adding %s --> %s' % (claim.getID(), claim.getTarget()))
item.addClaim(claim)
- if self.source:
- claim.addSource(self.source, bot=True)
+ # A generator might yield pages from multiple sites
+ source = self.getSource(page.site.language())
+ if source:
+ claim.addSource(source, bot=True)
def main():
--
To view, visit https://gerrit.wikimedia.org/r/82263
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic1f10118a2dff93b71861b7ea97f7da22908cb04
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot