Merge "Actually assign suppression-related rights to 'suppress' group"
[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 // @phan-suppress-next-line PhanTypeMismatchReturn
58 return $this->modules;
59 }
60
61 /**
62 * @param string[] $modules
63 */
64 public function setModules( array $modules ) {
65 $this->modules = $modules;
66 }
67
68 public function getLanguage() {
69 if ( $this->language === self::INHERIT_VALUE ) {
70 return $this->context->getLanguage();
71 }
72 return $this->language;
73 }
74
75 /**
76 * @param string $language
77 */
78 public function setLanguage( $language ) {
79 $this->language = $language;
80 // Invalidate direction since it is based on language
81 $this->direction = null;
82 $this->hash = null;
83 }
84
85 public function getDirection() {
86 if ( $this->direction === self::INHERIT_VALUE ) {
87 return $this->context->getDirection();
88 }
89 if ( $this->direction === null ) {
90 $this->direction = Language::factory( $this->getLanguage() )->getDir();
91 }
92 return $this->direction;
93 }
94
95 /**
96 * @param string $direction
97 */
98 public function setDirection( $direction ) {
99 $this->direction = $direction;
100 $this->hash = null;
101 }
102
103 public function getSkin() {
104 if ( $this->skin === self::INHERIT_VALUE ) {
105 return $this->context->getSkin();
106 }
107 return $this->skin;
108 }
109
110 /**
111 * @param string $skin
112 */
113 public function setSkin( $skin ) {
114 $this->skin = $skin;
115 $this->hash = null;
116 }
117
118 public function getUser() {
119 if ( $this->user === self::INHERIT_VALUE ) {
120 return $this->context->getUser();
121 }
122 return $this->user;
123 }
124
125 /**
126 * @param string|null $user
127 */
128 public function setUser( $user ) {
129 $this->user = $user;
130 $this->hash = null;
131 $this->userObj = null;
132 }
133
134 public function getDebug() {
135 if ( $this->debug === self::INHERIT_VALUE ) {
136 return $this->context->getDebug();
137 }
138 return $this->debug;
139 }
140
141 /**
142 * @param bool $debug
143 */
144 public function setDebug( $debug ) {
145 $this->debug = $debug;
146 $this->hash = null;
147 }
148
149 public function getOnly() {
150 if ( $this->only === self::INHERIT_VALUE ) {
151 return $this->context->getOnly();
152 }
153 return $this->only;
154 }
155
156 /**
157 * @param string|null $only
158 */
159 public function setOnly( $only ) {
160 $this->only = $only;
161 $this->hash = null;
162 }
163
164 public function getVersion() {
165 if ( $this->version === self::INHERIT_VALUE ) {
166 return $this->context->getVersion();
167 }
168 return $this->version;
169 }
170
171 /**
172 * @param string|null $version
173 */
174 public function setVersion( $version ) {
175 $this->version = $version;
176 $this->hash = null;
177 }
178
179 public function getRaw() {
180 if ( $this->raw === self::INHERIT_VALUE ) {
181 return $this->context->getRaw();
182 }
183 return $this->raw;
184 }
185
186 /**
187 * @param bool $raw
188 */
189 public function setRaw( $raw ) {
190 $this->raw = $raw;
191 }
192
193 public function getRequest() {
194 return $this->context->getRequest();
195 }
196
197 public function getResourceLoader() {
198 return $this->context->getResourceLoader();
199 }
200
201 public function getContentOverrideCallback() {
202 if ( $this->contentOverrideCallback === self::INHERIT_VALUE ) {
203 return $this->context->getContentOverrideCallback();
204 }
205 return $this->contentOverrideCallback;
206 }
207
208 /**
209 * @see self::getContentOverrideCallback
210 * @since 1.32
211 * @param callable|null|int $callback As per self::getContentOverrideCallback,
212 * or self::INHERIT_VALUE
213 */
214 public function setContentOverrideCallback( $callback ) {
215 $this->contentOverrideCallback = $callback;
216 }
217
218 }