resourceloader: Move queue formatting out of OutputPage
[lhc/web/wiklou.git] / includes / resourceloader / DerivativeResourceLoaderContext.php
index d114d7e..418d17f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Derivative context for resource loader modules.
+ * Derivative context for ResourceLoader modules.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * @since 1.24
  */
 class DerivativeResourceLoaderContext extends ResourceLoaderContext {
+       const INHERIT_VALUE = -1;
 
        /**
         * @var ResourceLoaderContext
         */
        private $context;
-       protected $modules;
-       protected $language;
-       protected $direction;
-       protected $skin;
-       protected $user;
-       protected $debug;
-       protected $only;
-       protected $version;
-       protected $hash;
-       protected $raw;
+
+       protected $modules = self::INHERIT_VALUE;
+       protected $language = self::INHERIT_VALUE;
+       protected $direction = self::INHERIT_VALUE;
+       protected $skin = self::INHERIT_VALUE;
+       protected $user = self::INHERIT_VALUE;
+       protected $debug = self::INHERIT_VALUE;
+       protected $only = self::INHERIT_VALUE;
+       protected $version = self::INHERIT_VALUE;
+       protected $raw = self::INHERIT_VALUE;
 
        public function __construct( ResourceLoaderContext $context ) {
                $this->context = $context;
        }
 
        public function getModules() {
-               if ( !is_null( $this->modules ) ) {
-                       return $this->modules;
-               } else {
+               if ( $this->modules === self::INHERIT_VALUE ) {
                        return $this->context->getModules();
                }
+               return $this->modules;
        }
 
        /**
@@ -64,11 +64,10 @@ class DerivativeResourceLoaderContext extends ResourceLoaderContext {
        }
 
        public function getLanguage() {
-               if ( !is_null( $this->language ) ) {
-                       return $this->language;
-               } else {
+               if ( $this->language === self::INHERIT_VALUE ) {
                        return $this->context->getLanguage();
                }
+               return $this->language;
        }
 
        /**
@@ -76,16 +75,19 @@ class DerivativeResourceLoaderContext extends ResourceLoaderContext {
         */
        public function setLanguage( $language ) {
                $this->language = $language;
-               $this->direction = null; // Invalidate direction since it might be based on language
+               // Invalidate direction since it is based on language
+               $this->direction = null;
                $this->hash = null;
        }
 
        public function getDirection() {
-               if ( !is_null( $this->direction ) ) {
-                       return $this->direction;
-               } else {
+               if ( $this->direction === self::INHERIT_VALUE ) {
                        return $this->context->getDirection();
                }
+               if ( $this->direction === null ) {
+                       $this->direction = Language::factory( $this->getLanguage() )->getDir();
+               }
+               return $this->direction;
        }
 
        /**
@@ -97,11 +99,10 @@ class DerivativeResourceLoaderContext extends ResourceLoaderContext {
        }
 
        public function getSkin() {
-               if ( !is_null( $this->skin ) ) {
-                       return $this->skin;
-               } else {
+               if ( $this->skin === self::INHERIT_VALUE ) {
                        return $this->context->getSkin();
                }
+               return $this->skin;
        }
 
        /**
@@ -113,27 +114,26 @@ class DerivativeResourceLoaderContext extends ResourceLoaderContext {
        }
 
        public function getUser() {
-               if ( !is_null( $this->user ) ) {
-                       return $this->user;
-               } else {
+               if ( $this->user === self::INHERIT_VALUE ) {
                        return $this->context->getUser();
                }
+               return $this->user;
        }
 
        /**
-        * @param string $user
+        * @param string|null $user
         */
        public function setUser( $user ) {
                $this->user = $user;
                $this->hash = null;
+               $this->userObj = null;
        }
 
        public function getDebug() {
-               if ( !is_null( $this->debug ) ) {
-                       return $this->debug;
-               } else {
+               if ( $this->debug === self::INHERIT_VALUE ) {
                        return $this->context->getDebug();
                }
+               return $this->debug;
        }
 
        /**
@@ -145,15 +145,14 @@ class DerivativeResourceLoaderContext extends ResourceLoaderContext {
        }
 
        public function getOnly() {
-               if ( !is_null( $this->only ) ) {
-                       return $this->only;
-               } else {
+               if ( $this->only === self::INHERIT_VALUE ) {
                        return $this->context->getOnly();
                }
+               return $this->only;
        }
 
        /**
-        * @param string $only
+        * @param string|null $only
         */
        public function setOnly( $only ) {
                $this->only = $only;
@@ -161,15 +160,14 @@ class DerivativeResourceLoaderContext extends ResourceLoaderContext {
        }
 
        public function getVersion() {
-               if ( !is_null( $this->version ) ) {
-                       return $this->version;
-               } else {
+               if ( $this->version === self::INHERIT_VALUE ) {
                        return $this->context->getVersion();
                }
+               return $this->version;
        }
 
        /**
-        * @param string $version
+        * @param string|null $version
         */
        public function setVersion( $version ) {
                $this->version = $version;
@@ -177,11 +175,10 @@ class DerivativeResourceLoaderContext extends ResourceLoaderContext {
        }
 
        public function getRaw() {
-               if ( !is_null( $this->raw ) ) {
-                       return $this->raw;
-               } else {
+               if ( $this->raw === self::INHERIT_VALUE ) {
                        return $this->context->getRaw();
                }
+               return $this->raw;
        }
 
        /**