[MediaWiki-commits] [Gerrit] [WIP] Function to create a new item - change (pywikibot/core)

2014-04-20 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: [WIP] Function to create a new item
..


[WIP] Function to create a new item

Based on the provided page, it would add each of the langlinks
as connected pages.

Some TODOs:

* Option to add aliases based on redirects
* Check against already existing links upon errors
* Use linktitles if one of the links already exists

Change-Id: I5d497926c447d4c08e022c9b924cf028656378fd
---
M pywikibot/site.py
1 file changed, 36 insertions(+), 0 deletions(-)

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



diff --git a/pywikibot/site.py b/pywikibot/site.py
index 56492c5..8bf77bb 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -4017,6 +4017,42 @@
 data = req.submit()
 return data
 
+def createNewItemFromPage(self, page, bot=True, **kwargs):
+"""
+Create a new Wikibase item for a provided page
+@param page: page to fetch links from
+@type page: pywikibot.Page
+@param bot: whether to mark the edit as bot
+@return: pywikibot.ItemPage of newly created item
+"""
+sitelinks = {
+page.site.dbName(): {
+'site': page.site.dbName(),
+'title': page.title(),
+}
+}
+labels = {
+page.site.language(): {
+'language': page.site.language(),
+'value': page.title(),
+}
+}
+for link in page.iterlanglinks():
+sitelinks[link.site.dbName()] = {
+'site': link.site.dbName(),
+'title': link.title,
+}
+labels[link.site.language()] = {
+'language': link.site.language(),
+'value': link.title,
+}
+data = {
+'sitelinks': sitelinks,
+'labels': labels,
+}
+result = self.editEntity({}, data, bot=bot, **kwargs)
+return pywikibot.ItemPage(self, result['entity']['id'])
+
 # deprecated BaseSite methods
 def fam(self):
 raise NotImplementedError

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5d497926c447d4c08e022c9b924cf028656378fd
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm 
Gerrit-Reviewer: Ladsgroup 
Gerrit-Reviewer: Merlijn van Deen 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] [WIP] Function to create a new item - change (pywikibot/core)

2013-09-19 Thread Legoktm (Code Review)
Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/85179


Change subject: [WIP] Function to create a new item
..

[WIP] Function to create a new item

Based on the provided page, it would add each of the langlinks
as connected pages.

Some TODOs:

* Option to add aliases based on redirects
* Check against already existing links upon errors
* Use linktitles if one of the links already exists

Change-Id: I5d497926c447d4c08e022c9b924cf028656378fd
---
M pywikibot/site.py
1 file changed, 36 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/79/85179/1

diff --git a/pywikibot/site.py b/pywikibot/site.py
index 13477b0..2f8e4be 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3681,6 +3681,42 @@
 data = req.submit()
 return data
 
+def createNewItemFromPage(self, page, bot=True, **kwargs):
+"""
+Create a new Wikibase item for a provided page
+@param page: page to fetch links from
+@type page: pywikibot.Page
+@param bot: whether to mark the edit as bot
+@return: pywikibot.ItemPage of newly created item
+"""
+sitelinks = {
+page.site.dbName(): {
+'site': page.site.dbName(),
+'title': page.title(),
+}
+}
+labels = {
+page.site.language(): {
+'language': page.site.language(),
+'value': page.title(),
+}
+}
+for link in page.iterlanglinks():
+sitelinks[link.site.dbName()] = {
+'site': link.site.dbName(),
+'title': link.title,
+}
+labels[link.site.language()] = {
+'language': link.site.language(),
+'value': link.title,
+}
+data = {
+'sitelinks': sitelinks,
+'labels': labels,
+}
+result = self.editEntity({}, data, bot=bot, **kwargs)
+return pywikibot.ItemPage(self, result['entity']['id'])
+
 # deprecated BaseSite methods
 def fam(self):
 raise NotImplementedError

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5d497926c447d4c08e022c9b924cf028656378fd
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits