Legoktm has uploaded a new change for review. https://gerrit.wikimedia.org/r/132767
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, 30 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/67/132767/1 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..c0ad9fb 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -1579,6 +1579,15 @@ % (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"): -- To view, visit https://gerrit.wikimedia.org/r/132767 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If830e022841918afe7866509380daddaafd036a4 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits