jenkins-bot has submitted this change and it was merged.

Change subject: Revert "Implement wbsetclaim function"
......................................................................


Revert "Implement wbsetclaim function"

This reverts commit 227f0dddab5a3f6c5b87a101ae3a0e739210cc1b; backing
out due to broken build:

https://travis-ci.org/wikimedia/pywikibot-core/builds/10577053

Change-Id: I4eda408501751b19a848cf20e480c773df5f968c
---
M pywikibot/page.py
M pywikibot/site.py
2 files changed, 13 insertions(+), 119 deletions(-)

Approvals:
  Merlijn van Deen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/page.py b/pywikibot/page.py
index bee1461..52e792a 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2693,7 +2693,6 @@
         self.qualifiers = {}
         self.target = None
         self.snaktype = 'value'
-        self.rank = 'normal'
         self.on_item = None  # The item it's on
 
     @staticmethod
@@ -2723,7 +2722,6 @@
             else:
                 #This covers string type
                 claim.target = data['mainsnak']['datavalue']['value']
-        claim.rank = data['rank']
         if 'references' in data:
             for source in data['references']:
                 claim.sources.append(Claim.referenceFromJSON(site, source))
@@ -2757,6 +2755,7 @@
         """
         wrap = {'mainsnak': data}
         return Claim.fromJSON(site, wrap)
+
 
     def setTarget(self, value):
         """
@@ -2793,12 +2792,6 @@
         """
         return self.target
 
-    def getRank(self):
-        return self.rank
-
-    def setRank(self):
-        raise NotImplementedError
-
     def getSnakType(self):
         """
         Returns the "snaktype"
@@ -2829,9 +2822,8 @@
 
     def addSource(self, source, **kwargs):
         """
-        Adds a reference to the current claim
-        @param source: reference to add
-        @type source: pywikibot.Claim
+        source is a Claim.
+        adds it as a reference.
         """
         data = self.repo.editSource(self, source, new=True, **kwargs)
         source.hash = data['reference']['hash']
@@ -2841,7 +2833,6 @@
     def _formatDataValue(self):
         """
         Format the target into the proper JSON datavalue that Wikibase wants
-        @return: dict|basestring
         """
         if self.getType() == 'wikibase-item':
             value = {'entity-type': 'item',
@@ -2855,32 +2846,6 @@
         else:
             raise NotImplementedError('%s datatype is not supported yet.' % 
self.getType())
         return value
-
-    def _buildMainSnak(self):
-        """
-        Builds the full mainsnak that Wikibase wants
-        @return: dict
-        """
-        if self.getType() == 'wikibase-item':
-            datavalue = {
-                'type': 'wikibase-entityid',
-                'value': self._formatDataValue()
-            }
-        elif self.getType() in ['string', 'commonsMedia']:
-            datavalue = {
-                'type': 'string',
-                'value': self._formatDataValue()
-            }
-        elif self.getType() == 'globecoordinate':
-            datavalue = {
-                'type': 'globecoordinate',
-                'value': self._formatDataValue()
-            }
-        else:
-            raise NotImplementedError('%s datatype is not supported yet.' % 
self.getType())
-        return datavalue
-
-
 
 
 
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 31ce3d5..bca3feb 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -17,7 +17,6 @@
 import datetime
 import itertools
 import os
-from random import randint
 import re
 import sys
 import threading
@@ -3461,85 +3460,6 @@
             item.claims[claim.getID()] = [claim]
         item.lastrevid = data['pageinfo']['lastrevid']
 
-    def setClaim(self, item, claim, bot=True, **kwargs):
-        """
-        Implementation of wbsetclaim
-        The advantage of using this is that we can create
-        the reference in the same edit as adding the claim
-        @param item: Item to add a claim on
-        @type item: pywikibot.ItemPage
-        @param claim: Claim to add. This claim can have references
-        @type claim: pywikibot.Claim
-        @param bot: Mark edit as bot
-        @type bot: bool
-        @return: dict
-        """
-        if claim.getSnakType() != 'value':
-            raise NotImplementedError
-        # Assemble the claim thingy
-        data = {
-            'id': self.generateGUID(item),
-            'mainsnak': {
-                'snaktype': claim.getSnakType(),
-                'property': claim.getID(),
-                'datavalue': claim._buildMainSnak(),
-            },
-            'type': 'statement',
-            'rank': claim.getRank(),
-            'references': [],
-        }
-        if claim.sources:
-            # FIXME: Only the first ref will be added
-            ref = claim.sources[0]
-            data['references'].append({
-                'snaks': {
-                    ref.getID(): [{
-                        'snaktype': 'value',  # FIXME: Support multiple 
snaktypes
-                        'property': ref.getID(),
-                        'datavalue': ref._buildMainSnak(),
-                    }]
-                }
-            })
-
-        params = {
-            'action': 'wbsetclaim',
-            'claim': json.dumps(data),
-            'token': self.token(item, 'edit'),
-            'baserevid': item.lastrevid,
-        }
-        if bot:
-            params['bot'] = 1
-
-        req = api.Request(site=self, **params)
-        data = req.submit()
-        if claim.getID() in item.claims:
-            item.claims[claim.getID()].append(claim)
-        else:
-            item.claims[claim.getID()] = [claim]
-        item.lastrevid = data['pageinfo']['lastrevid']
-        claim.on_item = item
-
-    def generateGUID(self, item):
-        """
-        Function to generate a random GUID, converted from the
-        one in Wikibase in PHP
-        @param item: item the guid is for
-        @type item: pywikibot.ItemPage
-        @return: str
-        """
-        fmt = '{0:04X}{0:04X}-{0:04X}-{0:04X}-{0:04X}-{0:04X}{0:04X}{0:04X}'
-        string = fmt.format(
-            randint(0, 65535),
-            randint(0, 65535),
-            randint(0, 65535),
-            randint(16384, 20479),
-            randint(32768, 49151),
-            randint(0, 65535),
-            randint(0, 65535),
-            randint(0, 65535),
-        )
-        return item.getID() + '$' + string
-
     @must_be(group='user')
     def changeClaimTarget(self, claim, snaktype='value', bot=True, **kwargs):
         """
@@ -3590,7 +3510,16 @@
         if not new and hasattr(source, 'hash'):
             params['reference'] = source.hash
         #build up the snak
-        datavalue = source._buildMainSnak()
+        if source.getType() == 'wikibase-item':
+            datavalue = {'type': 'wikibase-entityid',
+                         'value': source._formatDataValue(),
+                         }
+        elif source.getType() == 'string':
+            datavalue = {'type': 'string',
+                         'value': source._formatDataValue(),
+                         }
+        else:
+            raise NotImplementedError('%s datatype is not supported yet.' % 
claim.getType())
         snak = {source.getID(): [{'snaktype': 'value',
                                   'property': source.getID(),
                                   'datavalue': datavalue,

-- 
To view, visit https://gerrit.wikimedia.org/r/80765
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4eda408501751b19a848cf20e480c773df5f968c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to