jenkins-bot has submitted this change and it was merged.
Change subject: Fix string formatting in copyAndKeep.
......................................................................
Fix string formatting in copyAndKeep.
According to Python docs, section 5.6.2, "When the right argument is a dictionary
(or other mapping type), then the formats in the string must include a parenthesised
mapping key into that dictionary inserted immediately after the '%' character.
The mapping key selects the value to be formatted from the mapping."
This is not the case here.
Change-Id: I3ee69a1d44b4109fd98837be12af39a23eba2ae3
---
M pywikibot/page.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 94694da..a103aca 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1948,7 +1948,7 @@
else:
pywikibot.output(
'Moving text from %s to %s.'
- % {'oldcat': self.title(), 'authors': targetCat.title()})
+ % (self.title(), targetCat.title()))
authors = ', '.join(self.contributingUsers())
creationSummary = message % (self.title(), authors)
newtext = self.get()
--
To view, visit https://gerrit.wikimedia.org/r/96900
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3ee69a1d44b4109fd98837be12af39a23eba2ae3
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploader(a)gmail.com>
Gerrit-Reviewer: Gerrit Patch Uploader <gerritpatchuploader(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Bug 54868 - isDisambig results in AttributeError
......................................................................
Bug 54868 - isDisambig results in AttributeError
Set _pageprops to {} per default before updating from live site as
- a page without any pageprops has no corresponding entry in the pagedict and, thus, Page._pageprops will not be set in api.update_page()
- the pageprops may be removed after a forced update
Same problem (ValueError in Page) for Page.coordinates() if the page has no coordinates fixed in Page.
Change-Id: I557733ab88d43b4577678dfc0c36ae383bc7dce5
---
M pywikibot/page.py
1 file changed, 3 insertions(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index eefc5d9..c0aa834 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -377,6 +377,7 @@
@return: dict
"""
if not hasattr(self, '_pageprops') or force:
+ self._pageprops = {} # page may not have pageprops (see bug 54868)
self.site.loadpageprops(self)
return self._pageprops
@@ -1143,9 +1144,10 @@
@return: A list of Coordinate objects
"""
if not hasattr(self, '_coords'):
+ self._coords = []
self.site.loadcoordinfo(self)
if primary_only:
- return self._coords[0]
+ return self._coords[0] if len(self._coords) > 0 else None
else:
return self._coords
--
To view, visit https://gerrit.wikimedia.org/r/87060
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I557733ab88d43b4577678dfc0c36ae383bc7dce5
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: FelixReimann <felix(a)fex-it.de>
Gerrit-Reviewer: FelixReimann <felix(a)fex-it.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Ported image.py to core
......................................................................
Ported image.py to core
Bug: 57322
Change-Id: I9e63adb52888477eded82d34839c5885be96e8b8
---
A scripts/image.py
1 file changed, 203 insertions(+), 0 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/image.py b/scripts/image.py
new file mode 100644
index 0000000..d041736
--- /dev/null
+++ b/scripts/image.py
@@ -0,0 +1,203 @@
+# -*- coding: utf-8 -*-
+"""
+This script can be used to change one image to another or remove an image
+entirely.
+
+Syntax: python image.py image_name [new_image_name]
+
+If only one command-line parameter is provided then that image will be removed;
+if two are provided, then the first image will be replaced by the second one on
+all pages.
+
+Command line options:
+
+-summary: Provide a custom edit summary. If the summary includes spaces,
+ surround it with single quotes, such as:
+ -summary:'My edit summary'
+-always Don't prompt to make changes, just do them.
+-loose Do loose replacements. This will replace all occurences of the name
+ of the image (and not just explicit image syntax). This should work
+ to catch all instances of the image, including where it is used as a
+ template parameter or in image galleries. However, it can also make
+ more mistakes. This only works with image replacement, not image
+ removal.
+
+Examples:
+
+The image "FlagrantCopyvio.jpg" is about to be deleted, so let's first remove it
+from everything that displays it:
+
+ python image.py FlagrantCopyvio.jpg
+
+The image "Flag.svg" has been uploaded, making the old "Flag.jpg" obselete:
+
+ python image.py Flag.jpg Flag.svg
+
+"""
+__version__ = '$Id$'
+#
+# Distributed under the terms of the MIT license.
+#
+import pywikibot
+import replace
+from pywikibot import pagegenerators
+import re
+
+
+class ImageRobot:
+ """
+ This robot will load all pages yielded by a file links image page generator and
+ replace or remove all occurences of the old image.
+ """
+ # Summary messages for replacing images
+ msg_replace = {
+ 'ar': u'روبوت - استبدال الصورة %s مع %s',
+ 'de': u'Bot: Ersetze Bild %s durch %s',
+ 'en': u'Robot: Replacing image %s with %s',
+ 'es': u'Robot - Reemplazando imagen %s por %s',
+ 'fa': u'ربات: جایگزین کردن تصویر %s با %s',
+ 'fr': u'Bot: Remplace image %s par %s',
+ 'he': u'בוט: מחליף את התמונה %s בתמונה %s',
+ 'it': u"Bot: Sostituisco l'immagine %s con %s",
+ 'ja': u'ロボットによる:画像置き換え %s から %s へ',
+ 'ko': u'로봇 - 그림 %s을 %s로 치환',
+ 'lt': u'robotas: vaizdas %s keičiamas į %s',
+ 'nn': u'robot: erstatta biletet %s med %s',
+ 'no': u'robot: erstatter bildet %s med %s',
+ 'nl': u'Bot: afbeelding %s vervangen door %s',
+ 'pl': u'Robot zamienia obraz %s na %s',
+ 'pt': u'Bot: Alterando imagem %s para %s',
+ 'ru': u'Бот: Замена файла %s на %s',
+ 'zh': u'機器人:取代圖像 %s 至 %s',
+ }
+
+ # Summary messages for removing images
+ msg_remove = {
+ 'ar': u'روبوت - إزالة الصورة %s',
+ 'de': u'Bot: Entferne Bild %s',
+ 'en': u'Robot: Removing image %s',
+ 'es': u'Robot - Retirando imagen %s',
+ 'fa': u'ربات: برداشتن تصویر %s',
+ 'fr': u'Bot: Enleve image %s',
+ 'he': u'בוט: מסיר את התמונה %s',
+ 'it': u"Bot: Rimuovo l'immagine %s",
+ 'ja': u'ロボットによる:画像削除 %s',
+ 'ko': u'로봇 - %s 그림을 제거',
+ 'lt': u'robotas: Šalinamas vaizdas %s',
+ 'nl': u'Bot: afbeelding %s verwijderd',
+ 'no': u'robot: fjerner bildet %s',
+ 'nn': u'robot: fjerna biletet %s',
+ 'pl': u'Robot usuwa obraz %s',
+ 'pt': u'Bot: Alterando imagem %s',
+ 'ru': u'Бот: удалил файл %s',
+ 'zh': u'機器人:移除圖像 %s',
+ }
+
+ def __init__(self, generator, oldImage, newImage=None, summary='',
+ always=False, loose=False):
+ """
+ Arguments:
+ * generator - A page generator.
+ * oldImage - The title of the old image (without namespace)
+ * newImage - The title of the new image (without namespace), or
+ None if you want to remove the image.
+ """
+ self.generator = generator
+ self.oldImage = oldImage
+ self.newImage = newImage
+ self.editSummary = summary
+ self.summary = summary
+ self.always = always
+ self.loose = loose
+
+ # get edit summary message
+ mysite = pywikibot.getSite()
+ if summary:
+ self.editSummary = summary
+ elif self.newImage:
+ self.editSummary = pywikibot.translate(mysite, self.msg_replace) \
+ % (self.oldImage, self.newImage)
+ else:
+ self.editSummary = pywikibot.translate(mysite, self.msg_remove) \
+ % self.oldImage
+
+ def run(self):
+ """
+ Starts the robot's action.
+ """
+ # regular expression to find the original template.
+ # {{vfd}} does the same thing as {{Vfd}}, so both will be found.
+ # The old syntax, {{msg:vfd}}, will also be found.
+ # The group 'parameters' will either match the parameters, or an
+ # empty string if there are none.
+
+ replacements = []
+ site = pywikibot.getSite()
+
+ if not site.nocapitalize:
+ case = re.escape(self.oldImage[0].upper() + \
+ self.oldImage[0].lower())
+ escaped = '[' + case + ']' + re.escape(self.oldImage[1:])
+ else:
+ escaped = re.escape(self.oldImage)
+
+ # Be careful, spaces and _ have been converted to '\ ' and '\_'
+ escaped = re.sub('\\\\[_ ]', '[_ ]', escaped)
+ if not self.loose or not self.newImage:
+ ImageRegex = re.compile(r'\[\[ *(?:' + '|'.join(site.namespace(6, all=True)) + ')\s*:\s*' + escaped + ' *(?P<parameters>\|[^\n]+|) *\]\]')
+ else:
+ ImageRegex = re.compile(r'' + escaped)
+
+ if self.newImage:
+ if not self.loose:
+ replacements.append((ImageRegex, '[[' + site.image_namespace() + ':' + self.newImage + '\g<parameters>]]'))
+ else:
+ replacements.append((ImageRegex, self.newImage))
+ else:
+ replacements.append((ImageRegex, ''))
+
+ replaceBot = replace.ReplaceRobot(self.generator, replacements,
+ acceptall=self.always,
+ summary=self.editSummary)
+ replaceBot.run()
+
+
+def main():
+ oldImage = None
+ newImage = None
+ summary = ''
+ always = False
+ loose = False
+ # read command line parameters
+ for arg in pywikibot.handleArgs():
+ if arg == '-always':
+ always = True
+ elif arg == '-loose':
+ loose = True
+ elif arg.startswith('-summary'):
+ if len(arg) == len('-summary'):
+ summary = pywikibot.input(u'Choose an edit summary: ')
+ else:
+ summary = arg[len('-summary:'):]
+ else:
+ if oldImage:
+ newImage = arg
+ else:
+ oldImage = arg
+ if not oldImage:
+ pywikibot.showHelp('image')
+ else:
+ mysite = pywikibot.getSite()
+ ns = mysite.image_namespace()
+ oldImagePage = pywikibot.ImagePage(mysite, ns + ':' + oldImage)
+ gen = pagegenerators.FileLinksGenerator(oldImagePage)
+ preloadingGen = pagegenerators.PreloadingGenerator(gen)
+ bot = ImageRobot(preloadingGen, oldImage, newImage, summary, always,
+ loose)
+ bot.run()
+
+if __name__ == "__main__":
+ try:
+ main()
+ finally:
+ pywikibot.stopme()
--
To view, visit https://gerrit.wikimedia.org/r/96717
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9e63adb52888477eded82d34839c5885be96e8b8
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mayankmadan <maddiemadan(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Strainu <wiki(a)strainu.ro>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot