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 $wgLang, $wgDefaultSkin, $wgResourceLoaderDebug;
48 $this->resourceLoader
= $resourceLoader;
49 $this->request
= $request;
53 $modules = $request->getVal( 'modules' );
54 $this->modules
= $modules ?
explode( '|', $modules ) : array();
56 $this->language
= $request->getVal( 'lang' );
57 $this->direction
= $request->getVal( 'dir' );
58 $this->skin
= $request->getVal( 'skin' );
59 $this->user
= $request->getVal( 'user' );
60 $this->debug
= $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug );
61 $this->only
= $request->getVal( 'only' );
62 $this->version
= $request->getVal( 'version' );
64 // Fallback on system defaults
65 if ( !$this->language
) {
66 $this->language
= $wgLang->getCode();
69 if ( !$this->direction
) {
70 $this->direction
= Language
::factory( $this->language
)->getDir();
74 $this->skin
= $wgDefaultSkin;
78 public function getResourceLoader() {
79 return $this->resourceLoader
;
82 public function getRequest() {
83 return $this->request
;
86 public function getModules() {
87 return $this->modules
;
90 public function getLanguage() {
91 return $this->language
;
94 public function getDirection() {
95 return $this->direction
;
98 public function getSkin() {
102 public function getUser() {
106 public function getDebug() {
110 public function getOnly() {
114 public function getVersion() {
115 return $this->version
;
118 public function shouldIncludeScripts() {
119 return is_null( $this->only
) ||
$this->only
=== 'scripts';
122 public function shouldIncludeStyles() {
123 return is_null( $this->only
) ||
$this->only
=== 'styles';
126 public function shouldIncludeMessages() {
127 return is_null( $this->only
) ||
$this->only
=== 'messages';
130 public function getHash() {
131 if ( isset( $this->hash
) ) {
132 $this->hash
= implode( '|', array(
133 $this->language
, $this->direction
, $this->skin
, $this->user
,
134 $this->debug
, $this->only
, $this->version