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 */
33 protected $resourceLoader;
47 public function __construct( ResourceLoader
$resourceLoader, WebRequest
$request ) {
48 global $wgLang, $wgDefaultSkin, $wgResourceLoaderDebug;
50 $this->resourceLoader
= $resourceLoader;
51 $this->request
= $request;
53 $modules = $request->getVal( 'modules' );
54 $this->modules
= $modules ?
explode( '|', $modules ) : array();
55 $this->language
= $request->getVal( 'lang' );
56 $this->direction
= $request->getVal( 'dir' );
57 $this->skin
= $request->getVal( 'skin' );
58 $this->user
= $request->getVal( 'user' );
59 $this->debug
= $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug );
60 $this->only
= $request->getVal( 'only' );
61 $this->version
= $request->getVal( 'version' );
63 // Fallback on system defaults
64 if ( !$this->language
) {
65 $this->language
= $wgLang->getCode();
68 if ( !$this->direction
) {
69 $this->direction
= Language
::factory( $this->language
)->getDir();
73 $this->skin
= $wgDefaultSkin;
77 public function getResourceLoader() {
78 return $this->resourceLoader
;
81 public function getRequest() {
82 return $this->request
;
85 public function getModules() {
86 return $this->modules
;
89 public function getLanguage() {
90 return $this->language
;
93 public function getDirection() {
94 return $this->direction
;
97 public function getSkin() {
101 public function getUser() {
105 public function getDebug() {
109 public function getOnly() {
113 public function getVersion() {
114 return $this->version
;
117 public function shouldIncludeScripts() {
118 return is_null( $this->only
) ||
$this->only
=== 'scripts';
121 public function shouldIncludeStyles() {
122 return is_null( $this->only
) ||
$this->only
=== 'styles';
125 public function shouldIncludeMessages() {
126 return is_null( $this->only
) ||
$this->only
=== 'messages';
129 public function getHash() {
130 if ( isset( $this->hash
) ) {
131 $this->hash
= implode( '|', array(
132 $this->language
, $this->direction
, $this->skin
, $this->user
,
133 $this->debug
, $this->only
, $this->version