Merge "CoreTagHooks: Use parse() for output to HTML rather than text()"
[lhc/web/wiklou.git] / includes / resourceloader / DerivativeResourceLoaderContext.php
1 <?php
2 /**
3 * Derivative context for resource loader 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
32 /**
33 * @var ResourceLoaderContext
34 */
35 private $context;
36 protected $modules;
37 protected $language;
38 protected $direction;
39 protected $skin;
40 protected $user;
41 protected $debug;
42 protected $only;
43 protected $version;
44 protected $hash;
45 protected $raw;
46
47 public function __construct( ResourceLoaderContext $context ) {
48 $this->context = $context;
49 }
50
51 public function getModules() {
52 if ( !is_null( $this->modules ) ) {
53 return $this->modules;
54 } else {
55 return $this->context->getModules();
56 }
57 }
58
59 /**
60 * @param string[] $modules
61 */
62 public function setModules( array $modules ) {
63 $this->modules = $modules;
64 }
65
66 public function getLanguage() {
67 if ( !is_null( $this->language ) ) {
68 return $this->language;
69 } else {
70 return $this->context->getLanguage();
71 }
72 }
73
74 /**
75 * @param string $language
76 */
77 public function setLanguage( $language ) {
78 $this->language = $language;
79 $this->direction = null; // Invalidate direction since it might be based on language
80 $this->hash = null;
81 }
82
83 public function getDirection() {
84 if ( !is_null( $this->direction ) ) {
85 return $this->direction;
86 } else {
87 return $this->context->getDirection();
88 }
89 }
90
91 /**
92 * @param string $direction
93 */
94 public function setDirection( $direction ) {
95 $this->direction = $direction;
96 $this->hash = null;
97 }
98
99 public function getSkin() {
100 if ( !is_null( $this->skin ) ) {
101 return $this->skin;
102 } else {
103 return $this->context->getSkin();
104 }
105 }
106
107 /**
108 * @param string $skin
109 */
110 public function setSkin( $skin ) {
111 $this->skin = $skin;
112 $this->hash = null;
113 }
114
115 public function getUser() {
116 if ( !is_null( $this->user ) ) {
117 return $this->user;
118 } else {
119 return $this->context->getUser();
120 }
121 }
122
123 /**
124 * @param string $user
125 */
126 public function setUser( $user ) {
127 $this->user = $user;
128 $this->hash = null;
129 $this->userObj = null;
130 }
131
132 public function getDebug() {
133 if ( !is_null( $this->debug ) ) {
134 return $this->debug;
135 } else {
136 return $this->context->getDebug();
137 }
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 ( !is_null( $this->only ) ) {
150 return $this->only;
151 } else {
152 return $this->context->getOnly();
153 }
154 }
155
156 /**
157 * @param string $only
158 */
159 public function setOnly( $only ) {
160 $this->only = $only;
161 $this->hash = null;
162 }
163
164 public function getVersion() {
165 if ( !is_null( $this->version ) ) {
166 return $this->version;
167 } else {
168 return $this->context->getVersion();
169 }
170 }
171
172 /**
173 * @param string $version
174 */
175 public function setVersion( $version ) {
176 $this->version = $version;
177 $this->hash = null;
178 }
179
180 public function getRaw() {
181 if ( !is_null( $this->raw ) ) {
182 return $this->raw;
183 } else {
184 return $this->context->getRaw();
185 }
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 }