http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72315
Revision: 72315
Author: tparscal
Date: 2010-09-03 21:33:59 +0000 (Fri, 03 Sep 2010)
Log Message:
-----------
Added getHash to ResourceLoaderContext. Moved special casing of startup module
to ResourceLoaderStartupModule
Modified Paths:
--------------
branches/resourceloader/phase3/includes/ResourceLoader.php
branches/resourceloader/phase3/includes/ResourceLoaderContext.php
branches/resourceloader/phase3/includes/ResourceLoaderModule.php
Modified: branches/resourceloader/phase3/includes/ResourceLoader.php
===================================================================
--- branches/resourceloader/phase3/includes/ResourceLoader.php 2010-09-03
21:17:33 UTC (rev 72314)
+++ branches/resourceloader/phase3/includes/ResourceLoader.php 2010-09-03
21:33:59 UTC (rev 72315)
@@ -218,6 +218,8 @@
return $time;
}
+ /* Methods */
+
/*
* Outputs a response to a resource load-request, including a
content-type header
*
@@ -280,38 +282,6 @@
$scripts = '';
if ( $context->shouldIncludeScripts() ) {
$scripts .= self::$modules[$name]->getScript(
$context );
- // Special meta-information for the 'startup'
module
- if ( $name === 'startup' && $context->getOnly()
=== 'scripts' ) {
- // Get all module registrations
- $registration =
self::getModuleRegistrations( $context );
- // Build configuration
- $config = FormatJson::encode(
- array( 'server' =>
$context->getServer(), 'debug' => $context->getDebug() )
- );
- // Add a well-known start-up function
- $scripts .= "window.startUp =
function() { $registration mediaWiki.config.set( $config ); };";
- // Build load query for jquery and
mediawiki modules
- $query = wfArrayToCGI(
- array(
- 'modules' => implode(
'|', array( 'jquery', 'mediawiki' ) ),
- 'only' => 'scripts',
- 'lang' =>
$context->getLanguage(),
- 'dir' =>
$context->getDirection(),
- 'skin' =>
$context->getSkin(),
- 'debug' =>
$context->getDebug(),
- 'version' =>
wfTimestamp( TS_ISO_8601, round( max(
-
self::$modules['jquery']->getModifiedTime( $context ),
-
self::$modules['mediawiki']->getModifiedTime( $context )
- ), -2 ) )
- )
- );
- // Build HTML code for loading jquery
and mediawiki modules
- $loadScript = Html::linkedScript(
$context->getServer() . "?$query" );
- // Add code to add jquery and mediawiki
loading code; only if the current client is compatible
- $scripts .= "if ( isCompatible() ) {
document.write( '$loadScript' ); }";
- // Delete the compatible function -
it's not needed anymore
- $scripts .= "delete
window['isCompatible'];";
- }
}
// Styles
$styles = '';
@@ -335,7 +305,7 @@
echo "mediaWiki.msg.set( $messages );\n";
} else {
$styles = Xml::escapeJsString( $styles );
- echo "mediaWiki.loader.implement( '{$name}',
function() {{$scripts}},\n'{$styles}',\n{$messages} );\n";
+ echo "mediaWiki.loader.implement( '$name',
function() {{$scripts}},\n'$styles',\n$messages );\n";
}
}
// Update the status of script-only modules
@@ -345,12 +315,12 @@
$statuses[$name] = 'ready';
}
$statuses = FormatJson::encode( $statuses );
- echo "mediaWiki.loader.state( {$statuses} );";
+ echo "mediaWiki.loader.state( $statuses );";
}
// Register missing modules
if ( $context->shouldIncludeScripts() ) {
foreach ( $missing as $name ) {
- echo "mediaWiki.loader.register( '{$name}',
null, 'missing' );\n";
+ echo "mediaWiki.loader.register( '$name', null,
'missing' );\n";
}
}
// Output the appropriate header
Modified: branches/resourceloader/phase3/includes/ResourceLoaderContext.php
===================================================================
--- branches/resourceloader/phase3/includes/ResourceLoaderContext.php
2010-09-03 21:17:33 UTC (rev 72314)
+++ branches/resourceloader/phase3/includes/ResourceLoaderContext.php
2010-09-03 21:33:59 UTC (rev 72315)
@@ -24,6 +24,8 @@
*/
class ResourceLoaderContext {
+ /* Protected Members */
+
protected $request;
protected $server;
protected $modules;
@@ -32,7 +34,10 @@
protected $skin;
protected $debug;
protected $only;
+ protected $hash;
+ /* Methods */
+
public function __construct( WebRequest $request, $server ) {
global $wgUser, $wgLang, $wgDefaultSkin;
@@ -56,37 +61,53 @@
$this->skin = $wgDefaultSkin;
}
}
+
public function getRequest() {
return $this->request;
}
+
public function getServer() {
return $this->server;
}
+
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 getDebug() {
return $this->debug;
}
+
public function getOnly() {
return $this->only;
}
+
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->skin, $this->debug ) );
+ }
}
\ No newline at end of file
Modified: branches/resourceloader/phase3/includes/ResourceLoaderModule.php
===================================================================
--- branches/resourceloader/phase3/includes/ResourceLoaderModule.php
2010-09-03 21:17:33 UTC (rev 72314)
+++ branches/resourceloader/phase3/includes/ResourceLoaderModule.php
2010-09-03 21:33:59 UTC (rev 72315)
@@ -22,8 +22,13 @@
* Interface for resource loader modules, with name registration and maxage
functionality.
*/
abstract class ResourceLoaderModule {
- private $name = null;
+ /* Protected Members */
+
+ protected $name = null;
+
+ /* Methods */
+
/**
* Get this module's name. This is set when the module is registered
* with ResourceLoader::register()
@@ -130,23 +135,26 @@
* Module based on local JS/CSS files. This is the most common type of module.
*/
class ResourceLoaderFileModule extends ResourceLoaderModule {
- private $scripts = array();
- private $styles = array();
- private $messages = array();
- private $dependencies = array();
- private $debugScripts = array();
- private $languageScripts = array();
- private $skinScripts = array();
- private $skinStyles = array();
- private $loaders = array();
- private $parameters = array();
+ /* Protected Members */
+
+ protected $scripts = array();
+ protected $styles = array();
+ protected $messages = array();
+ protected $dependencies = array();
+ protected $debugScripts = array();
+ protected $languageScripts = array();
+ protected $skinScripts = array();
+ protected $skinStyles = array();
+ protected $loaders = array();
+ protected $parameters = array();
+
// In-object cache for file dependencies
- private $fileDeps = array();
+ protected $fileDeps = array();
// In-object cache for mtime
- private $modifiedTime = array();
+ protected $modifiedTime = array();
- /* Public methods */
+ /* Methods */
/**
* Construct a new module from an options array.
@@ -384,9 +392,8 @@
* @return int UNIX timestamp
*/
public function getModifiedTime( ResourceLoaderContext $context ) {
- $hash = implode( '|', array( $context->getLanguage(),
$context->getSkin(), $context->getDebug() ) );
- if ( isset( $this->modifiedTime[$hash] ) ) {
- return $this->modifiedTime[$hash];
+ if ( isset( $this->modifiedTime[$context->getHash()] ) ) {
+ return $this->modifiedTime[$context->getHash()];
}
$files = array_merge(
@@ -400,12 +407,14 @@
$this->loaders,
$this->getFileDependencies( $context->getSkin() )
);
- $this->modifiedTime[$hash] = max(
+ $this->modifiedTime[$context->getHash()] = max(
array_map( 'filemtime', array_map( array( __CLASS__,
'remapFilename' ), $files ) )
);
- return $this->modifiedTime[$hash];
+ return $this->modifiedTime[$context->getHash()];
}
+ /* Protected Members */
+
/**
* Get the primary JS for this module. This is pulled from the
* script files added through addScripts()
@@ -558,17 +567,21 @@
* TODO: Add Site CSS functionality too
*/
class ResourceLoaderSiteModule extends ResourceLoaderModule {
+
+ /* Protected Members */
+
// In-object cache for modified time
- private $modifiedTime = null;
+ protected $modifiedTime = null;
+ /* Methods */
+
public function getScript( ResourceLoaderContext $context ) {
return Skin::newFromKey( $context->getSkin()
)->generateUserJs();
}
public function getModifiedTime( ResourceLoaderContext $context ) {
- $hash = implode( '|', array( $context->getLanguage(),
$context->getSkin(), $context->getDebug() ) );
- if ( isset( $this->modifiedTime[$hash] ) ) {
- return $this->modifiedTime[$hash];
+ if ( isset( $this->modifiedTime[$context->getHash()] ) ) {
+ return $this->modifiedTime[$context->getHash()];
}
// HACK: We duplicate the message names from generateUserJs()
@@ -600,11 +613,49 @@
class ResourceLoaderStartUpModule extends ResourceLoaderModule {
- private $modifiedTime = null;
+ /* Protected Members */
+
+ protected $modifiedTime = null;
+
+ /* Methods */
+
public function getScript( ResourceLoaderContext $context ) {
global $IP;
- return file_get_contents( "$IP/resources/startup.js" );
+
+ $scripts = file_get_contents( "$IP/resources/startup.js" );
+ if ( $context->getOnly() === 'scripts' ) {
+ // Get all module registrations
+ $registration = ResourceLoader::getModuleRegistrations(
$context );
+ // Build configuration
+ $config = FormatJson::encode(
+ array( 'server' => $context->getServer(),
'debug' => $context->getDebug() )
+ );
+ // Add a well-known start-up function
+ $scripts .= "window.startUp = function() {
$registration mediaWiki.config.set( $config ); };";
+ // Build load query for jquery and mediawiki modules
+ $query = wfArrayToCGI(
+ array(
+ 'modules' => implode( '|', array(
'jquery', 'mediawiki' ) ),
+ 'only' => 'scripts',
+ 'lang' => $context->getLanguage(),
+ 'dir' => $context->getDirection(),
+ 'skin' => $context->getSkin(),
+ 'debug' => $context->getDebug(),
+ 'version' => wfTimestamp( TS_ISO_8601,
round( max(
+ ResourceLoader::getModule(
'jquery' )->getModifiedTime( $context ),
+ ResourceLoader::getModule(
'mediawiki' )->getModifiedTime( $context )
+ ), -2 ) )
+ )
+ );
+ // Build HTML code for loading jquery and mediawiki
modules
+ $loadScript = Html::linkedScript( $context->getServer()
. "?$query" );
+ // Add code to add jquery and mediawiki loading code;
only if the current client is compatible
+ $scripts .= "if ( isCompatible() ) { document.write(
'$loadScript' ); }";
+ // Delete the compatible function - it's not needed
anymore
+ $scripts .= "delete window['isCompatible'];";
+ }
+ return $scripts;
}
public function getModifiedTime( ResourceLoaderContext $context ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs