jenkins-bot has submitted this change and it was merged.
Change subject: Function to check whether a site has a certain extension loaded ......................................................................
Function to check whether a site has a certain extension loaded
Change-Id: I0fc57f974b19da5d929f119f759f5cd6d56c5e43 --- M pywikibot/site.py 1 file changed, 9 insertions(+), 1 deletion(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index 2775f2b..43ec1df 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1086,7 +1086,7 @@ site=self, action="query", meta="siteinfo", - siprop="general|namespaces|namespacealiases" + siprop="general|namespaces|namespacealiases|extensions" ) try: sidata = sirequest.submit() @@ -1127,6 +1127,14 @@ # this is a less preferred form so it goes at the end self._namespaces[int(item['id'])].append(item["*"])
+ def hasExtension(self, name): + if not 'extensions' in self.siteinfo: + return NotImplementedError("Feature 'hasExtension' only available in MW 1.14+") + for ext in self.siteinfo['extensions']: + if ext['name'] == name: + return True + return False + @property def siteinfo(self): """Site information dict."""