Ricordisamoa has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/179351

Change subject: [WIP] Page.templatesWithParams(): catch wrong content model
......................................................................

[WIP] Page.templatesWithParams(): catch wrong content model

+ new Page.content_model property

Change-Id: I71742c26c8eb1be2953197ad4622aee105f211fc
---
M pywikibot/data/api.py
M pywikibot/page.py
2 files changed, 15 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/51/179351/1

diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index a460313..3999041 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')
     if 'info' in props:
         page._isredir = 'redirect' in pagedict
     if 'touched' in pagedict:
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 192d3e1..7823bb9 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -162,6 +162,17 @@
         """
         return self._link.namespace
 
+    @property
+    def content_model(self):
+        # try the API first
+        if not hasattr(self, '_contentmodel'):
+            self.site.loadpageinfo(self)
+        if self._contentmodel is None:
+            # and fall back to the default content model of the namespace
+            return getattr(self.site.namespaces()[self.namespace()],
+                           'defaultcontentmodel', None)
+        return self._contentmodel
+
     @deprecated_args(decode=None, savetitle="asUrl")
     def title(self, underscore=False, withNamespace=True,
               withSection=True, asUrl=False, asLink=False,
@@ -1291,6 +1302,9 @@
         parameters as the second entry.
 
         """
+        if self.content_model != 'wikitext':
+            raise pywikibot.Error(u'Page %s is of unsupported content model 
"%s"'
+                                  % (self.title(asLink=True), 
self.content_model))
         # WARNING: may not return all templates used in particularly
         # intricate cases such as template substitution
         titles = list(t.title() for t in self.templates())

-- 
To view, visit https://gerrit.wikimedia.org/r/179351
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I71742c26c8eb1be2953197ad4622aee105f211fc
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to