phpcs: Pass ResourceLoader.php
[lhc/web/wiklou.git] / includes / context / RequestContext.php
index 2c051ba..091e8da 100644 (file)
@@ -123,10 +123,10 @@ class RequestContext implements IContextSource {
        /**
         * Set the Title object
         *
-        * @param Title $t
+        * @param Title $title
         */
-       public function setTitle( Title $t ) {
-               $this->title = $t;
+       public function setTitle( Title $title ) {
+               $this->title = $title;
                // Erase the WikiPage so a new one with the new title gets created.
                $this->wikipage = null;
        }
@@ -297,13 +297,12 @@ class RequestContext implements IContextSource {
                        $e = new Exception;
                        wfDebugLog( 'recursion-guard', "Recursion detected:\n" . $e->getTraceAsString() );
 
-                       global $wgLanguageCode;
-                       $code = ( $wgLanguageCode ) ? $wgLanguageCode : 'en';
+                       $code = $this->getConfig()->get( 'LanguageCode' ) ?: 'en';
                        $this->lang = Language::factory( $code );
                } elseif ( $this->lang === null ) {
                        $this->recursion = true;
 
-                       global $wgLanguageCode, $wgContLang;
+                       global $wgContLang;
 
                        try {
                                $request = $this->getRequest();
@@ -314,7 +313,7 @@ class RequestContext implements IContextSource {
 
                                wfRunHooks( 'UserGetLanguageObject', array( $user, &$code, $this ) );
 
-                               if ( $code === $wgLanguageCode ) {
+                               if ( $code === $this->getConfig()->get( 'LanguageCode' ) ) {
                                        $this->lang = $wgContLang;
                                } else {
                                        $obj = Language::factory( $code );
@@ -353,29 +352,36 @@ class RequestContext implements IContextSource {
 
                        $skin = null;
                        wfRunHooks( 'RequestContextCreateSkin', array( $this, &$skin ) );
+                       $factory = SkinFactory::getDefaultInstance();
 
                        // If the hook worked try to set a skin from it
                        if ( $skin instanceof Skin ) {
                                $this->skin = $skin;
                        } elseif ( is_string( $skin ) ) {
-                               $this->skin = Skin::newFromKey( $skin );
+                               // Normalize the key, just in case the hook did something weird.
+                               $normalized = Skin::normalizeKey( $skin );
+                               $this->skin = $factory->makeSkin( $normalized );
                        }
 
                        // If this is still null (the hook didn't run or didn't work)
                        // then go through the normal processing to load a skin
                        if ( $this->skin === null ) {
-                               global $wgHiddenPrefs;
-                               if ( !in_array( 'skin', $wgHiddenPrefs ) ) {
+                               if ( !in_array( 'skin', $this->getConfig()->get( 'HiddenPrefs' ) ) ) {
                                        # get the user skin
                                        $userSkin = $this->getUser()->getOption( 'skin' );
                                        $userSkin = $this->getRequest()->getVal( 'useskin', $userSkin );
                                } else {
                                        # if we're not allowing users to override, then use the default
-                                       global $wgDefaultSkin;
-                                       $userSkin = $wgDefaultSkin;
+                                       $userSkin = $this->getConfig()->get( 'DefaultSkin' );
                                }
 
-                               $this->skin = Skin::newFromKey( $userSkin );
+                               // Normalize the key in case the user is passing gibberish
+                               // or has old preferences (bug 69566).
+                               $normalized = Skin::normalizeKey( $userSkin );
+
+                               // Skin::normalizeKey will also validate it, so
+                               // this won't throw an exception
+                               $this->skin = $factory->makeSkin( $normalized );
                        }
 
                        // After all that set a context on whatever skin got created
@@ -415,6 +421,20 @@ class RequestContext implements IContextSource {
                return self::$instance;
        }
 
+       /**
+        * Get the RequestContext object associated with the main request
+        * and gives a warning to the log, to find places, where a context maybe is missing.
+        *
+        * @return RequestContext
+        * @since 1.24
+        */
+       public static function getMainAndWarn( $func = __METHOD__ ) {
+               wfDebug( $func . ' called without context. ' .
+                       "Using RequestContext::getMain() for sanity\n" );
+
+               return self::getMain();
+       }
+
        /**
         * Resets singleton returned by getMain(). Should be called only from unit tests.
         */