jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/575548 )
Change subject: [IMPR] Fix search for changed claims when saving entity
......................................................................
[IMPR] Fix search for changed claims when saving entity
The details on what was broken and how are described
in T246359#5926070.
The suggestion for more granular claim comparison
comes from T186200#4267477.
Bug: T246359
Change-Id: I041930dd3a3413d568b9b75d638d287e4b085745
---
M pywikibot/page.py
1 file changed, 72 insertions(+), 28 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 032096e..5332b1e 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -4158,21 +4158,34 @@
if diffto and 'claims' in diffto:
temp = defaultdict(list)
- claim_ids = set()
+ props_add = set(claims.keys())
+ props_orig = set(diffto['claims'].keys())
+ for prop in (props_orig | props_add):
+ if prop not in props_orig:
+ temp[prop].extend(claims[prop])
+ continue
+ if prop not in props_add:
+ temp[prop].extend(
+ {'id': claim['id'], 'remove': ''}
+ for claim in diffto['claims'][prop] if 'id' in claim)
+ continue
- diffto_claims = diffto['claims']
+ claim_ids = set()
+ claim_map = {
+ json['id']: json for json in diffto['claims'][prop]
+ if 'id' in json}
+ for claim, json in zip(self.claims[prop], claims[prop]):
+ if 'id' in json:
+ claim_ids.add(json['id'])
+ if json['id'] in claim_map:
+ other = Claim.fromJSON(
+ self.repo, claim_map[json['id']])
+ if claim.same_as(other, ignore_rank=False,
+ ignore_refs=False):
+ continue
+ temp[prop].append(json)
- for prop in claims:
- for claim in claims[prop]:
- if (prop not in diffto_claims
- or claim not in diffto_claims[prop]):
- temp[prop].append(claim)
-
- if 'id' in claim:
- claim_ids.add(claim['id'])
-
- for prop, prop_claims in diffto_claims.items():
- for claim in prop_claims:
+ for claim in diffto['claims'][prop]:
if 'id' in claim and claim['id'] not in claim_ids:
temp[prop].append({'id': claim['id'], 'remove': ''})
@@ -5125,25 +5138,56 @@
if not isinstance(other, self.__class__):
return False
- for attr in ('id', 'snaktype', 'target'):
- if getattr(self, attr) != getattr(other, attr):
- return False
-
- my_qualifiers = list(chain.from_iterable(self.qualifiers.values()))
- other_qualifiers = list(chain.from_iterable(other.qualifiers.values()))
- if len(my_qualifiers) != len(other_qualifiers):
- return False
- for q in my_qualifiers:
- if q not in other_qualifiers:
- return False
- for q in other_qualifiers:
- if q not in my_qualifiers:
- return False
- return True
+ return self.same_as(other)
def __ne__(self, other):
return not self.__eq__(other)
+ @staticmethod
+ def _claim_mapping_same(this, other):
+ if len(this) != len(other):
+ return False
+ my_values = list(chain.from_iterable(this.values()))
+ other_values = list(chain.from_iterable(other.values()))
+ if len(my_values) != len(other_values):
+ return False
+ for val in my_values:
+ if val not in other_values:
+ return False
+ for val in other_values:
+ if val not in my_values:
+ return False
+ return True
+
+ def same_as(self, other, ignore_rank=True, ignore_quals=False,
+ ignore_refs=True):
+ """Check if two claims are same."""
+ if ignore_rank:
+ attributes = ['id', 'snaktype', 'target']
+ else:
+ attributes = ['id', 'snaktype', 'rank', 'target']
+ for attr in attributes:
+ if getattr(self, attr) != getattr(other, attr):
+ return False
+
+ if not ignore_quals:
+ if not self._claim_mapping_same(self.qualifiers, other.qualifiers):
+ return False
+
+ if not ignore_refs:
+ if len(self.sources) != len(other.sources):
+ return False
+ for source in self.sources:
+ same = False
+ for other_source in other.sources:
+ if self._claim_mapping_same(source, other_source):
+ same = True
+ break
+ if not same:
+ return False
+
+ return True
+
def copy(self):
"""
Create an independent copy of this object.
--
To view, visit https://gerrit.wikimedia.org/r/575548
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I041930dd3a3413d568b9b75d638d287e4b085745
Gerrit-Change-Number: 575548
Gerrit-PatchSet: 2
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/577696 )
Change subject: [tests] Replace seattlewiki with opensprints wiki
......................................................................
[tests] Replace seattlewiki with opensprints wiki
seattlewiki.org/wiki is redirected and no longer outputs
404 status code. Replace it with opensprints wiki.
Bug: T247140
Change-Id: I09a87699b3c68a61b3d8ca825ad0bffe0750884c
---
M tests/site_detect_tests.py
1 file changed, 3 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_detect_tests.py b/tests/site_detect_tests.py
index d1a1c04..a5f6230 100644
--- a/tests/site_detect_tests.py
+++ b/tests/site_detect_tests.py
@@ -253,9 +253,9 @@
"""Test offline sites."""
- def test_seattlewiki(self):
- """Test detection of MediaWiki sites for seattlewiki.org."""
- self.assertNoSite('http://seattlewiki.org/wiki/$1')
+ def test_opensprints_wiki(self):
+ """Test detection of MediaWiki sites for wiki.opensprints.org."""
+ self.assertNoSite('http://wiki.opensprints.org/index.php?title=$1')
class OtherSiteTestCase(SiteDetectionTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/577696
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I09a87699b3c68a61b3d8ca825ad0bffe0750884c
Gerrit-Change-Number: 577696
Gerrit-PatchSet: 4
Gerrit-Owner: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/577598 )
Change subject: [cleanup] Remove outdated has_api method
......................................................................
[cleanup] Remove outdated has_api method
has_api method was introduced for compat compatibility.
Since all supported MediaWiki has an API,
this method is superfluous. It isn't used anymore.
It is already announced to be removed from the framework.
Bug: T106121
Change-Id: I1a556fbc6a009a32f75e166805ef6426ab9a011b
---
M HISTORY.rst
M pywikibot/site.py
2 files changed, 1 insertion(+), 10 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/HISTORY.rst b/HISTORY.rst
index 3989473..2bb2114 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -4,6 +4,7 @@
Current release
---------------
+* Site.has_api method has been removed (T106121)
* Bugfixes and improvements
* Localisation updates
diff --git a/pywikibot/site.py b/pywikibot/site.py
index ca504ed..575b1e4 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -781,11 +781,6 @@
self._pagemutex = threading.Condition()
self._locked_pages = set()
- @deprecated(since='20141225', future_warning=True)
- def has_api(self):
- """Return whether this site has an API."""
- return False
-
@property
@deprecated(
"APISite.siteinfo['case'] or Namespace.case == 'case-sensitive'",
@@ -1913,11 +1908,6 @@
return pywikibot.Site(url=site['url'] + '/w/index.php')
raise ValueError('Cannot parse a site out of %s.' % dbname)
- @deprecated(since='20141225', future_warning=True)
- def has_api(self):
- """Return whether this site has an API."""
- return True
-
@deprecated_args(step=None)
def _generator(self, gen_class, type_arg=None, namespaces=None,
total=None, **args):
--
To view, visit https://gerrit.wikimedia.org/r/577598
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1a556fbc6a009a32f75e166805ef6426ab9a011b
Gerrit-Change-Number: 577598
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/573259 )
Change subject: [FEAT] Make Revision support slots
......................................................................
[FEAT] Make Revision support slots
In new MediaWiki versions, one revision can hold more
than just one content. This feature is called "slot".
Bug: T226544
Change-Id: Ic926b34980f7b61b8447acc0631b7649c3130ed7
---
M pywikibot/data/api.py
M pywikibot/page.py
2 files changed, 31 insertions(+), 6 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 0702d38..eae947f 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -3249,8 +3249,6 @@
"""Update page revisions."""
# TODO: T102735: Use the page content model for <1.21
for rev in revisions:
- if 'slots' in rev and 'main' in rev['slots']: # MW 1.32+
- rev.update(rev['slots']['main'])
revision = pywikibot.page.Revision(
revid=rev['revid'],
timestamp=pywikibot.Timestamp.fromISOformat(rev['timestamp']),
@@ -3258,10 +3256,11 @@
anon='anon' in rev,
comment=rev.get('comment', ''),
minor='minor' in rev,
- text=rev.get('*'),
+ slots=rev.get('slots'), # MW 1.32+
+ text=rev.get('*'), # b/c
rollbacktoken=rev.get('rollbacktoken'),
parentid=rev.get('parentid'),
- contentmodel=rev.get('contentmodel'),
+ contentmodel=rev.get('contentmodel'), # b/c
sha1=rev.get('sha1')
)
page._revisions[revision.revid] = revision
diff --git a/pywikibot/page.py b/pywikibot/page.py
index b9f4f35..8172689 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -5606,7 +5606,7 @@
def __init__(self, revid, timestamp, user, anon=False, comment='',
text=None, minor=False, rollbacktoken=None, parentid=None,
- contentmodel=None, sha1=None):
+ contentmodel=None, sha1=None, slots=None):
"""
Initializer.
@@ -5635,9 +5635,11 @@
@type contentmodel: str
@param sha1: sha1 of revision text (v1.19+)
@type sha1: str
+ @param slots: revision slots (v1.32+)
+ @type slots: dict
"""
self.revid = revid
- self.text = text
+ self._text = text
self.timestamp = timestamp
self.user = user
self.anon = anon
@@ -5647,6 +5649,7 @@
self._parent_id = parentid
self._content_model = contentmodel
self._sha1 = sha1
+ self.slots = slots
@property
def parent_id(self):
@@ -5666,15 +5669,38 @@
return self._parent_id
@property
+ def text(self):
+ """
+ Return text of this revision.
+
+ This is meant for compatibility with older MW version which
+ didn't support revisions with slots. For newer MW versions,
+ this returns the contents of the main slot.
+
+ @return: text of the revision
+ @rtype: str or None if text not yet retrieved
+ """
+ if self.slots is not None:
+ return self.slots.get('main', {}).get('*')
+ return self._text
+
+ @property
def content_model(self):
"""
Return content model of the revision.
+ This is meant for compatibility with older MW version which
+ didn't support revisions with slots. For newer MW versions,
+ this returns the content model of the main slot.
+
@return: content model
@rtype: str
@raises AssertionError: content model not supplied to the constructor
which always occurs for MediaWiki versions lower than 1.21.
"""
+ if self._content_model is None and self.slots is not None:
+ self._content_model = self.slots.get('main', {}).get(
+ 'contentmodel')
# TODO: T102735: Add a sane default of 'wikitext' and others for <1.21
assert self._content_model is not None, (
'Revision {0} was instantiated without a content model'
--
To view, visit https://gerrit.wikimedia.org/r/573259
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic926b34980f7b61b8447acc0631b7649c3130ed7
Gerrit-Change-Number: 573259
Gerrit-PatchSet: 2
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/577597 )
Change subject: [IMPR] Unify HISTORY.rst next release removals
......................................................................
[IMPR] Unify HISTORY.rst next release removals
Change-Id: I1033e2bd8614871dbbf27042a295820c51aac8d9
---
M HISTORY.rst
1 file changed, 4 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/HISTORY.rst b/HISTORY.rst
index 3989473..245348e 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -17,11 +17,11 @@
* Use mw API IP/anon user detection (T245318)
* Correctly choose primary coordinates in BasePage.coordinates() (T244963)
* Rewrite APISite.page_can_be_edited (T244604)
-* compat module is deprecated for 5 years and will be removed with next release (T183085)
+* compat module is deprecated for 5 years and will be removed in next release (T183085)
* ipaddress module is required for Python 2 (T243171)
* tools.ip will be dropped in favour of tools.is_IP (T243171)
-* tools.ip_regexp is deprecatd for 5 years and will be removed with next release
-* backports.py will be removed with next release (T244664)
+* tools.ip_regexp is deprecatd for 5 years and will be removed in next release
+* backports.py will be removed in next release (T244664)
* stdnum package is required for ISBN scripts and cosmetic_changes (T132919, T144288, T241141)
* preload urllib.quote() with Python 2 (T243710, T222623)
* Drop isbn_hyphenate package due to outdated data (T243157)
@@ -29,7 +29,7 @@
* Deprecate/remove sysop parameter in several methods and functions
* Refactor Wikibase entity namespace handling (T160395)
* Site.has_api method will be removed in next release
-* Category.copyTo and Category.copyAndKeep will be removed in the next release
+* Category.copyTo and Category.copyAndKeep will be removed in next release
* weblib module has been removed (T85001)
* botirc module has been removed (T212632)
* Bugfixes and improvements
--
To view, visit https://gerrit.wikimedia.org/r/577597
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1033e2bd8614871dbbf27042a295820c51aac8d9
Gerrit-Change-Number: 577597
Gerrit-PatchSet: 2
Gerrit-Owner: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)