Merge "Add .pipeline/ with dev image variant"
[lhc/web/wiklou.git] / includes / resourceloader / DerivativeResourceLoaderContext.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @author Kunal Mehta
20 */
21
22 /**
23 * A mutable version of ResourceLoaderContext.
24 *
25 * Allows changing specific properties of a context object,
26 * without changing the main one. Inspired by MediaWiki's DerivativeContext.
27 *
28 * @ingroup ResourceLoader
29 * @since 1.24
30 */
31 class DerivativeResourceLoaderContext extends ResourceLoaderContext {
32 const INHERIT_VALUE = -1;
33
34 /**
35 * @var ResourceLoaderContext
36 */
37 private $context;
38
39 /** @var int|array */
40 protected $modules = self::INHERIT_VALUE;
41 protected $language = self::INHERIT_VALUE;
42 protected $direction = self::INHERIT_VALUE;
43 protected $skin = self::INHERIT_VALUE;
44 protected $user = self::INHERIT_VALUE;
45 protected $debug = self::INHERIT_VALUE;
46 protected $only = self::INHERIT_VALUE;
47 protected $version = self::INHERIT_VALUE;
48 protected $raw = self::INHERIT_VALUE;
49 protected $contentOverrideCallback = self::INHERIT_VALUE;
50
51 public function __construct( ResourceLoaderContext $context ) {
52 $this->context = $context;
53 }
54
55 public function getModules() {
56 if ( $this->modules === self::INHERIT_VALUE ) {
57 return $this->context->getModules();
58 }
59
60 return $this->modules;
61 }
62
63 /**
64 * @param string[] $modules
65 */
66 public function setModules( array $modules ) {
67 $this->modules = $modules;
68 }
69
70 public function getLanguage() {
71 if ( $this->language === self::INHERIT_VALUE ) {
72 return $this->context->getLanguage();
73 }
74 return $this->language;
75 }
76
77 /**
78 * @param string $language
79 */
80 public function setLanguage( $language ) {
81 $this->language = $language;
82 // Invalidate direction since it is based on language
83 $this->direction = null;
84 $this->hash = null;
85 }
86
87 public function getDirection() {
88 if ( $this->direction === self::INHERIT_VALUE ) {
89 return $this->context->getDirection();
90 }
91 if ( $this->direction === null ) {
92 $this->direction = Language::factory( $this->getLanguage() )->getDir();
93 }
94 return $this->direction;
95 }
96
97 /**
98 * @param string $direction
99 */
100 public function setDirection( $direction ) {
101 $this->direction = $direction;
102 $this->hash = null;
103 }
104
105 public function getSkin() {
106 if ( $this->skin === self::INHERIT_VALUE ) {
107 return $this->context->getSkin();
108 }
109 return $this->skin;
110 }
111
112 /**
113 * @param string $skin
114 */
115 public function setSkin( $skin ) {
116 $this->skin = $skin;
117 $this->hash = null;
118 }
119
120 public function getUser() {
121 if ( $this->user === self::INHERIT_VALUE ) {
122 return $this->context->getUser();
123 }
124 return $this->user;
125 }
126
127 /**
128 * @param string|null $user
129 */
130 public function setUser( $user ) {
131 $this->user = $user;
132 $this->hash = null;
133 $this->userObj = null;
134 }
135
136 public function getDebug() {
137 if ( $this->debug === self::INHERIT_VALUE ) {
138 return $this->context->getDebug();
139 }
140 return $this->debug;
141 }
142
143 /**
144 * @param bool $debug
145 */
146 public function setDebug( $debug ) {
147 $this->debug = $debug;
148 $this->hash = null;
149 }
150
151 public function getOnly() {
152 if ( $this->only === self::INHERIT_VALUE ) {
153 return $this->context->getOnly();
154 }
155 return $this->only;
156 }
157
158 /**
159 * @param string|null $only
160 */
161 public function setOnly( $only ) {
162 $this->only = $only;
163 $this->hash = null;
164 }
165
166 public function getVersion() {
167 if ( $this->version === self::INHERIT_VALUE ) {
168 return $this->context->getVersion();
169 }
170 return $this->version;
171 }
172
173 /**
174 * @param string|null $version
175 */
176 public function setVersion( $version ) {
177 $this->version = $version;
178 $this->hash = null;
179 }
180
181 public function getRaw() {
182 if ( $this->raw === self::INHERIT_VALUE ) {
183 return $this->context->getRaw();
184 }
185 return $this->raw;
186 }
187
188 /**
189 * @param bool $raw
190 */
191 public function setRaw( $raw ) {
192 $this->raw = $raw;
193 }
194
195 public function getRequest() {
196 return $this->context->getRequest();
197 }
198
199 public function getResourceLoader() {
200 return $this->context->getResourceLoader();
201 }
202
203 public function getContentOverrideCallback() {
204 if ( $this->contentOverrideCallback === self::INHERIT_VALUE ) {
205 return $this->context->getContentOverrideCallback();
206 }
207 return $this->contentOverrideCallback;
208 }
209
210 /**
211 * @see self::getContentOverrideCallback
212 * @since 1.32
213 * @param callable|null|int $callback As per self::getContentOverrideCallback,
214 * or self::INHERIT_VALUE
215 */
216 public function setContentOverrideCallback( $callback ) {
217 $this->contentOverrideCallback = $callback;
218 }
219
220 }