jenkins-bot has submitted this change and it was merged.
Change subject: Add method for removing sources from a claim ......................................................................
Add method for removing sources from a claim
Change-Id: I043aa2ba65348d69b0591c72ee479c942a1b2363 --- M pywikibot/page.py M pywikibot/site.py 2 files changed, 43 insertions(+), 0 deletions(-)
Approvals: Guoguo12: 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 a103aca..9307f86 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -2941,6 +2941,26 @@ source[claim.getID()].append(claim) self.sources.append(source)
+ def removeSource(self, source, **kwargs): + """ + Removes the source. + @param source: the source to remove + @type source: pywikibot.Claim + """ + self.removeSources([source], **kwargs) + + def removeSources(self, sources, **kwargs): + """ + Removes the individual sources. + @param sources: the sources to remove + @type sources: list of pywikibot.Claim + """ + data = self.repo.removeSources(self, sources, **kwargs) + for source in sources: + source_dict = collections.defaultdict(list) + source_dict[source.getID()].append(source) + self.sources.remove(source_dict) + def addQualifier(self, qualifier, **kwargs): """Adds the given qualifier
diff --git a/pywikibot/site.py b/pywikibot/site.py index 854ec27..d825753 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3787,6 +3787,29 @@ data = req.submit() return data
+ @must_be(group='user') + def removeSources(self, claim, sources, bot=True, **kwargs): + """ + Removes sources. + @param claim A Claim object to remove the sources from + @type claim pywikibot.Claim + @param sources A list of Claim objects that are sources + @type sources pywikibot.Claim + """ + params = dict(action='wbremovereferences') + if bot: + params['bot'] = 1 + params['statement'] = claim.snak + params['references'] = '|'.join(source.hash for source in sources) + params['token'] = self.token(pywikibot.Page(self, u'Main Page'), + 'edit') # Use a dummy page + for kwarg in kwargs: + if kwarg in ['baserevid', 'summary']: + params[kwarg] = kwargs[kwarg] + req = api.Request(site=self, **params) + data = req.submit() + return data + def linkTitles(self, page1, page2, bot=True): """ Link two pages together
pywikibot-commits@lists.wikimedia.org