Don't use Config as an access method for global objects
authorFlorian Schmidt <florian.schmidt.stargatewissen@gmail.com>
Tue, 4 Oct 2016 15:40:35 +0000 (17:40 +0200)
committerFlorian Schmidt <florian.schmidt.stargatewissen@gmail.com>
Tue, 4 Oct 2016 15:40:35 +0000 (17:40 +0200)
The Config interface (and it's implementation(s)) was never thought
to be an access method for objects saved in the global state, even
if it works with the current implementation GlobalVarConfig.

Imagine, that MediaWiki core switches to another file-based configuratiion
storage or a a database based one, we wouldn't be able to provide
access to global objects anymore, without weird hacks in the new
config-backend implementation or serializing objects to store in
the database or something else. This all isn't the idea with the Config
interface, as far as I know, so don't use it at all.

This commit changes the access to wgContLang to use the global keyword,
instead of accessing it through Config.

Follow up: Ice4f40911c3761c2542430935bc1898bc4e7a4d4
Follow up: I46f376a82205a5c99b98c9e971f9e9d7868ce9fb

Change-Id: I7a08b3bb649898abd445317a523051b07420b211

includes/OutputPage.php
includes/cache/HTMLFileCache.php

index b2e7d94..a69c0e6 100644 (file)
@@ -2215,6 +2215,8 @@ class OutputPage extends ContextSource {
         * @throws MWException
         */
        public function output( $return = false ) {
+               global $wgContLang;
+
                if ( $this->mDoNothing ) {
                        return $return ? '' : null;
                }
@@ -2261,7 +2263,7 @@ class OutputPage extends ContextSource {
                ob_start();
 
                $response->header( 'Content-type: ' . $config->get( 'MimeType' ) . '; charset=UTF-8' );
-               $response->header( 'Content-language: ' . $config->get( 'ContLang' )->getHtmlCode() );
+               $response->header( 'Content-language: ' . $wgContLang->getHtmlCode() );
 
                // Avoid Internet Explorer "compatibility view" in IE 8-10, so that
                // jQuery etc. can work correctly.
index 060837e..ae8efa9 100644 (file)
@@ -157,6 +157,7 @@ class HTMLFileCache extends FileCacheBase {
         * @return void
         */
        public function loadFromFileCache( IContextSource $context, $mode = self::MODE_NORMAL ) {
+               global $wgContLang;
                $config = MediaWikiServices::getInstance()->getMainConfig();
 
                wfDebug( __METHOD__ . "()\n" );
@@ -167,10 +168,9 @@ class HTMLFileCache extends FileCacheBase {
                        $context->getTitle()->resetArticleID( 0 );
                }
 
-               $contLang = $config->get( 'ContLang' );
                $context->getOutput()->sendCacheControl();
                header( "Content-Type: {$config->get( 'MimeType' )}; charset=UTF-8" );
-               header( "Content-Language: {$contLang->getHtmlCode()}" );
+               header( "Content-Language: {$wgContLang->getHtmlCode()}" );
                if ( $this->useGzip() ) {
                        if ( wfClientAcceptsGzip() ) {
                                header( 'Content-Encoding: gzip' );