Fix issues identified by SpaceBeforeSingleLineComment sniff
[lhc/web/wiklou.git] / includes / content / ContentHandler.php
index f8d0879..76f2a7b 100644 (file)
@@ -207,26 +207,26 @@ abstract class ContentHandler {
                        }
                }
 
-               // Could this page contain custom CSS or JavaScript, based on the title?
-               $isCssOrJsPage = NS_MEDIAWIKI == $ns && preg_match( '!\.(css|js)$!u', $title->getText(), $m );
-               if ( $isCssOrJsPage ) {
+               // Could this page contain code based on the title?
+               $isCodePage = NS_MEDIAWIKI == $ns && preg_match( '!\.(css|js|json)$!u', $title->getText(), $m );
+               if ( $isCodePage ) {
                        $ext = $m[1];
                }
 
                // Hook can force JS/CSS
-               Hooks::run( 'TitleIsCssOrJsPage', array( $title, &$isCssOrJsPage ), '1.25' );
+               Hooks::run( 'TitleIsCssOrJsPage', array( $title, &$isCodePage ), '1.25' );
 
-               // Is this a .css subpage of a user page?
-               $isJsCssSubpage = NS_USER == $ns
-                       && !$isCssOrJsPage
-                       && preg_match( "/\\/.*\\.(js|css)$/", $title->getText(), $m );
-               if ( $isJsCssSubpage ) {
+               // Is this a user subpage containing code?
+               $isCodeSubpage = NS_USER == $ns
+                       && !$isCodePage
+                       && preg_match( "/\\/.*\\.(js|css|json)$/", $title->getText(), $m );
+               if ( $isCodeSubpage ) {
                        $ext = $m[1];
                }
 
                // Is this wikitext, according to $wgNamespaceContentModels or the DefaultModelFor hook?
                $isWikitext = is_null( $model ) || $model == CONTENT_MODEL_WIKITEXT;
-               $isWikitext = $isWikitext && !$isCssOrJsPage && !$isJsCssSubpage;
+               $isWikitext = $isWikitext && !$isCodePage && !$isCodeSubpage;
 
                // Hook can override $isWikitext
                Hooks::run( 'TitleIsWikitextPage', array( $title, &$isWikitext ), '1.25' );
@@ -237,6 +237,8 @@ abstract class ContentHandler {
                                        return CONTENT_MODEL_JAVASCRIPT;
                                case 'css':
                                        return CONTENT_MODEL_CSS;
+                               case 'json':
+                                       return CONTENT_MODEL_JSON;
                                default:
                                        return is_null( $model ) ? CONTENT_MODEL_TEXT : $model;
                        }
@@ -353,16 +355,20 @@ abstract class ContentHandler {
         *
         * @param string $name The content model ID, as given by a CONTENT_MODEL_XXX
         *    constant or returned by Revision::getContentModel().
+        * @param Language|null $lang The language to parse the message in (since 1.26)
         *
         * @throws MWException If the model ID isn't known.
         * @return string The content model's localized name.
         */
-       public static function getLocalizedName( $name ) {
+       public static function getLocalizedName( $name, Language $lang = null ) {
                // Messages: content-model-wikitext, content-model-text,
                // content-model-javascript, content-model-css
                $key = "content-model-$name";
 
                $msg = wfMessage( $key );
+               if ( $lang ) {
+                       $msg->inLanguage( $lang );
+               }
 
                return $msg->exists() ? $msg->plain() : $name;
        }
@@ -624,7 +630,7 @@ abstract class ContentHandler {
         * @return DifferenceEngine
         */
        public function createDifferenceEngine( IContextSource $context, $old = 0, $new = 0,
-               $rcid = 0, //FIXME: Deprecated, no longer used
+               $rcid = 0, // FIXME: Deprecated, no longer used
                $refreshCache = false, $unhide = false ) {
 
                // hook: get difference engine
@@ -1021,7 +1027,7 @@ abstract class ContentHandler {
 
        /**
         * Returns true for content models that support caching using the
-        * ParserCache mechanism. See WikiPage::isParserCacheUsed().
+        * ParserCache mechanism. See WikiPage::shouldCheckParserCache().
         *
         * @since 1.21
         *
@@ -1130,7 +1136,7 @@ abstract class ContentHandler {
                        $handlers = Hooks::getHandlers( $event );
                        $handlerInfo = array();
 
-                       wfSuppressWarnings();
+                       MediaWiki\suppressWarnings();
 
                        foreach ( $handlers as $handler ) {
                                if ( is_array( $handler ) ) {
@@ -1153,7 +1159,7 @@ abstract class ContentHandler {
                                $handlerInfo[] = $info;
                        }
 
-                       wfRestoreWarnings();
+                       MediaWiki\restoreWarnings();
 
                        wfWarn( "Using obsolete hook $event via ContentHandler::runLegacyHooks()! Handlers: " .
                                implode( ', ', $handlerInfo ), 2 );