Adding check for lessphp compiler to getLessCompiler()
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderContext.php
index 7af7b89..02744a6 100644 (file)
@@ -41,6 +41,7 @@ class ResourceLoaderContext {
        protected $version;
        protected $hash;
        protected $raw;
+       protected $userObj;
 
        /* Methods */
 
@@ -178,6 +179,31 @@ class ResourceLoaderContext {
                return $this->user;
        }
 
+       /**
+        * Get the possibly-cached User object for the specified username
+        *
+        * @since 1.25
+        * @return User|bool false if a valid object cannot be created
+        */
+       public function getUserObj() {
+               if ( $this->userObj === null ) {
+                       $username = $this->getUser();
+                       if ( $username ) {
+                               // Optimize: Avoid loading a new User object if possible
+                               global $wgUser;
+                               if ( is_object( $wgUser ) && $wgUser->getName() === $username ) {
+                                       $this->userObj = $wgUser;
+                               } else {
+                                       $this->userObj = User::newFromName( $username );
+                               }
+                       } else {
+                               $this->userObj = new User; // Anonymous user
+                       }
+               }
+
+               return $this->userObj;
+       }
+
        /**
         * @return bool
         */