MediaWiki  1.23.6
ResourceLoaderContext.php
Go to the documentation of this file.
1 <?php
30 
31  /* Protected Members */
32 
33  protected $resourceLoader;
34  protected $request;
35  protected $modules;
36  protected $language;
37  protected $direction;
38  protected $skin;
39  protected $user;
40  protected $debug;
41  protected $only;
42  protected $version;
43  protected $hash;
44  protected $raw;
45 
46  /* Methods */
47 
53  global $wgDefaultSkin, $wgResourceLoaderDebug;
54 
55  $this->resourceLoader = $resourceLoader;
56  $this->request = $request;
57 
58  // Interpret request
59  // List of modules
60  $modules = $request->getVal( 'modules' );
61  $this->modules = $modules ? self::expandModuleNames( $modules ) : array();
62  // Various parameters
63  $this->skin = $request->getVal( 'skin' );
64  $this->user = $request->getVal( 'user' );
65  $this->debug = $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug );
66  $this->only = $request->getVal( 'only' );
67  $this->version = $request->getVal( 'version' );
68  $this->raw = $request->getFuzzyBool( 'raw' );
69 
70  $skinnames = Skin::getSkinNames();
71  // If no skin is specified, or we don't recognize the skin, use the default skin
72  if ( !$this->skin || !isset( $skinnames[$this->skin] ) ) {
73  $this->skin = $wgDefaultSkin;
74  }
75  }
76 
84  public static function expandModuleNames( $modules ) {
85  $retval = array();
86  $exploded = explode( '|', $modules );
87  foreach ( $exploded as $group ) {
88  if ( strpos( $group, ',' ) === false ) {
89  // This is not a set of modules in foo.bar,baz notation
90  // but a single module
91  $retval[] = $group;
92  } else {
93  // This is a set of modules in foo.bar,baz notation
94  $pos = strrpos( $group, '.' );
95  if ( $pos === false ) {
96  // Prefixless modules, i.e. without dots
97  $retval = array_merge( $retval, explode( ',', $group ) );
98  } else {
99  // We have a prefix and a bunch of suffixes
100  $prefix = substr( $group, 0, $pos ); // 'foo'
101  $suffixes = explode( ',', substr( $group, $pos + 1 ) ); // array( 'bar', 'baz' )
102  foreach ( $suffixes as $suffix ) {
103  $retval[] = "$prefix.$suffix";
104  }
105  }
106  }
107  }
108  return $retval;
109  }
110 
115  public static function newDummyContext() {
116  return new self( null, new FauxRequest( array() ) );
117  }
118 
122  public function getResourceLoader() {
123  return $this->resourceLoader;
124  }
125 
129  public function getRequest() {
130  return $this->request;
131  }
132 
136  public function getModules() {
137  return $this->modules;
138  }
139 
143  public function getLanguage() {
144  if ( $this->language === null ) {
145  // Must be a valid language code after this point (bug 62849)
146  $this->language = RequestContext::sanitizeLangCode( $this->request->getVal( 'lang' ) );
147  }
148  return $this->language;
149  }
150 
154  public function getDirection() {
155  if ( $this->direction === null ) {
156  $this->direction = $this->request->getVal( 'dir' );
157  if ( !$this->direction ) {
158  // Determine directionality based on user language (bug 6100)
159  $this->direction = Language::factory( $this->getLanguage() )->getDir();
160  }
161  }
162  return $this->direction;
163  }
164 
168  public function getSkin() {
169  return $this->skin;
170  }
171 
175  public function getUser() {
176  return $this->user;
177  }
178 
182  public function getDebug() {
183  return $this->debug;
184  }
185 
189  public function getOnly() {
190  return $this->only;
191  }
192 
196  public function getVersion() {
197  return $this->version;
198  }
199 
203  public function getRaw() {
204  return $this->raw;
205  }
206 
210  public function shouldIncludeScripts() {
211  return is_null( $this->only ) || $this->only === 'scripts';
212  }
213 
217  public function shouldIncludeStyles() {
218  return is_null( $this->only ) || $this->only === 'styles';
219  }
220 
224  public function shouldIncludeMessages() {
225  return is_null( $this->only ) || $this->only === 'messages';
226  }
227 
231  public function getHash() {
232  if ( !isset( $this->hash ) ) {
233  $this->hash = implode( '|', array(
234  $this->getLanguage(), $this->getDirection(), $this->skin, $this->user,
235  $this->debug, $this->only, $this->version
236  ) );
237  }
238  return $this->hash;
239  }
240 }
ResourceLoaderContext\$hash
$hash
Definition: ResourceLoaderContext.php:43
ResourceLoaderContext
Object passed around to modules which contains information about the state of a specific loader reque...
Definition: ResourceLoaderContext.php:29
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: WebRequest.php:1275
RequestContext\sanitizeLangCode
static sanitizeLangCode( $code)
Accepts a language code and ensures it's sane.
Definition: RequestContext.php:248
ResourceLoaderContext\getDirection
getDirection()
Definition: ResourceLoaderContext.php:154
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ResourceLoaderContext\newDummyContext
static newDummyContext()
Return a dummy ResourceLoaderContext object suitable for passing into things that don't "really" need...
Definition: ResourceLoaderContext.php:115
ResourceLoaderContext\getResourceLoader
getResourceLoader()
Definition: ResourceLoaderContext.php:122
ResourceLoaderContext\$version
$version
Definition: ResourceLoaderContext.php:42
ResourceLoaderContext\$skin
$skin
Definition: ResourceLoaderContext.php:38
ResourceLoaderContext\$direction
$direction
Definition: ResourceLoaderContext.php:37
ResourceLoaderContext\getModules
getModules()
Definition: ResourceLoaderContext.php:136
ResourceLoaderContext\$user
$user
Definition: ResourceLoaderContext.php:39
ResourceLoaderContext\expandModuleNames
static expandModuleNames( $modules)
Expand a string of the form jquery.foo,bar|jquery.ui.baz,quux to an array of module names like array(...
Definition: ResourceLoaderContext.php:84
ResourceLoaderContext\getOnly
getOnly()
Definition: ResourceLoaderContext.php:189
Skin\getSkinNames
static getSkinNames()
Fetch the set of available skins.
Definition: Skin.php:44
ResourceLoaderContext\$modules
$modules
Definition: ResourceLoaderContext.php:35
ResourceLoaderContext\__construct
__construct( $resourceLoader, WebRequest $request)
Definition: ResourceLoaderContext.php:52
ResourceLoaderContext\getRequest
getRequest()
Definition: ResourceLoaderContext.php:129
ResourceLoaderContext\$language
$language
Definition: ResourceLoaderContext.php:36
ResourceLoaderContext\getDebug
getDebug()
Definition: ResourceLoaderContext.php:182
ResourceLoaderContext\$raw
$raw
Definition: ResourceLoaderContext.php:44
version
Prior to version
Definition: maintenance.txt:1
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ResourceLoaderContext\getLanguage
getLanguage()
Definition: ResourceLoaderContext.php:143
ResourceLoaderContext\getVersion
getVersion()
Definition: ResourceLoaderContext.php:196
ResourceLoaderContext\shouldIncludeStyles
shouldIncludeStyles()
Definition: ResourceLoaderContext.php:217
ResourceLoaderContext\$resourceLoader
$resourceLoader
Definition: ResourceLoaderContext.php:33
user
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
skin
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a skin(according to that user 's preference)
ResourceLoaderContext\$debug
$debug
Definition: ResourceLoaderContext.php:40
ResourceLoaderContext\shouldIncludeMessages
shouldIncludeMessages()
Definition: ResourceLoaderContext.php:224
ResourceLoaderContext\getSkin
getSkin()
Definition: ResourceLoaderContext.php:168
ResourceLoaderContext\shouldIncludeScripts
shouldIncludeScripts()
Definition: ResourceLoaderContext.php:210
only
published in in Madrid In the first edition of the Vocabolario for was published In in Rotterdam was the Dictionnaire Universel ! html< p > The first monolingual dictionary written in a Romance language was< i > Sebastián Covarrubias</i >< i > Tesoro de la lengua castellana o published in in Madrid In the first edition of the< i > Vocabolario dell< a href="/index.php?title=Accademia_della_Crusca&amp;action=edit&amp;redlink=1" class="new" title="Accademia della Crusca (page does not exist)"> Accademia della Crusca</a ></i > for was published In in Rotterdam was the< i > Dictionnaire Universel</i ></p > ! end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html php< p >< i > foo</i ></p > ! html parsoid< p >< i > foo</i >< b ></b ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html php< p >< b > foo</b ></p > ! html parsoid< p >< b > foo</b >< i ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html php< p >< b > foo</b ></p > ! html parsoid< p >< b > foo</b >< i ></i ></p > !end ! test Italics and ! options ! wikitext foo ! html< p >< b >< i > foo</i ></b ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html php< p >< b > foo</b > bar</p > ! html parsoid< p >< b > foo</b > bar< i ></i ></p > !end ! test Italics and ! wikitext foo bar ! html php< p >< b > foo</b > bar</p > ! html parsoid< p >< b > foo</b > bar< b ></b ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< i > this is about< b > foo s family</b ></i ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< i > this is about< b > foo s</b > family</i ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< b > this is about< i > foo</i ></b >< i > s family</i ></p > !end ! test Italics and ! options ! wikitext this is about foo s family ! html< p >< i > this is about</i > foo< b > s family</b ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< b > this is about< i > foo s</i > family</b ></p > !end ! test Italicized possessive ! wikitext The s talk page ! html< p > The< i >< a href="/wiki/Main_Page" title="Main Page"> Main Page</a ></i > s talk page</p > ! end ! test Parsoid only
Definition: parserTests.txt:396
ResourceLoaderContext\getUser
getUser()
Definition: ResourceLoaderContext.php:175
WebRequest
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form,...
Definition: WebRequest.php:38
ResourceLoaderContext\$request
$request
Definition: ResourceLoaderContext.php:34
WebRequest\getVal
getVal( $name, $default=null)
Fetch a scalar from the input or return $default if it's not set.
Definition: WebRequest.php:374
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ResourceLoaderContext\$only
$only
Definition: ResourceLoaderContext.php:41
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184
ResourceLoaderContext\getHash
getHash()
Definition: ResourceLoaderContext.php:231
ResourceLoaderContext\getRaw
getRaw()
Definition: ResourceLoaderContext.php:203
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:237
request
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LoginAuthenticateAudit' this hook is for auditing only etc create2 Corresponds to logging log_action database field and which is displayed in the UI similar to $comment this hook should only be used to add variables that depend on the current page request
Definition: hooks.txt:1632