MediaWiki  master
DerivativeResourceLoaderContext.php
Go to the documentation of this file.
1 <?php
23 
34  private const INHERIT_VALUE = -1;
35 
39  private $context;
40 
53 
55  $this->context = $context;
56  }
57 
58  public function getModules() : array {
59  if ( $this->modules === self::INHERIT_VALUE ) {
60  return $this->context->getModules();
61  }
62 
63  return $this->modules;
64  }
65 
69  public function setModules( array $modules ) {
70  $this->modules = $modules;
71  }
72 
73  public function getLanguage() : string {
74  if ( $this->language === self::INHERIT_VALUE ) {
75  return $this->context->getLanguage();
76  }
77  return $this->language;
78  }
79 
80  public function setLanguage( string $language ) {
81  $this->language = $language;
82  // Invalidate direction since it is based on language
83  $this->direction = null;
84  $this->hash = null;
85  }
86 
87  public function getDirection() : string {
88  if ( $this->direction === self::INHERIT_VALUE ) {
89  return $this->context->getDirection();
90  }
91  if ( $this->direction === null ) {
92  $this->direction = MediaWikiServices::getInstance()->getLanguageFactory()
93  ->getLanguage( $this->getLanguage() )->getDir();
94  }
95  return $this->direction;
96  }
97 
98  public function setDirection( string $direction ) {
99  $this->direction = $direction;
100  $this->hash = null;
101  }
102 
103  public function getSkin() : string {
104  if ( $this->skin === self::INHERIT_VALUE ) {
105  return $this->context->getSkin();
106  }
107  return $this->skin;
108  }
109 
110  public function setSkin( string $skin ) {
111  $this->skin = $skin;
112  $this->hash = null;
113  }
114 
115  public function getUser() : ?string {
116  if ( $this->user === self::INHERIT_VALUE ) {
117  return $this->context->getUser();
118  }
119  return $this->user;
120  }
121 
122  public function getUserObj() : User {
123  if ( $this->userObj === self::INHERIT_VALUE ) {
124  return $this->context->getUserObj();
125  }
126  if ( $this->userObj === null ) {
127  $username = $this->getUser();
128  if ( $username ) {
129  $this->userObj = User::newFromName( $username ) ?: new User;
130  } else {
131  $this->userObj = new User;
132  }
133  }
134  return $this->userObj;
135  }
136 
140  public function setUser( ?string $user ) {
141  $this->user = $user;
142  $this->hash = null;
143  // Clear getUserObj cache
144  $this->userObj = null;
145  }
146 
147  public function getDebug() : bool {
148  if ( $this->debug === self::INHERIT_VALUE ) {
149  return $this->context->getDebug();
150  }
151  return $this->debug;
152  }
153 
154  public function setDebug( bool $debug ) {
155  $this->debug = $debug;
156  $this->hash = null;
157  }
158 
159  public function getOnly() : ?string {
160  if ( $this->only === self::INHERIT_VALUE ) {
161  return $this->context->getOnly();
162  }
163  return $this->only;
164  }
165 
169  public function setOnly( ?string $only ) {
170  $this->only = $only;
171  $this->hash = null;
172  }
173 
174  public function getVersion() : ?string {
175  if ( $this->version === self::INHERIT_VALUE ) {
176  return $this->context->getVersion();
177  }
178  return $this->version;
179  }
180 
184  public function setVersion( ?string $version ) {
185  $this->version = $version;
186  $this->hash = null;
187  }
188 
189  public function getRaw() : bool {
190  if ( $this->raw === self::INHERIT_VALUE ) {
191  return $this->context->getRaw();
192  }
193  return $this->raw;
194  }
195 
196  public function setRaw( bool $raw ) {
197  $this->raw = $raw;
198  }
199 
200  public function getRequest() : WebRequest {
201  return $this->context->getRequest();
202  }
203 
204  public function getResourceLoader() : ResourceLoader {
205  return $this->context->getResourceLoader();
206  }
207 
208  public function getContentOverrideCallback() {
209  if ( $this->contentOverrideCallback === self::INHERIT_VALUE ) {
210  return $this->context->getContentOverrideCallback();
211  }
213  }
214 
221  public function setContentOverrideCallback( $callback ) {
222  $this->contentOverrideCallback = $callback;
223  }
224 
225 }
ResourceLoaderContext
Context object that contains information about the state of a specific ResourceLoader web request.
Definition: ResourceLoaderContext.php:33
DerivativeResourceLoaderContext\$skin
$skin
Definition: DerivativeResourceLoaderContext.php:45
DerivativeResourceLoaderContext\getContentOverrideCallback
getContentOverrideCallback()
Return the replaced-content mapping callback.
Definition: DerivativeResourceLoaderContext.php:208
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:149
DerivativeResourceLoaderContext\getResourceLoader
getResourceLoader()
Definition: DerivativeResourceLoaderContext.php:204
DerivativeResourceLoaderContext\$raw
$raw
Definition: DerivativeResourceLoaderContext.php:51
DerivativeResourceLoaderContext\setUser
setUser(?string $user)
Definition: DerivativeResourceLoaderContext.php:140
DerivativeResourceLoaderContext\setSkin
setSkin(string $skin)
Definition: DerivativeResourceLoaderContext.php:110
DerivativeResourceLoaderContext\getRequest
getRequest()
Definition: DerivativeResourceLoaderContext.php:200
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:534
DerivativeResourceLoaderContext\$modules
int array $modules
Definition: DerivativeResourceLoaderContext.php:42
DerivativeResourceLoaderContext\$debug
$debug
Definition: DerivativeResourceLoaderContext.php:48
DerivativeResourceLoaderContext\setRaw
setRaw(bool $raw)
Definition: DerivativeResourceLoaderContext.php:196
DerivativeResourceLoaderContext\$contentOverrideCallback
$contentOverrideCallback
Definition: DerivativeResourceLoaderContext.php:52
DerivativeResourceLoaderContext\getModules
getModules()
Definition: DerivativeResourceLoaderContext.php:58
DerivativeResourceLoaderContext\getSkin
getSkin()
Definition: DerivativeResourceLoaderContext.php:103
DerivativeResourceLoaderContext\setContentOverrideCallback
setContentOverrideCallback( $callback)
Definition: DerivativeResourceLoaderContext.php:221
DerivativeResourceLoaderContext\setModules
setModules(array $modules)
Definition: DerivativeResourceLoaderContext.php:69
DerivativeResourceLoaderContext\setVersion
setVersion(?string $version)
Definition: DerivativeResourceLoaderContext.php:184
DerivativeResourceLoaderContext\setDebug
setDebug(bool $debug)
Definition: DerivativeResourceLoaderContext.php:154
DerivativeResourceLoaderContext\setLanguage
setLanguage(string $language)
Definition: DerivativeResourceLoaderContext.php:80
DerivativeResourceLoaderContext\setOnly
setOnly(?string $only)
Definition: DerivativeResourceLoaderContext.php:169
DerivativeResourceLoaderContext\$context
ResourceLoaderContext $context
Definition: DerivativeResourceLoaderContext.php:39
DerivativeResourceLoaderContext\getOnly
getOnly()
Definition: DerivativeResourceLoaderContext.php:159
DerivativeResourceLoaderContext\getRaw
getRaw()
Definition: DerivativeResourceLoaderContext.php:189
DerivativeResourceLoaderContext\$version
$version
Definition: DerivativeResourceLoaderContext.php:50
DerivativeResourceLoaderContext\$user
$user
Definition: DerivativeResourceLoaderContext.php:46
DerivativeResourceLoaderContext\$userObj
$userObj
Definition: DerivativeResourceLoaderContext.php:47
DerivativeResourceLoaderContext
A mutable version of ResourceLoaderContext.
Definition: DerivativeResourceLoaderContext.php:33
DerivativeResourceLoaderContext\getDirection
getDirection()
Definition: DerivativeResourceLoaderContext.php:87
WebRequest
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
Definition: WebRequest.php:43
DerivativeResourceLoaderContext\$language
$language
Definition: DerivativeResourceLoaderContext.php:43
ResourceLoader
ResourceLoader is a loading system for JavaScript and CSS resources.
Definition: ResourceLoader.php:56
DerivativeResourceLoaderContext\INHERIT_VALUE
const INHERIT_VALUE
Definition: DerivativeResourceLoaderContext.php:34
DerivativeResourceLoaderContext\getLanguage
getLanguage()
Definition: DerivativeResourceLoaderContext.php:73
DerivativeResourceLoaderContext\setDirection
setDirection(string $direction)
Definition: DerivativeResourceLoaderContext.php:98
DerivativeResourceLoaderContext\getVersion
getVersion()
Definition: DerivativeResourceLoaderContext.php:174
DerivativeResourceLoaderContext\getUserObj
getUserObj()
Get the possibly-cached User object for the specified username.
Definition: DerivativeResourceLoaderContext.php:122
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:55
DerivativeResourceLoaderContext\getUser
getUser()
Definition: DerivativeResourceLoaderContext.php:115
DerivativeResourceLoaderContext\__construct
__construct(ResourceLoaderContext $context)
Definition: DerivativeResourceLoaderContext.php:54
DerivativeResourceLoaderContext\$direction
$direction
Definition: DerivativeResourceLoaderContext.php:44
DerivativeResourceLoaderContext\$only
$only
Definition: DerivativeResourceLoaderContext.php:49
DerivativeResourceLoaderContext\getDebug
getDebug()
Definition: DerivativeResourceLoaderContext.php:147