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
19 * @author Trevor Parscal
20 * @author Roan Kattouw
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;
45 public function __construct( ResourceLoader
$resourceLoader, WebRequest
$request ) {
46 global $wgDefaultSkin, $wgResourceLoaderDebug;
48 $this->resourceLoader
= $resourceLoader;
49 $this->request
= $request;
53 $modules = $request->getVal( 'modules' );
54 $this->modules
= $modules ?
explode( '|', $modules ) : array();
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' );
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 ) {
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() {
104 public function getUser() {
108 public function getDebug() {
112 public function getOnly() {
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