wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / resourceloader / DerivativeResourceLoaderContext.php
blob1db9ce5a571ef095aa846dc775c09bc77b2480d8
1 <?php
2 /**
3 * Derivative context for ResourceLoader modules.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @author Kunal Mehta
24 /**
25 * Allows changing specific properties of a context object,
26 * without changing the main one. Inspired by DerivativeContext.
28 * @since 1.24
30 class DerivativeResourceLoaderContext extends ResourceLoaderContext {
31 const INHERIT_VALUE = -1;
33 /**
34 * @var ResourceLoaderContext
36 private $context;
38 protected $modules = self::INHERIT_VALUE;
39 protected $language = self::INHERIT_VALUE;
40 protected $direction = self::INHERIT_VALUE;
41 protected $skin = self::INHERIT_VALUE;
42 protected $user = self::INHERIT_VALUE;
43 protected $debug = self::INHERIT_VALUE;
44 protected $only = self::INHERIT_VALUE;
45 protected $version = self::INHERIT_VALUE;
46 protected $raw = self::INHERIT_VALUE;
48 public function __construct( ResourceLoaderContext $context ) {
49 $this->context = $context;
52 public function getModules() {
53 if ( $this->modules === self::INHERIT_VALUE ) {
54 return $this->context->getModules();
56 return $this->modules;
59 /**
60 * @param string[] $modules
62 public function setModules( array $modules ) {
63 $this->modules = $modules;
66 public function getLanguage() {
67 if ( $this->language === self::INHERIT_VALUE ) {
68 return $this->context->getLanguage();
70 return $this->language;
73 /**
74 * @param string $language
76 public function setLanguage( $language ) {
77 $this->language = $language;
78 // Invalidate direction since it is based on language
79 $this->direction = null;
80 $this->hash = null;
83 public function getDirection() {
84 if ( $this->direction === self::INHERIT_VALUE ) {
85 return $this->context->getDirection();
87 if ( $this->direction === null ) {
88 $this->direction = Language::factory( $this->getLanguage() )->getDir();
90 return $this->direction;
93 /**
94 * @param string $direction
96 public function setDirection( $direction ) {
97 $this->direction = $direction;
98 $this->hash = null;
101 public function getSkin() {
102 if ( $this->skin === self::INHERIT_VALUE ) {
103 return $this->context->getSkin();
105 return $this->skin;
109 * @param string $skin
111 public function setSkin( $skin ) {
112 $this->skin = $skin;
113 $this->hash = null;
116 public function getUser() {
117 if ( $this->user === self::INHERIT_VALUE ) {
118 return $this->context->getUser();
120 return $this->user;
124 * @param string $user
126 public function setUser( $user ) {
127 $this->user = $user;
128 $this->hash = null;
129 $this->userObj = null;
132 public function getDebug() {
133 if ( $this->debug === self::INHERIT_VALUE ) {
134 return $this->context->getDebug();
136 return $this->debug;
140 * @param bool $debug
142 public function setDebug( $debug ) {
143 $this->debug = $debug;
144 $this->hash = null;
147 public function getOnly() {
148 if ( $this->only === self::INHERIT_VALUE ) {
149 return $this->context->getOnly();
151 return $this->only;
155 * @param string|null $only
157 public function setOnly( $only ) {
158 $this->only = $only;
159 $this->hash = null;
162 public function getVersion() {
163 if ( $this->version === self::INHERIT_VALUE ) {
164 return $this->context->getVersion();
166 return $this->version;
170 * @param string|null $version
172 public function setVersion( $version ) {
173 $this->version = $version;
174 $this->hash = null;
177 public function getRaw() {
178 if ( $this->raw === self::INHERIT_VALUE ) {
179 return $this->context->getRaw();
181 return $this->raw;
185 * @param bool $raw
187 public function setRaw( $raw ) {
188 $this->raw = $raw;
191 public function getRequest() {
192 return $this->context->getRequest();
195 public function getResourceLoader() {
196 return $this->context->getResourceLoader();