]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/resourceloader/DerivativeResourceLoaderContext.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.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
48         public function __construct( ResourceLoaderContext $context ) {
49                 $this->context = $context;
50         }
51
52         public function getModules() {
53                 if ( $this->modules === self::INHERIT_VALUE ) {
54                         return $this->context->getModules();
55                 }
56                 return $this->modules;
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 ( $this->language === self::INHERIT_VALUE ) {
68                         return $this->context->getLanguage();
69                 }
70                 return $this->language;
71         }
72
73         /**
74          * @param string $language
75          */
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;
81         }
82
83         public function getDirection() {
84                 if ( $this->direction === self::INHERIT_VALUE ) {
85                         return $this->context->getDirection();
86                 }
87                 if ( $this->direction === null ) {
88                         $this->direction = Language::factory( $this->getLanguage() )->getDir();
89                 }
90                 return $this->direction;
91         }
92
93         /**
94          * @param string $direction
95          */
96         public function setDirection( $direction ) {
97                 $this->direction = $direction;
98                 $this->hash = null;
99         }
100
101         public function getSkin() {
102                 if ( $this->skin === self::INHERIT_VALUE ) {
103                         return $this->context->getSkin();
104                 }
105                 return $this->skin;
106         }
107
108         /**
109          * @param string $skin
110          */
111         public function setSkin( $skin ) {
112                 $this->skin = $skin;
113                 $this->hash = null;
114         }
115
116         public function getUser() {
117                 if ( $this->user === self::INHERIT_VALUE ) {
118                         return $this->context->getUser();
119                 }
120                 return $this->user;
121         }
122
123         /**
124          * @param string|null $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 ( $this->debug === self::INHERIT_VALUE ) {
134                         return $this->context->getDebug();
135                 }
136                 return $this->debug;
137         }
138
139         /**
140          * @param bool $debug
141          */
142         public function setDebug( $debug ) {
143                 $this->debug = $debug;
144                 $this->hash = null;
145         }
146
147         public function getOnly() {
148                 if ( $this->only === self::INHERIT_VALUE ) {
149                         return $this->context->getOnly();
150                 }
151                 return $this->only;
152         }
153
154         /**
155          * @param string|null $only
156          */
157         public function setOnly( $only ) {
158                 $this->only = $only;
159                 $this->hash = null;
160         }
161
162         public function getVersion() {
163                 if ( $this->version === self::INHERIT_VALUE ) {
164                         return $this->context->getVersion();
165                 }
166                 return $this->version;
167         }
168
169         /**
170          * @param string|null $version
171          */
172         public function setVersion( $version ) {
173                 $this->version = $version;
174                 $this->hash = null;
175         }
176
177         public function getRaw() {
178                 if ( $this->raw === self::INHERIT_VALUE ) {
179                         return $this->context->getRaw();
180                 }
181                 return $this->raw;
182         }
183
184         /**
185          * @param bool $raw
186          */
187         public function setRaw( $raw ) {
188                 $this->raw = $raw;
189         }
190
191         public function getRequest() {
192                 return $this->context->getRequest();
193         }
194
195         public function getResourceLoader() {
196                 return $this->context->getResourceLoader();
197         }
198
199 }