2010-09-04 04:00:09 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @author Trevor Parscal
|
|
|
|
|
* @author Roan Kattouw
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Object passed around to modules which contains information about the state of a specific loader request
|
|
|
|
|
*/
|
|
|
|
|
class ResourceLoaderContext {
|
|
|
|
|
/* Protected Members */
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
protected $request;
|
|
|
|
|
protected $modules;
|
|
|
|
|
protected $language;
|
|
|
|
|
protected $direction;
|
|
|
|
|
protected $skin;
|
2010-09-11 03:26:15 +00:00
|
|
|
protected $user;
|
2010-09-04 04:00:09 +00:00
|
|
|
protected $debug;
|
|
|
|
|
protected $only;
|
|
|
|
|
protected $hash;
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/* Methods */
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-11 03:26:15 +00:00
|
|
|
public function __construct( WebRequest $request ) {
|
2010-09-04 13:27:12 +00:00
|
|
|
global $wgLang, $wgDefaultSkin;
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
$this->request = $request;
|
|
|
|
|
// Interperet request
|
|
|
|
|
$this->modules = explode( '|', $request->getVal( 'modules' ) );
|
|
|
|
|
$this->language = $request->getVal( 'lang' );
|
|
|
|
|
$this->direction = $request->getVal( 'dir' );
|
|
|
|
|
$this->skin = $request->getVal( 'skin' );
|
2010-09-11 03:26:15 +00:00
|
|
|
$this->user = $request->getVal( 'user' );
|
|
|
|
|
$this->debug = $request->getBool( 'debug' ) && $request->getVal( 'debug' ) === 'true';
|
2010-09-04 04:00:09 +00:00
|
|
|
$this->only = $request->getVal( 'only' );
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
// Fallback on system defaults
|
|
|
|
|
if ( !$this->language ) {
|
|
|
|
|
$this->language = $wgLang->getCode();
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
if ( !$this->direction ) {
|
|
|
|
|
$this->direction = Language::factory( $this->language )->getDir();
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
if ( !$this->skin ) {
|
|
|
|
|
$this->skin = $wgDefaultSkin;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-11 08:03:11 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function getRequest() {
|
|
|
|
|
return $this->request;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function getModules() {
|
|
|
|
|
return $this->modules;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function getLanguage() {
|
|
|
|
|
return $this->language;
|
|
|
|
|
}
|
2010-09-04 10:28:41 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function getDirection() {
|
|
|
|
|
return $this->direction;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function getSkin() {
|
|
|
|
|
return $this->skin;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-11 03:26:15 +00:00
|
|
|
public function getUser() {
|
2010-09-11 07:33:16 +00:00
|
|
|
return $this->user;
|
2010-09-11 03:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function getDebug() {
|
|
|
|
|
return $this->debug;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function getOnly() {
|
|
|
|
|
return $this->only;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function shouldIncludeScripts() {
|
|
|
|
|
return is_null( $this->only ) || $this->only === 'scripts';
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function shouldIncludeStyles() {
|
|
|
|
|
return is_null( $this->only ) || $this->only === 'styles';
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function shouldIncludeMessages() {
|
|
|
|
|
return is_null( $this->only ) || $this->only === 'messages';
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
public function getHash() {
|
|
|
|
|
return isset( $this->hash ) ?
|
2010-09-11 08:22:32 +00:00
|
|
|
$this->hash : $this->hash = implode( '|', array(
|
|
|
|
|
$this->language, $this->direction, $this->skin, $this->user, $this->debug, $this->only
|
|
|
|
|
) );
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-09-11 08:03:11 +00:00
|
|
|
}
|