jenkins-bot has submitted this change and it was merged.
Change subject: Add Page.isFlowPage to check whether Flow is enabled on a given page ......................................................................
Add Page.isFlowPage to check whether Flow is enabled on a given page
Also adds Site.loadflowinfo to query the API
Bug: 65119 Change-Id: If830e022841918afe7866509380daddaafd036a4 --- M pywikibot/data/api.py M pywikibot/page.py M pywikibot/site.py 3 files changed, 29 insertions(+), 0 deletions(-)
Approvals: Ladsgroup: Looks good to me, approved Xqt: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 1a85255..ea462e2 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -1055,6 +1055,9 @@ if "pageprops" in pagedict: page._pageprops = pagedict['pageprops']
+ if "flowinfo" in pagedict: + page._flowinfo = pagedict['flowinfo']['flow'] +
if __name__ == "__main__": from pywikibot import Site, logging diff --git a/pywikibot/page.py b/pywikibot/page.py index fe54ef6..848f748 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -1579,6 +1579,14 @@ % (self.title(asLink=True), error.message)) return False
+ def isFlowPage(self): + """Whether the given title is a Flow page""" + if not self.site.hasExtension('Flow', False): + return False + if not hasattr(self, '_flowinfo'): + self.site.loadflowinfo(self) + return 'enabled' in self._flowinfo + # ####### DEPRECATED METHODS ########
@deprecated("Site.encoding()") diff --git a/pywikibot/site.py b/pywikibot/site.py index 5e54f9f..583df32 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1299,6 +1299,24 @@ return (pageitem['imageinfo'] if history else pageitem['imageinfo'][0])
+ def loadflowinfo(self, page): + """ + Loads Flow-related information about a given page + Assumes that the Flow extension is installed + """ + title = page.title(withSection=False) + query = self._generator(api.PropertyGenerator, + type_arg="flowinfo", + titles=title.encode(self.encoding()), + ) + for pageitem in query: + if not self.sametitle(pageitem['title'], title): + pywikibot.warning( + u"loadflowinfo: Query on %s returned data on '%s'" + % (page, pageitem['title'])) + continue + api.update_page(page, pageitem) + def page_exists(self, page): """Return True if and only if page is an existing page on site.""" if not hasattr(page, "_pageid"):
pywikibot-commits@lists.wikimedia.org