(bug 42089) meta=siteinfo should output the default content model
authorumherirrender <umherirrender_de.wp@web.de>
Thu, 13 Dec 2012 20:05:15 +0000 (21:05 +0100)
committerumherirrender <umherirrender_de.wp@web.de>
Thu, 13 Dec 2012 20:05:15 +0000 (21:05 +0100)
Adding MWNamespace::getNamespaceContentModel which returns the namespace
content model from the global, if set

Change-Id: Ie012fd0ff846d50cae8081fc32b76900dbcad209

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 b61dc34..9d8db93 100644 (file)
@@ -185,8 +185,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.
 
@@ -194,11 +192,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 ) ) ) {