Magul has uploaded a new change for review.
https://gerrit.wikimedia.org/r/76527
Change subject: create new ItemPage without providing sitelink ......................................................................
create new ItemPage without providing sitelink
Change-Id: Ib2e72a0d8236c5d44feede639b6801f566565872 --- M pywikibot/exceptions.py M pywikibot/page.py 2 files changed, 22 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/27/76527/1
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py index c5a7b3f..e90573a 100644 --- a/pywikibot/exceptions.py +++ b/pywikibot/exceptions.py @@ -90,6 +90,8 @@ class InvalidTitle(Error): """Invalid page title"""
+class NoIdOrSiteAndTitle(Error): + """There's no id or site and title provided"""
class LockedPage(PageRelatedError): """Page is locked""" diff --git a/pywikibot/page.py b/pywikibot/page.py index 215b643..705fc77 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -2293,8 +2293,7 @@ params[site] = self._site.dbName() params[title] = self._title else: - quit() - params[id] = self.getID() + raise pywikibot.NoIdOrSiteAndTitle("Page doesn't provide id or site and title")
return params
@@ -2445,7 +2444,7 @@
class ItemPage(WikibasePage): - def __init__(self, site, title=None): + def __init__(self, site, title=''): """ defined by qid XOR site AND title options: @@ -2453,7 +2452,8 @@ site=pywikibot.Site & title=Main Page """ super(ItemPage, self).__init__(site, title, ns=0) - self.id = title.lower() + if title != '': + self.id = title.lower()
@classmethod def fromPage(cls, page): @@ -2461,12 +2461,26 @@ Get the ItemPage based on a Page that links to it """ repo = page.site.data_repository() - i = cls(repo, 'null') - del i.id + i = cls(repo, '') i._site = page.site i._title = page.title() return i
+ @classmethod + def createNew(cls, site): + """ + Create new ItemPage + """ + i = cls(site, '') + req = pywikibot.data.api.Request(action='wbeditentity', + new='item', + data='{}', + site=site, + token=site.token(pywikibot.Page(site, u'Main Page'), 'edit')) # dummy page provided + i.id = req.submit()['entity']['id'] + print i.id + return i + def __make_site(self, dbname): """ Converts a Site.dbName() into a Site object.
pywikibot-commits@lists.wikimedia.org