Remove HWLDFWordAccumulator, deprecated in 1.28
[lhc/web/wiklou.git] / includes / resourceloader / DerivativeResourceLoaderContext.php
1 <?php
2 /**
3 * Derivative context for ResourceLoader modules.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author Kunal Mehta
22 */
23
24 /**
25 * Allows changing specific properties of a context object,
26 * without changing the main one. Inspired by DerivativeContext.
27 *
28 * @since 1.24
29 */
30 class DerivativeResourceLoaderContext extends ResourceLoaderContext {
31 const INHERIT_VALUE = -1;
32
33 /**
34 * @var ResourceLoaderContext
35 */
36 private $context;
37
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;
47 protected $contentOverrideCallback = self::INHERIT_VALUE;
48
49 public function __construct( ResourceLoaderContext $context ) {
50 $this->context = $context;
51 }
52
53 public function getModules() {
54 if ( $this->modules === self::INHERIT_VALUE ) {
55 return $this->context->getModules();
56 }
57 return $this->modules;
58 }
59
60 /**
61 * @param string[] $modules
62 */
63 public function setModules( array $modules ) {
64 $this->modules = $modules;
65 }
66
67 public function getLanguage() {
68 if ( $this->language === self::INHERIT_VALUE ) {
69 return $this->context->getLanguage();
70 }
71 return $this->language;
72 }
73
74 /**
75 * @param string $language
76 */
77 public function setLanguage( $language ) {
78 $this->language = $language;
79 // Invalidate direction since it is based on language
80 $this->direction = null;
81 $this->hash = null;
82 }
83
84 public function getDirection() {
85 if ( $this->direction === self::INHERIT_VALUE ) {
86 return $this->context->getDirection();
87 }
88 if ( $this->direction === null ) {
89 $this->direction = Language::factory( $this->getLanguage() )->getDir();
90 }
91 return $this->direction;
92 }
93
94 /**
95 * @param string $direction
96 */
97 public function setDirection( $direction ) {
98 $this->direction = $direction;
99 $this->hash = null;
100 }
101
102 public function getSkin() {
103 if ( $this->skin === self::INHERIT_VALUE ) {
104 return $this->context->getSkin();
105 }
106 return $this->skin;
107 }
108
109 /**
110 * @param string $skin
111 */
112 public function setSkin( $skin ) {
113 $this->skin = $skin;
114 $this->hash = null;
115 }
116
117 public function getUser() {
118 if ( $this->user === self::INHERIT_VALUE ) {
119 return $this->context->getUser();
120 }
121 return $this->user;
122 }
123
124 /**
125 * @param string|null $user
126 */
127 public function setUser( $user ) {
128 $this->user = $user;
129 $this->hash = null;
130 $this->userObj = null;
131 }
132
133 public function getDebug() {
134 if ( $this->debug === self::INHERIT_VALUE ) {
135 return $this->context->getDebug();
136 }
137 return $this->debug;
138 }
139
140 /**
141 * @param bool $debug
142 */
143 public function setDebug( $debug ) {
144 $this->debug = $debug;
145 $this->hash = null;
146 }
147
148 public function getOnly() {
149 if ( $this->only === self::INHERIT_VALUE ) {
150 return $this->context->getOnly();
151 }
152 return $this->only;
153 }
154
155 /**
156 * @param string|null $only
157 */
158 public function setOnly( $only ) {
159 $this->only = $only;
160 $this->hash = null;
161 }
162
163 public function getVersion() {
164 if ( $this->version === self::INHERIT_VALUE ) {
165 return $this->context->getVersion();
166 }
167 return $this->version;
168 }
169
170 /**
171 * @param string|null $version
172 */
173 public function setVersion( $version ) {
174 $this->version = $version;
175 $this->hash = null;
176 }
177
178 public function getRaw() {
179 if ( $this->raw === self::INHERIT_VALUE ) {
180 return $this->context->getRaw();
181 }
182 return $this->raw;
183 }
184
185 /**
186 * @param bool $raw
187 */
188 public function setRaw( $raw ) {
189 $this->raw = $raw;
190 }
191
192 public function getRequest() {
193 return $this->context->getRequest();
194 }
195
196 public function getResourceLoader() {
197 return $this->context->getResourceLoader();
198 }
199
200 public function getContentOverrideCallback() {
201 if ( $this->contentOverrideCallback === self::INHERIT_VALUE ) {
202 return $this->context->getContentOverrideCallback();
203 }
204 return $this->contentOverrideCallback;
205 }
206
207 /**
208 * @see self::getContentOverrideCallback
209 * @since 1.32
210 * @param callable|null|int $callback As per self::getContentOverrideCallback,
211 * or self::INHERIT_VALUE
212 */
213 public function setContentOverrideCallback( $callback ) {
214 $this->contentOverrideCallback = $callback;
215 }
216
217 }