Skip to content

Commit

Permalink
Merge "[IMPR] Add pageid property to Page object"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Aug 19, 2016
2 parents 1c3438a + 1950634 commit c4160dd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions pywikibot/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ def depth(self):

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,
Expand Down
4 changes: 1 addition & 3 deletions pywikibot/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -2967,9 +2967,7 @@ def loadflowinfo(self, page):

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."""
Expand Down
2 changes: 1 addition & 1 deletion scripts/redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _next_redirect_group(self):
"""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 = []
Expand Down
2 changes: 2 additions & 0 deletions tests/site_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,8 @@ def test_titles(self):
# 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):
Expand Down

0 comments on commit c4160dd

Please sign in to comment.