jenkins-bot has submitted this change and it was merged.
Change subject: New BasePage.content_model property ......................................................................
New BasePage.content_model property
If it cannot be reliably determined via the API, None is returned, to allow case-by-case fallbacks.
Bug: T75488 Change-Id: Ia337b5ba9e914d44232c2b9bd09781047e874e04 --- M pywikibot/data/api.py M pywikibot/page.py 2 files changed, 12 insertions(+), 0 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index a460313..4bb7962 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -1795,6 +1795,7 @@ else: raise AssertionError( "Page %s has neither 'pageid' nor 'missing' attribute" % pagedict['title']) + page._contentmodel = pagedict.get('contentmodel') # can be None if 'info' in props: page._isredir = 'redirect' in pagedict if 'touched' in pagedict: diff --git a/pywikibot/page.py b/pywikibot/page.py index 08eddc3..b5ada5b 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -162,6 +162,17 @@ """ return self._link.namespace
+ @property + def content_model(self): + """Return the content model for this page. + + If it cannot be reliably determined via the API, + None is returned. + """ + if not hasattr(self, '_contentmodel'): + self.site.loadpageinfo(self) + return self._contentmodel + @deprecated_args(decode=None, savetitle="asUrl") def title(self, underscore=False, withNamespace=True, withSection=True, asUrl=False, asLink=False,
pywikibot-commits@lists.wikimedia.org