Merge "(bug 42089) meta=siteinfo should output the default content model"
authorDaniel Kinzler <daniel.kinzler@wikimedia.de>
Fri, 14 Dec 2012 10:29:28 +0000 (10:29 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 14 Dec 2012 10:29:28 +0000 (10:29 +0000)
includes/Namespace.php
includes/api/ApiQuerySiteinfo.php
includes/content/ContentHandler.php

index e8d5632..46af002 100644 (file)
@@ -419,4 +419,18 @@ class MWNamespace {
                return $wgNonincludableNamespaces && in_array( $index, $wgNonincludableNamespaces );
        }
 
+       /**
+        * Get the default content model for a namespace
+        * This does not mean that all pages in that namespace have the model
+        *
+        * @since 1.21
+        * @param $index int Index to check
+        * @return null|string default model name for the given namespace, if set
+        */
+       public static function getNamespaceContentModel( $index ) {
+               global $wgNamespaceContentModels;
+               return isset( $wgNamespaceContentModels[$index] )
+                       ? $wgNamespaceContentModels[$index]
+                       : null;
+       }
 }
index ec503d6..bb22448 100644 (file)
@@ -227,6 +227,11 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        if ( MWNamespace::isNonincludable( $ns ) ) {
                                $data[$ns]['nonincludable'] = '';
                        }
+
+                       $contentmodel = MWNamespace::getNamespaceContentModel( $ns );
+                       if ( $contentmodel ) {
+                               $data[$ns]['defaultcontentmodel'] = $contentmodel;
+                       }
                }
 
                $this->getResult()->setIndexedTagName( $data, 'ns' );
index 282a7ba..cff49df 100644 (file)
@@ -186,8 +186,6 @@ abstract class ContentHandler {
         * @return null|string default model name for the page given by $title
         */
        public static function getDefaultModelFor( Title $title ) {
-               global $wgNamespaceContentModels;
-
                // NOTE: this method must not rely on $title->getContentModel() directly or indirectly,
                //       because it is used to initialize the mContentModel member.
 
@@ -195,11 +193,7 @@ abstract class ContentHandler {
 
                $ext = false;
                $m = null;
-               $model = null;
-
-               if ( !empty( $wgNamespaceContentModels[ $ns ] ) ) {
-                       $model = $wgNamespaceContentModels[ $ns ];
-               }
+               $model = MWNamespace::getNamespaceContentModel( $ns );
 
                // Hook can determine default model
                if ( !wfRunHooks( 'ContentHandlerDefaultModelFor', array( $title, &$model ) ) ) {