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 * @author Trevor Parscal
19 * @author Roan Kattouw
23 * Object passed around to modules which contains information about the state
24 * of a specific loader request
26 class ResourceLoaderContext
{
27 /* Protected Members */
42 public function __construct( WebRequest
$request ) {
43 global $wgLang, $wgDefaultSkin;
45 $this->request
= $request;
47 $this->modules
= explode( '|', $request->getVal( 'modules' ) );
48 $this->language
= $request->getVal( 'lang' );
49 $this->direction
= $request->getVal( 'dir' );
50 $this->skin
= $request->getVal( 'skin' );
51 $this->user
= $request->getVal( 'user' );
52 $this->debug
= $request->getBool( 'debug' ) && $request->getVal( 'debug' ) === 'true';
53 $this->only
= $request->getVal( 'only' );
54 $this->version
= $request->getVal( 'version' );
56 // Fallback on system defaults
57 if ( !$this->language
) {
58 $this->language
= $wgLang->getCode();
61 if ( !$this->direction
) {
62 $this->direction
= Language
::factory( $this->language
)->getDir();
66 $this->skin
= $wgDefaultSkin;
70 public function getRequest() {
71 return $this->request
;
74 public function getModules() {
75 return $this->modules
;
78 public function getLanguage() {
79 return $this->language
;
82 public function getDirection() {
83 return $this->direction
;
86 public function getSkin() {
90 public function getUser() {
94 public function getDebug() {
98 public function getOnly() {
102 public function getVersion() {
103 return $this->version
;
106 public function shouldIncludeScripts() {
107 return is_null( $this->only
) ||
$this->only
=== 'scripts';
110 public function shouldIncludeStyles() {
111 return is_null( $this->only
) ||
$this->only
=== 'styles';
114 public function shouldIncludeMessages() {
115 return is_null( $this->only
) ||
$this->only
=== 'messages';
118 public function getHash() {
119 if ( isset( $this->hash
) ) {
120 $this->hash
= implode( '|', array(
121 $this->language
, $this->direction
, $this->skin
, $this->user
,
122 $this->debug
, $this->only
, $this->version