Merge "Language: s/error_log/wfWarn/"
[lhc/web/wiklou.git] / includes / context / RequestContext.php
index b847163..ede10fe 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,7 +297,7 @@ class RequestContext implements IContextSource {
                        $e = new Exception;
                        wfDebugLog( 'recursion-guard', "Recursion detected:\n" . $e->getTraceAsString() );
 
-                       $code = $this->getConfig()->get( 'LanguageCode' ) ? : 'en';
+                       $code = $this->getConfig()->get( 'LanguageCode' ) ?: 'en';
                        $this->lang = Language::factory( $code );
                } elseif ( $this->lang === null ) {
                        $this->recursion = true;
@@ -352,12 +352,15 @@ 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)
@@ -372,7 +375,13 @@ class RequestContext implements IContextSource {
                                        $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
@@ -412,6 +421,21 @@ 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.
+        *
+        * @param string $func
+        * @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.
         */