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
23 defined( 'MEDIAWIKI' ) ||
die( 1 );
26 * Object passed around to modules which contains information about the state
27 * of a specific loader request
29 class ResourceLoaderContext
{
31 /* Protected Members */
46 public function __construct( WebRequest
$request ) {
47 global $wgLang, $wgDefaultSkin, $wgResourceLoaderDebug;
49 $this->request
= $request;
51 $this->modules
= explode( '|', $request->getVal( 'modules' ) );
52 $this->language
= $request->getVal( 'lang' );
53 $this->direction
= $request->getVal( 'dir' );
54 $this->skin
= $request->getVal( 'skin' );
55 $this->user
= $request->getVal( 'user' );
56 $this->debug
= $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug );
57 $this->only
= $request->getVal( 'only' );
58 $this->version
= $request->getVal( 'version' );
60 // Fallback on system defaults
61 if ( !$this->language
) {
62 $this->language
= $wgLang->getCode();
65 if ( !$this->direction
) {
66 $this->direction
= Language
::factory( $this->language
)->getDir();
70 $this->skin
= $wgDefaultSkin;
74 public function getRequest() {
75 return $this->request
;
78 public function getModules() {
79 return $this->modules
;
82 public function getLanguage() {
83 return $this->language
;
86 public function getDirection() {
87 return $this->direction
;
90 public function getSkin() {
94 public function getUser() {
98 public function getDebug() {
102 public function getOnly() {
106 public function getVersion() {
107 return $this->version
;
110 public function shouldIncludeScripts() {
111 return is_null( $this->only
) ||
$this->only
=== 'scripts';
114 public function shouldIncludeStyles() {
115 return is_null( $this->only
) ||
$this->only
=== 'styles';
118 public function shouldIncludeMessages() {
119 return is_null( $this->only
) ||
$this->only
=== 'messages';
122 public function getHash() {
123 if ( isset( $this->hash
) ) {
124 $this->hash
= implode( '|', array(
125 $this->language
, $this->direction
, $this->skin
, $this->user
,
126 $this->debug
, $this->only
, $this->version