Fix spaes from r80362
[mediawiki.git] / includes / resourceloader / ResourceLoaderContext.php
blobcbd04a6dd31f88398def241b63ac874416c9a779
1 <?php
2 /**
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
18 * @file
19 * @author Trevor Parscal
20 * @author Roan Kattouw
23 /**
24 * Object passed around to modules which contains information about the state
25 * of a specific loader request
27 class ResourceLoaderContext {
29 /* Protected Members */
31 protected $resourceLoader;
32 protected $request;
33 protected $modules;
34 protected $language;
35 protected $direction;
36 protected $skin;
37 protected $user;
38 protected $debug;
39 protected $only;
40 protected $version;
41 protected $hash;
43 /* Methods */
45 public function __construct( ResourceLoader $resourceLoader, WebRequest $request ) {
46 global $wgDefaultSkin, $wgResourceLoaderDebug;
48 $this->resourceLoader = $resourceLoader;
49 $this->request = $request;
51 // Interpret request
52 // List of modules
53 $modules = $request->getVal( 'modules' );
54 $this->modules = $modules ? explode( '|', $modules ) : array();
55 // Various parameters
56 $this->skin = $request->getVal( 'skin' );
57 $this->user = $request->getVal( 'user' );
58 $this->debug = $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug );
59 $this->only = $request->getVal( 'only' );
60 $this->version = $request->getVal( 'version' );
62 if ( !$this->skin ) {
63 $this->skin = $wgDefaultSkin;
67 public function getResourceLoader() {
68 return $this->resourceLoader;
71 public function getRequest() {
72 return $this->request;
75 public function getModules() {
76 return $this->modules;
79 public function getLanguage() {
80 if ( $this->language === null ) {
81 global $wgLang;
82 $this->language = $this->request->getVal( 'lang' );
83 if ( !$this->language ) {
84 $this->language = $wgLang->getCode();
87 return $this->language;
90 public function getDirection() {
91 if ( $this->direction === null ) {
92 $this->direction = $this->request->getVal( 'dir' );
93 if ( !$this->direction ) {
94 $this->direction = Language::factory( $this->language )->getDir();
97 return $this->direction;
100 public function getSkin() {
101 return $this->skin;
104 public function getUser() {
105 return $this->user;
108 public function getDebug() {
109 return $this->debug;
112 public function getOnly() {
113 return $this->only;
116 public function getVersion() {
117 return $this->version;
120 public function shouldIncludeScripts() {
121 return is_null( $this->only ) || $this->only === 'scripts';
124 public function shouldIncludeStyles() {
125 return is_null( $this->only ) || $this->only === 'styles';
128 public function shouldIncludeMessages() {
129 return is_null( $this->only ) || $this->only === 'messages';
132 public function getHash() {
133 if ( isset( $this->hash ) ) {
134 $this->hash = implode( '|', array(
135 $this->getLanguage(), $this->getDirection(), $this->skin, $this->user,
136 $this->debug, $this->only, $this->version
137 ) );
139 return $this->hash;