jenkins-bot has submitted this change and it was merged.
Change subject: [IMPR] Add pageid property to Page object
......................................................................
[IMPR] Add pageid property to Page object
- pageid is sometimes needed e.g. for external web tools.
This patch implements a property method to get it without other page
related actions like Page.get().
- site.page_exists may just call page.pageid because that property method
calls loadpageinfo.
- use pageid instead of the internal _pageid in redirect.py
- add test for equality
Change-Id: If1bb4c4737015eb6044e9c524a61429a8ffce621
---
M pywikibot/page.py
M pywikibot/site.py
M scripts/redirect.py
M tests/site_tests.py
4 files changed, 16 insertions(+), 4 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 5c5f2e0..f0fd05e 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -242,6 +242,18 @@
return _depth
+ @property
+ def pageid(self):
+ """
+ Return pageid of the page.
+
+ @return: pageid or 0 if page does not exist
+ @rtype: int
+ """
+ if not hasattr(self, '_pageid'):
+ self.site.loadpageinfo(self)
+ return self._pageid
+
@deprecated_args(decode=None, savetitle="asUrl")
def title(self, underscore=False, withNamespace=True,
withSection=True, asUrl=False, asLink=False,
diff --git a/pywikibot/site.py b/pywikibot/site.py
index f8c6996..531b9b8 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -2965,9 +2965,7 @@
def page_exists(self, page):
"""Return True if and only if page is an existing page on
site."""
- if not hasattr(page, "_pageid"):
- self.loadpageinfo(page)
- return page._pageid > 0
+ return page.pageid > 0
def page_restrictions(self, page):
"""Return a dictionary reflecting page
protections."""
diff --git a/scripts/redirect.py b/scripts/redirect.py
index 4bc9c60..abe9b34 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -202,7 +202,7 @@
"""Generator that yields batches of 500 redirects as a
list."""
apiQ = []
for page in self.get_redirect_pages_via_api():
- apiQ.append(str(page._pageid))
+ apiQ.append(str(page.pageid))
if len(apiQ) >= 500:
yield apiQ
apiQ = []
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 89bc75e..e56d9b2 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -2494,6 +2494,8 @@
# remove the pageids that have already been loaded above by pagelinks
# so that preloadpages will use the titles instead
for page in links:
+ if hasattr(page, '_pageid'):
+ self.assertEqual(page.pageid, page._pageid)
del page._pageid
for page in mysite.preloadpages(links):
--
To view, visit
https://gerrit.wikimedia.org/r/297257
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If1bb4c4737015eb6044e9c524a61429a8ffce621
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>