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.
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.
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
23 * A mutable version of ResourceLoaderContext.
25 * Allows changing specific properties of a context object,
26 * without changing the main one. Inspired by MediaWiki's DerivativeContext.
28 * @ingroup ResourceLoader
31 class DerivativeResourceLoaderContext
extends ResourceLoaderContext
{
32 const INHERIT_VALUE
= -1;
35 * @var ResourceLoaderContext
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
;
51 public function __construct( ResourceLoaderContext
$context ) {
52 $this->context
= $context;
55 public function getModules() {
56 if ( $this->modules
=== self
::INHERIT_VALUE
) {
57 return $this->context
->getModules();
60 return $this->modules
;
64 * @param string[] $modules
66 public function setModules( array $modules ) {
67 $this->modules
= $modules;
70 public function getLanguage() {
71 if ( $this->language
=== self
::INHERIT_VALUE
) {
72 return $this->context
->getLanguage();
74 return $this->language
;
78 * @param string $language
80 public function setLanguage( $language ) {
81 $this->language
= $language;
82 // Invalidate direction since it is based on language
83 $this->direction
= null;
87 public function getDirection() {
88 if ( $this->direction
=== self
::INHERIT_VALUE
) {
89 return $this->context
->getDirection();
91 if ( $this->direction
=== null ) {
92 $this->direction
= Language
::factory( $this->getLanguage() )->getDir();
94 return $this->direction
;
98 * @param string $direction
100 public function setDirection( $direction ) {
101 $this->direction
= $direction;
105 public function getSkin() {
106 if ( $this->skin
=== self
::INHERIT_VALUE
) {
107 return $this->context
->getSkin();
113 * @param string $skin
115 public function setSkin( $skin ) {
120 public function getUser() {
121 if ( $this->user
=== self
::INHERIT_VALUE
) {
122 return $this->context
->getUser();
128 * @param string|null $user
130 public function setUser( $user ) {
133 $this->userObj
= null;
136 public function getDebug() {
137 if ( $this->debug
=== self
::INHERIT_VALUE
) {
138 return $this->context
->getDebug();
146 public function setDebug( $debug ) {
147 $this->debug
= $debug;
151 public function getOnly() {
152 if ( $this->only
=== self
::INHERIT_VALUE
) {
153 return $this->context
->getOnly();
159 * @param string|null $only
161 public function setOnly( $only ) {
166 public function getVersion() {
167 if ( $this->version
=== self
::INHERIT_VALUE
) {
168 return $this->context
->getVersion();
170 return $this->version
;
174 * @param string|null $version
176 public function setVersion( $version ) {
177 $this->version
= $version;
181 public function getRaw() {
182 if ( $this->raw
=== self
::INHERIT_VALUE
) {
183 return $this->context
->getRaw();
191 public function setRaw( $raw ) {
195 public function getRequest() {
196 return $this->context
->getRequest();
199 public function getResourceLoader() {
200 return $this->context
->getResourceLoader();
203 public function getContentOverrideCallback() {
204 if ( $this->contentOverrideCallback
=== self
::INHERIT_VALUE
) {
205 return $this->context
->getContentOverrideCallback();
207 return $this->contentOverrideCallback
;
211 * @see self::getContentOverrideCallback
213 * @param callable|null|int $callback As per self::getContentOverrideCallback,
214 * or self::INHERIT_VALUE
216 public function setContentOverrideCallback( $callback ) {
217 $this->contentOverrideCallback
= $callback;