jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
Revert "pywikibot: Add support for property creation"

Revert due to failing tests:
https://travis-ci.org/wikimedia/pywikibot/jobs/525944446

This reverts commit c3c937a01dfd2aa985a160a5104538edb49aeab7.

Change-Id: I1b531c644850f419e5df3fa93d3f83711065dc83
---
M pywikibot/page.py
M pywikibot/site.py
M tests/wikibase_edit_tests.py
3 files changed, 19 insertions(+), 84 deletions(-)

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 27df20e..a07bf9c 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3956,16 +3956,6 @@
'claims': self.claims,
}

- def get_data_for_new_entity(self):
- """
- Return data required for creation of new page.
-
- Override it if you need.
-
- @rtype: dict
- """
- return {}
-
def _diff_to(self, type_key, key_name, value_name, diffto, data):
assert type_key not in data, 'Key type must be defined in data'
source = self._normalizeLanguages(getattr(self, type_key)).copy()
@@ -4196,7 +4186,7 @@
else:
data = WikibasePage._normalizeData(data)

- updates = self.repo.editEntity(self, data,
+ updates = self.repo.editEntity(self._defined_by(singular=True), data,
baserevid=baserevid, **kwargs)
self.latest_revision_id = updates['entity']['lastrevid']

@@ -4761,43 +4751,29 @@
A Wikibase entity in the property namespace.

Should be created as::
+
PropertyPage(DataSite, 'P21')
- or
- PropertyPage(DataSite, datatype='url')
"""

_cache_attrs = WikibasePage._cache_attrs + ('_type',)
entity_type = 'property'
- title_pattern = r'^(P[1-9]\d*|-1)$'
+ title_pattern = r'^P[1-9]\d*$'

- def __init__(self, source, title=None, datatype=None):
+ def __init__(self, source, title=''):
"""
Initializer.

@param source: data repository property is on
@type source: pywikibot.site.DataSite
- @param title: page name of property, like "P##",
- "-1" or None for an empty property.
+ @param title: page name of property, like "P##"
@type title: str
- @param datatype: Datatype for a new property.
- @type datatype: str
"""
- # Special case for new property.
- if title is None or title == '-1':
- if not datatype:
- raise TypeError('"datatype" is required for new property.')
- WikibasePage.__init__(self, source, '-1',
- ns=source.property_namespace)
- Property.__init__(self, source, '-1', datatype=datatype)
- assert self.id == '-1'
- else:
- if not title:
- raise pywikibot.InvalidTitle(
- "Property's title cannot be empty")
+ if not title:
+ raise pywikibot.InvalidTitle("Property's title cannot be empty")

- WikibasePage.__init__(self, source, title,
- ns=source.property_namespace)
- Property.__init__(self, source, self.id)
+ WikibasePage.__init__(self, source, title,
+ ns=source.property_namespace)
+ Property.__init__(self, source, self.id)

def get(self, force=False, *args, **kwargs):
"""
@@ -4826,10 +4802,6 @@
return Claim(self.site, self.getID(), datatype=self.type,
*args, **kwargs)

- def get_data_for_new_entity(self):
- """Return data required for creation of new property."""
- return {'datatype': self.type}
-

# Add PropertyPage to the class attribute "types" after its declaration.
Property.types['wikibase-property'] = PropertyPage
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 977d7dd..26c11c4 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -7785,17 +7785,13 @@

return dtype

- @deprecated_args(identification='entity')
@must_be(group='user')
- def editEntity(self, entity, data, bot=True, **kwargs):
+ def editEntity(self, identification, data, bot=True, **kwargs):
"""
Edit entity.

- Note: This method is unable to create entities other than 'item'
- if dict with API parameters was passed to 'entity' parameter.
- @param entity: Page to edit, or dict with API parameters
- to use for entity identification
- @type entity: WikibasePage or dict
+ @param identification: API parameters to use for entity identification
+ @type identification: dict
@param data: data updates
@type data: dict
@param bot: Whether to mark the edit as a bot edit
@@ -7803,23 +7799,11 @@
@return: New entity data
@rtype: dict
"""
- # this changes the reference to a new object
- data = dict(data)
- if isinstance(entity, pywikibot.page.WikibasePage):
- params = entity._defined_by(singular=True)
- if 'id' in params and params['id'] == '-1':
- del params['id']
- if not params:
- params['new'] = entity.entity_type
- data_for_new_entity = entity.get_data_for_new_entity()
- data.update(data_for_new_entity)
- else:
- if 'id' in entity and entity['id'] == '-1':
- del entity['id']
- params = dict(entity)
- if not params: # If no identification was provided
- params['new'] = 'item'
-
+ if 'id' in identification and identification['id'] == '-1':
+ del identification['id']
+ params = dict(**identification)
+ if not params: # If no identification was provided
+ params['new'] = 'item' # TODO create properties+queries
params['action'] = 'wbeditentity'
if bot:
params['bot'] = 1
@@ -7828,7 +7812,7 @@
params['token'] = self.tokens['edit']

for arg in kwargs:
- if arg in ['clear', 'summary']:
+ if arg in ['clear', 'data', 'summary']:
params[arg] = kwargs[arg]
elif arg != 'baserevid':
warn('Unknown wbeditentity parameter {0} ignored'.format(arg),
diff --git a/tests/wikibase_edit_tests.py b/tests/wikibase_edit_tests.py
index 13a5a6b..69e61e8 100644
--- a/tests/wikibase_edit_tests.py
+++ b/tests/wikibase_edit_tests.py
@@ -128,27 +128,6 @@
item = pywikibot.ItemPage(testsite)
item.editEntity(data)

- def test_edit_entity_new_property(self):
- """Test creating a new property using C{PropertyPage.editEntity}."""
- testsite = self.get_repo()
- ts = str(time.time())
- data = {
- 'labels': {
- 'en': {
- 'language': 'en',
- 'value': 'Pywikibot test new property',
- }
- },
- 'descriptions': {
- 'en': {
- 'language': 'en',
- 'value': 'Pywikibot test new property - ' + ts,
- }
- }
- }
- prop = pywikibot.PropertyPage(testsite, datatype='string')
- prop.editEntity(data)
-
def test_edit_entity_new_linked_item(self):
"""Test linking a page using a new item."""
ts = str(time.time())

To view, visit change 507016. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1b531c644850f419e5df3fa93d3f83711065dc83
Gerrit-Change-Number: 507016
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: 813gan <813gan@protonmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Aklapper <aklapper@wikimedia.org>
Gerrit-CC: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-CC: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-CC: Welcome, new contributor! <ssethi@wikimedia.org>