wiki.techinc.nl/includes/ResourceLoaderContext.php
Trevor Parscal 27a1a67359 * Changed the expiry time strategy, now treating any request to ResourceLoader::respond which does not contain a version parameter as an unversioned request which is responded to with a near-future maxage and smaxage, while those which do contain a version parameter are treated as versioned requests and responded to with a far-future maxage and smaxage.
* Added some release notes for ResourceLoader globals.
* Changed when OutputPage appends timestamps to style/script-only requests - now they are only made into versioned requests if the module is a ResourceLoaderWikiModule or a ResourceLoaderUserPreferencesModule - because they might be changed on-wiki and require immediate feedback. This would only affect logged-in users however, as cached pages will contain the latest version number as of the time they were generated. This strategy may need to be adjusted to work with ESI to add version parameters to everything all the time, but this at least presents a reasonable fallback in the event that ESI is not setup.
2010-09-13 23:19:05 +00:00

123 lines
No EOL
3.1 KiB
PHP

<?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 */
protected $request;
protected $modules;
protected $language;
protected $direction;
protected $skin;
protected $user;
protected $debug;
protected $only;
protected $version;
protected $hash;
/* Methods */
public function __construct( WebRequest $request ) {
global $wgLang, $wgDefaultSkin;
$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' );
$this->user = $request->getVal( 'user' );
$this->debug = $request->getBool( 'debug' ) && $request->getVal( 'debug' ) === 'true';
$this->only = $request->getVal( 'only' );
$this->version = $request->getVal( 'version' );
// Fallback on system defaults
if ( !$this->language ) {
$this->language = $wgLang->getCode();
}
if ( !$this->direction ) {
$this->direction = Language::factory( $this->language )->getDir();
}
if ( !$this->skin ) {
$this->skin = $wgDefaultSkin;
}
}
public function getRequest() {
return $this->request;
}
public function getModules() {
return $this->modules;
}
public function getLanguage() {
return $this->language;
}
public function getDirection() {
return $this->direction;
}
public function getSkin() {
return $this->skin;
}
public function getUser() {
return $this->user;
}
public function getDebug() {
return $this->debug;
}
public function getOnly() {
return $this->only;
}
public function getVersion() {
return $this->version;
}
public function shouldIncludeScripts() {
return is_null( $this->only ) || $this->only === 'scripts';
}
public function shouldIncludeStyles() {
return is_null( $this->only ) || $this->only === 'styles';
}
public function shouldIncludeMessages() {
return is_null( $this->only ) || $this->only === 'messages';
}
public function getHash() {
return isset( $this->hash ) ?
$this->hash : $this->hash = implode( '|', array(
$this->language, $this->direction, $this->skin, $this->user, $this->debug, $this->only, $this->version
) );
}
}