jenkins-bot has submitted this change and it was merged.
Change subject: (perf) Parse ItemPage title once
......................................................................
(perf) Parse ItemPage title once
ItemPage may be constructed without a page title, as it is
delay loaded from the wikibase_item of a page on another site.
Optimise ItemPage.title() so it does not reparse the Link title
every invocation.
Add test case for instantiating an empty ItemPage and setting .id to
a valid Qxx, and another case for altering .id highlighting a bug
yet to be fixed.
Split from: If7ca06adbb4b9932bba0abffc7588afcb320e934
Change-Id: I95a053a1ea17611498fcb5601c09a83d82f91fe8
---
M pywikibot/page.py
M tests/wikibase_tests.py
2 files changed, 49 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 4675a72..7a0d1bd 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2580,10 +2580,16 @@
self._isredir = False # Wikibase pages cannot be a redirect
def title(self, **kwargs):
- """ Page title. """
+ """ Page title.
+
+ If the item was instantiated without an ID,
+ fetch the ID and reparse the title.
+ """
if self.namespace() == 0:
- self._link._text = self.getID()
- del self._link._title
+ self.getID()
+ if self._link._text != self.id:
+ self._link._text = self.id
+ del self._link._title
return Page(self).title(**kwargs)
@deprecated("_defined_by")
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 4059c4a..aca60b3 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -167,6 +167,46 @@
item.get()
self.assertEquals(hasattr(item, '_content'), True)
+ def test_load_item_set_id(self):
+ """Test setting item.id attribute on empty item."""
+ item = pywikibot.ItemPage(wikidata, '-1')
+ self.assertEquals(item._link._title, '-1')
+ item.id = 'Q60'
+ self.assertEquals(hasattr(item, '_content'), False)
+ self.assertEquals(item.getID(), 'Q60')
+ self.assertEquals(hasattr(item, '_content'), False)
+ item.get()
+ self.assertEquals(hasattr(item, '_content'), True)
+ self.assertTrue('en' in item.labels)
+ self.assertEquals(item.labels['en'], 'New York City')
+ self.assertEquals(item.title(), 'Q60')
+
+ def test_reuse_item_set_id(self):
+ """
+ Test modifying item.id attribute.
+
+ Some scripts are using item.id = 'Q60' semantics, which does work
+ but modifying item.id does not currently work, and this test
+ highlights that it breaks silently.
+ """
+ item = pywikibot.ItemPage(wikidata, 'Q60')
+ item.get()
+ self.assertEquals(item.labels['en'], 'New York City')
+
+ # When the id attribute is modified, the ItemPage goes into
+ # an inconsistent state.
+ item.id = 'Q5296'
+ # The title is updated correctly
+ self.assertEquals(item.title(), 'Q5296')
+
+ # This del has no effect on the test; it is here to demonstrate that
+ # it doesnt help to clear this piece of saved state.
+ del item._content
+ # The labels are not updated; assertion showing undesirable behaviour:
+ self.assertEquals(item.labels['en'], 'New York City')
+ # TODO: This is the assertion that this test should be using:
+ #self.assertTrue(item.labels['en'].lower().endswith('main page'))
+
def test_empty_item(self):
# should not raise an error as the constructor only requires
# the site parameter, with the title parameter defaulted to None
--
To view, visit https://gerrit.wikimedia.org/r/137562
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I95a053a1ea17611498fcb5601c09a83d82f91fe8
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Bthfan <bth-fan(a)mcsmurf.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.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: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Underlying lk <a375070(a)drdrb.net>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Detect attempt to fetch wikibase item of an entity
......................................................................
Detect attempt to fetch wikibase item of an entity
While the wikidata and wikispecies families dont allow transcluded data,
the current code tries to find a wikibase item for wikidata pages, which
causes a warning like the following and raises an APIError exception.
WARNING: API warning (wbgetentities):
Unrecognized value for parameter 'sites': testwikidatawiki
This change detects whn ItemPage.fromPage is being asked to load an item
for a page on a site that cant have an item, and raises WikiBaseError
instead of APIError.
Change-Id: Ie89289536a777b8f6bb92b09d544c13cf32f5df4
---
M pywikibot/page.py
M tests/wikibase_tests.py
2 files changed, 33 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 266adb5..4675a72 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2836,6 +2836,9 @@
@param page: Page
@return: ItemPage
"""
+ if not page.site.has_transcluded_data:
+ raise pywikibot.WikiBaseError(u'%s has no transcluded data'
+ % page.site)
repo = page.site.data_repository()
if hasattr(page,
'_pageprops') and page.properties().get('wikibase_item'):
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 6487b55..4059c4a 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -114,6 +114,33 @@
pass
self.assertIsInstance(MyItemPage.fromPage(mainpage), MyItemPage)
+ def test_not_supported_family(self):
+ """Test that family without a data repository causes error."""
+ # Wikispecies is not supported by Wikidata yet.
+ species_site = pywikibot.Site('species', 'species')
+ self.wdp = pywikibot.Page(species_site, 'Main Page')
+ self.assertRaises(pywikibot.WikiBaseError,
+ pywikibot.ItemPage.fromPage, self.wdp)
+ self.assertRaisesRegexp(pywikibot.WikiBaseError,
+ 'species.*no transcluded data',
+ self.wdp.data_item)
+
+ # test.wikidata does not have a data repository.
+ self.wdp = pywikibot.ItemPage(wikidatatest, 'Q6')
+ self.assertRaises(pywikibot.WikiBaseError,
+ pywikibot.ItemPage.fromPage, self.wdp)
+
+ # The main Wikidata also does not have a data repository.
+ # It is a data repository, but no pages on Wikidata have
+ # a linked page.
+ self.wdp = pywikibot.ItemPage(wikidata, 'Q60')
+ self.assertRaises(pywikibot.WikiBaseError,
+ pywikibot.ItemPage.fromPage, self.wdp)
+
+ self.wdp = pywikibot.Page(wikidata, 'Main Page', ns=4)
+ self.assertRaises(pywikibot.WikiBaseError,
+ pywikibot.ItemPage.fromPage, self.wdp)
+
class TestItemLoad(PywikibotTestCase):
"""Test each of the three code paths for item creation:
@@ -342,10 +369,10 @@
class TestPageMethods(PywikibotTestCase):
"""Test cases to test methods of Page() behave correctly with Wikibase"""
- def test_item_save(self):
+ def test_page_methods(self):
+ """Test ItemPage methods inherited from superclass Page."""
self.wdp = pywikibot.ItemPage(wikidatatest, 'Q6')
- item = self.wdp.data_item()
- self.assertRaises(pywikibot.NoPage, item.title)
+ self.assertRaises(pywikibot.WikiBaseError, self.wdp.data_item)
self.assertRaises(pywikibot.PageNotSaved, self.wdp.save)
self.wdp.previousRevision()
self.assertEquals(self.wdp.langlinks(), [])
--
To view, visit https://gerrit.wikimedia.org/r/147905
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie89289536a777b8f6bb92b09d544c13cf32f5df4
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.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: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Namespace filtering in template.py
......................................................................
Namespace filtering in template.py
The namespace filtering (-namespace, -ns) was broken in core for
template.py, leading to changes intended for one (or more) namespace(s)
bleeding into others.
This commit makes sure that the page generator is always decorated with
genFactory.getCombinedGenerator.
Bug: 67435
Change-Id: I2336ebec356fb87e487f6d266e3415dbca77a603
---
M scripts/template.py
1 file changed, 5 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/template.py b/scripts/template.py
index 67c2bd0..3730b17 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -371,6 +371,11 @@
gen = pagegenerators.DuplicateFilterPageGenerator(gen)
if user:
gen = UserEditFilterGenerator(gen, user, timestamp, skip)
+
+ if not genFactory.gens:
+ # make sure that proper namespace filtering etc. is handled
+ gen = genFactory.getCombinedGenerator(gen)
+
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = TemplateRobot(preloadingGen, templates, subst, remove, editSummary,
--
To view, visit https://gerrit.wikimedia.org/r/150568
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2336ebec356fb87e487f6d266e3415dbca77a603
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Bep <bjorn.erik.pedersen(a)gmail.com>
Gerrit-Reviewer: Bep <bjorn.erik.pedersen(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: archivebot: add 'quarter' to variables for page name patterns
......................................................................
archivebot: add 'quarter' to variables for page name patterns
'quarter' of the year is available as a variable when specifying archive page names.
Related documentation comments are updated.
Change-Id: I7235aac26f7c577d4acde1b0b3466770f6a309d3
---
M scripts/archivebot.py
1 file changed, 11 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 8b073e8..99dd033 100644
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -52,6 +52,15 @@
key A secret key that (if valid) allows archives to not be
subpages of the page being archived.
+Variables below can be used in the value for "archive" in the template above:
+
+%(counter)d the current value of the counter
+%(year)d year of the thread being archived
+%(quarter)d quarter of the year of the thread being archived
+%(month)d month (as a number 1-12) of the thread being archived
+%(monthname)s English name of the month above
+%(monthnameshort)s first three letters of the name above
+%(week)d week number of the thread being archived
Options (may be omitted):
-help show this help message and exit
@@ -78,6 +87,7 @@
import re
import locale
from hashlib import md5
+from math import ceil
import pywikibot
from pywikibot import i18n
@@ -421,6 +431,7 @@
params = {
'counter': arch_counter,
'year': t.timestamp.year,
+ 'quarter': int(ceil(float(t.timestamp.month) / 3)),
'month': t.timestamp.month,
'monthname': self.month_num2orig_names[t.timestamp.month]['long'],
'monthnameshort': self.month_num2orig_names[t.timestamp.month]['short'],
--
To view, visit https://gerrit.wikimedia.org/r/150214
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7235aac26f7c577d4acde1b0b3466770f6a309d3
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Whym <whym(a)whym.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Whym <whym(a)whym.org>
Gerrit-Reviewer: jenkins-bot <>