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
|
|
|
|
|
*
|
2010-09-05 13:31:34 +00:00
|
|
|
* @file
|
2010-09-04 04:00:09 +00:00
|
|
|
* @author Roan Kattouw
|
|
|
|
|
* @author Trevor Parscal
|
|
|
|
|
*/
|
|
|
|
|
|
2010-09-05 13:31:34 +00:00
|
|
|
/**
|
2010-10-19 20:45:02 +00:00
|
|
|
* Dynamic JavaScript and CSS resource loading system.
|
|
|
|
|
*
|
2010-10-20 00:22:25 +00:00
|
|
|
* Most of the documention is on the MediaWiki documentation wiki starting at:
|
2010-10-19 20:45:02 +00:00
|
|
|
* http://www.mediawiki.org/wiki/ResourceLoader
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
|
|
|
|
class ResourceLoader {
|
2010-09-13 23:19:05 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/* Protected Static Members */
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-11-05 18:33:50 +00:00
|
|
|
/** Array: List of module name/ResourceLoaderModule object pairs */
|
2010-09-29 19:04:04 +00:00
|
|
|
protected $modules = array();
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-29 19:04:04 +00:00
|
|
|
/* Protected Methods */
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-29 19:04:04 +00:00
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Loads information stored in the database about modules.
|
|
|
|
|
*
|
2010-11-03 07:58:03 +00:00
|
|
|
* This method grabs modules dependencies from the database and updates modules
|
|
|
|
|
* objects.
|
2010-09-24 18:49:19 +00:00
|
|
|
*
|
2010-11-19 06:52:38 +00:00
|
|
|
* This is not inside the module code because it is much faster to
|
2010-11-03 07:58:03 +00:00
|
|
|
* request all of the information at once than it is to have each module
|
2010-11-19 06:52:38 +00:00
|
|
|
* requests its own information. This sacrifice of modularity yields a substantial
|
2010-10-20 00:22:25 +00:00
|
|
|
* performance improvement.
|
|
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $modules Array: List of module names to preload information for
|
|
|
|
|
* @param $context ResourceLoaderContext: Context to load the information within
|
2010-09-24 18:49:19 +00:00
|
|
|
*/
|
2010-09-29 19:04:04 +00:00
|
|
|
protected function preloadModuleInfo( array $modules, ResourceLoaderContext $context ) {
|
2010-10-02 10:18:48 +00:00
|
|
|
if ( !count( $modules ) ) {
|
2010-10-20 00:22:25 +00:00
|
|
|
return; // or else Database*::select() will explode, plus it's cheaper!
|
2010-10-02 10:18:48 +00:00
|
|
|
}
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2010-09-23 21:23:51 +00:00
|
|
|
$skin = $context->getSkin();
|
|
|
|
|
$lang = $context->getLanguage();
|
|
|
|
|
|
|
|
|
|
// Get file dependency information
|
|
|
|
|
$res = $dbr->select( 'module_deps', array( 'md_module', 'md_deps' ), array(
|
|
|
|
|
'md_module' => $modules,
|
|
|
|
|
'md_skin' => $context->getSkin()
|
|
|
|
|
), __METHOD__
|
|
|
|
|
);
|
2010-10-19 20:45:02 +00:00
|
|
|
|
2010-10-20 14:58:35 +00:00
|
|
|
// Set modules' dependecies
|
2010-09-23 21:23:51 +00:00
|
|
|
$modulesWithDeps = array();
|
|
|
|
|
foreach ( $res as $row ) {
|
2010-09-29 19:04:04 +00:00
|
|
|
$this->modules[$row->md_module]->setFileDependencies( $skin,
|
2010-09-23 21:23:51 +00:00
|
|
|
FormatJson::decode( $row->md_deps, true )
|
|
|
|
|
);
|
|
|
|
|
$modulesWithDeps[] = $row->md_module;
|
|
|
|
|
}
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-10-19 20:45:02 +00:00
|
|
|
// Register the absence of a dependency row too
|
2010-09-23 21:23:51 +00:00
|
|
|
foreach ( array_diff( $modules, $modulesWithDeps ) as $name ) {
|
2010-09-29 19:04:04 +00:00
|
|
|
$this->modules[$name]->setFileDependencies( $skin, array() );
|
2010-09-23 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get message blob mtimes. Only do this for modules with messages
|
|
|
|
|
$modulesWithMessages = array();
|
|
|
|
|
$modulesWithoutMessages = array();
|
|
|
|
|
foreach ( $modules as $name ) {
|
2010-09-29 19:04:04 +00:00
|
|
|
if ( count( $this->modules[$name]->getMessages() ) ) {
|
2010-09-23 21:23:51 +00:00
|
|
|
$modulesWithMessages[] = $name;
|
|
|
|
|
} else {
|
|
|
|
|
$modulesWithoutMessages[] = $name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( count( $modulesWithMessages ) ) {
|
|
|
|
|
$res = $dbr->select( 'msg_resource', array( 'mr_resource', 'mr_timestamp' ), array(
|
|
|
|
|
'mr_resource' => $modulesWithMessages,
|
|
|
|
|
'mr_lang' => $lang
|
|
|
|
|
), __METHOD__
|
|
|
|
|
);
|
|
|
|
|
foreach ( $res as $row ) {
|
2010-09-29 19:04:04 +00:00
|
|
|
$this->modules[$row->mr_resource]->setMsgBlobMtime( $lang, $row->mr_timestamp );
|
2010-09-23 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach ( $modulesWithoutMessages as $name ) {
|
2010-09-29 19:04:04 +00:00
|
|
|
$this->modules[$name]->setMsgBlobMtime( $lang, 0 );
|
2010-09-23 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-09-15 18:27:47 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Runs JavaScript or CSS data through a filter, caching the filtered result for future calls.
|
2010-10-19 20:45:02 +00:00
|
|
|
*
|
2010-10-20 14:58:35 +00:00
|
|
|
* Available filters are:
|
2010-10-19 20:45:02 +00:00
|
|
|
* - minify-js \see JSMin::minify
|
|
|
|
|
* - minify-css \see CSSMin::minify
|
|
|
|
|
* - flip-css \see CSSJanus::transform
|
2010-10-20 00:22:25 +00:00
|
|
|
*
|
2010-11-03 07:58:03 +00:00
|
|
|
* If $data is empty, only contains whitespace or the filter was unknown,
|
|
|
|
|
* $data is returned unmodified.
|
2010-10-20 00:22:25 +00:00
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $filter String: Name of filter to run
|
|
|
|
|
* @param $data String: Text to filter, such as JavaScript or CSS text
|
|
|
|
|
* @return String: Filtered data
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
2010-09-29 19:04:04 +00:00
|
|
|
protected function filter( $filter, $data ) {
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-11-03 07:58:03 +00:00
|
|
|
// For empty/whitespace-only data or for unknown filters, don't perform
|
|
|
|
|
// any caching or processing
|
|
|
|
|
if ( trim( $data ) === ''
|
|
|
|
|
|| !in_array( $filter, array( 'minify-js', 'minify-css', 'flip-css' ) ) )
|
|
|
|
|
{
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2010-09-04 04:00:09 +00:00
|
|
|
return $data;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-11-19 01:40:00 +00:00
|
|
|
// Try for cache hit
|
|
|
|
|
// Use CACHE_ANYTHING since filtering is very slow compared to DB queries
|
2010-09-04 04:00:09 +00:00
|
|
|
$key = wfMemcKey( 'resourceloader', 'filter', $filter, md5( $data ) );
|
2010-11-19 01:40:00 +00:00
|
|
|
$cache = wfGetCache( CACHE_ANYTHING );
|
|
|
|
|
$cacheEntry = $cache->get( $key );
|
2010-11-03 07:58:03 +00:00
|
|
|
if ( is_string( $cacheEntry ) ) {
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2010-11-03 07:58:03 +00:00
|
|
|
return $cacheEntry;
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-10-20 00:22:25 +00:00
|
|
|
// Run the filter - we've already verified one of these will work
|
2010-09-04 04:00:09 +00:00
|
|
|
try {
|
|
|
|
|
switch ( $filter ) {
|
|
|
|
|
case 'minify-js':
|
|
|
|
|
$result = JSMin::minify( $data );
|
|
|
|
|
break;
|
|
|
|
|
case 'minify-css':
|
|
|
|
|
$result = CSSMin::minify( $data );
|
|
|
|
|
break;
|
|
|
|
|
case 'flip-css':
|
|
|
|
|
$result = CSSJanus::transform( $data, true, false );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} catch ( Exception $exception ) {
|
2010-11-03 07:58:03 +00:00
|
|
|
throw new MWException( 'ResourceLoader filter error. ' .
|
|
|
|
|
'Exception was thrown: ' . $exception->getMessage() );
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-10-20 00:22:25 +00:00
|
|
|
// Save filtered text to Memcached
|
2010-11-19 01:40:00 +00:00
|
|
|
$cache->set( $key, $result );
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-29 19:04:04 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Registers core modules and runs registration hooks.
|
2010-09-29 19:04:04 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct() {
|
|
|
|
|
global $IP;
|
|
|
|
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
// Register core modules
|
|
|
|
|
$this->register( include( "$IP/resources/Resources.php" ) );
|
|
|
|
|
// Register extension modules
|
|
|
|
|
wfRunHooks( 'ResourceLoaderRegisterModules', array( &$this ) );
|
|
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
|
|
|
|
* Registers a module with the ResourceLoader system.
|
2010-10-20 00:22:25 +00:00
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $name Mixed: Name of module as a string or List of name/object pairs as an array
|
|
|
|
|
* @param $object ResourceLoaderModule: Module object (optional when using
|
|
|
|
|
* multiple-registration calling style)
|
|
|
|
|
* @throws MWException: If a duplicate module registration is attempted
|
|
|
|
|
* @throws MWException: If something other than a ResourceLoaderModule is being registered
|
|
|
|
|
* @return Boolean: False if there were any errors, in which case one or more modules were not
|
|
|
|
|
* registered
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
2010-09-29 19:04:04 +00:00
|
|
|
public function register( $name, ResourceLoaderModule $object = null ) {
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
// Allow multiple modules to be registered in one call
|
|
|
|
|
if ( is_array( $name ) && !isset( $object ) ) {
|
|
|
|
|
foreach ( $name as $key => $value ) {
|
2010-09-29 19:04:04 +00:00
|
|
|
$this->register( $key, $value );
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
// Disallow duplicate registrations
|
2010-09-29 19:04:04 +00:00
|
|
|
if ( isset( $this->modules[$name] ) ) {
|
2010-09-04 04:00:09 +00:00
|
|
|
// A module has already been registered by this name
|
2010-10-20 00:22:25 +00:00
|
|
|
throw new MWException(
|
2010-11-03 07:58:03 +00:00
|
|
|
'ResourceLoader duplicate registration error. ' .
|
|
|
|
|
'Another module has already been registered as ' . $name
|
2010-10-20 00:22:25 +00:00
|
|
|
);
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-29 23:57:53 +00:00
|
|
|
// Validate the input (type hinting lets null through)
|
|
|
|
|
if ( !( $object instanceof ResourceLoaderModule ) ) {
|
2010-11-03 07:58:03 +00:00
|
|
|
throw new MWException( 'ResourceLoader invalid module error. ' .
|
|
|
|
|
'Instances of ResourceLoaderModule expected.' );
|
2010-09-29 23:57:53 +00:00
|
|
|
}
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
// Attach module
|
2010-09-29 19:04:04 +00:00
|
|
|
$this->modules[$name] = $object;
|
2010-09-04 04:00:09 +00:00
|
|
|
$object->setName( $name );
|
2010-09-29 19:04:04 +00:00
|
|
|
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
|
|
|
|
* Gets a map of all modules and their options
|
|
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @return Array: List of modules keyed by module name
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
2010-09-29 19:04:04 +00:00
|
|
|
public function getModules() {
|
|
|
|
|
return $this->modules;
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Get the ResourceLoaderModule object for a given module name.
|
2010-09-05 13:31:34 +00:00
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $name String: Module name
|
2010-10-31 14:28:44 +00:00
|
|
|
* @return Mixed: ResourceLoaderModule if module has been registered, null otherwise
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
2010-09-29 19:04:04 +00:00
|
|
|
public function getModule( $name ) {
|
|
|
|
|
return isset( $this->modules[$name] ) ? $this->modules[$name] : null;
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-05 13:31:34 +00:00
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Outputs a response to a resource load-request, including a content-type header.
|
2010-09-04 04:00:09 +00:00
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $context ResourceLoaderContext: Context in which a response should be formed
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
2010-09-29 19:04:04 +00:00
|
|
|
public function respond( ResourceLoaderContext $context ) {
|
2010-10-07 19:35:05 +00:00
|
|
|
global $wgResourceLoaderMaxage, $wgCacheEpoch;
|
2010-09-13 23:19:05 +00:00
|
|
|
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
// Split requested modules into two groups, modules and missing
|
|
|
|
|
$modules = array();
|
|
|
|
|
$missing = array();
|
|
|
|
|
foreach ( $context->getModules() as $name ) {
|
2010-09-29 19:04:04 +00:00
|
|
|
if ( isset( $this->modules[$name] ) ) {
|
|
|
|
|
$modules[$name] = $this->modules[$name];
|
2010-09-04 04:00:09 +00:00
|
|
|
} else {
|
|
|
|
|
$missing[] = $name;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-11-03 07:58:03 +00:00
|
|
|
// If a version wasn't specified we need a shorter expiry time for updates
|
|
|
|
|
// to propagate to clients quickly
|
2010-09-13 23:19:05 +00:00
|
|
|
if ( is_null( $context->getVersion() ) ) {
|
2010-10-19 20:45:02 +00:00
|
|
|
$maxage = $wgResourceLoaderMaxage['unversioned']['client'];
|
2010-09-22 20:44:12 +00:00
|
|
|
$smaxage = $wgResourceLoaderMaxage['unversioned']['server'];
|
2010-09-13 23:19:05 +00:00
|
|
|
}
|
2010-11-03 07:58:03 +00:00
|
|
|
// If a version was specified we can use a longer expiry time since changing
|
|
|
|
|
// version numbers causes cache misses
|
2010-09-13 23:19:05 +00:00
|
|
|
else {
|
2010-10-19 20:45:02 +00:00
|
|
|
$maxage = $wgResourceLoaderMaxage['versioned']['client'];
|
2010-09-22 20:44:12 +00:00
|
|
|
$smaxage = $wgResourceLoaderMaxage['versioned']['server'];
|
2010-09-13 23:19:05 +00:00
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-23 21:23:51 +00:00
|
|
|
// Preload information needed to the mtime calculation below
|
2010-09-29 19:04:04 +00:00
|
|
|
$this->preloadModuleInfo( array_keys( $modules ), $context );
|
2010-09-23 21:23:51 +00:00
|
|
|
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileIn( __METHOD__.'-getModifiedTime' );
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-11-03 07:58:03 +00:00
|
|
|
// To send Last-Modified and support If-Modified-Since, we need to detect
|
|
|
|
|
// the last modified time
|
2010-10-08 10:25:23 +00:00
|
|
|
$mtime = wfTimestamp( TS_UNIX, $wgCacheEpoch );
|
2010-09-24 22:10:25 +00:00
|
|
|
foreach ( $modules as $module ) {
|
|
|
|
|
// Bypass squid cache if the request includes any private modules
|
|
|
|
|
if ( $module->getGroup() === 'private' ) {
|
|
|
|
|
$smaxage = 0;
|
|
|
|
|
}
|
|
|
|
|
// Calculate maximum modified time
|
|
|
|
|
$mtime = max( $mtime, $module->getModifiedTime( $context ) );
|
2010-09-04 08:38:45 +00:00
|
|
|
}
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileOut( __METHOD__.'-getModifiedTime' );
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-11-03 07:58:03 +00:00
|
|
|
if ( $context->getOnly() === 'styles' ) {
|
|
|
|
|
header( 'Content-Type: text/css' );
|
|
|
|
|
} else {
|
|
|
|
|
header( 'Content-Type: text/javascript' );
|
|
|
|
|
}
|
2010-09-04 04:00:09 +00:00
|
|
|
header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $mtime ) );
|
2010-11-01 20:48:30 +00:00
|
|
|
if ( $context->getDebug() ) {
|
|
|
|
|
header( 'Cache-Control: must-revalidate' );
|
|
|
|
|
} else {
|
|
|
|
|
header( "Cache-Control: public, max-age=$maxage, s-maxage=$smaxage" );
|
|
|
|
|
header( 'Expires: ' . wfTimestamp( TS_RFC2822, min( $maxage, $smaxage ) + time() ) );
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-13 23:19:05 +00:00
|
|
|
// If there's an If-Modified-Since header, respond with a 304 appropriately
|
2010-09-04 04:00:09 +00:00
|
|
|
$ims = $context->getRequest()->getHeader( 'If-Modified-Since' );
|
2010-10-02 16:54:53 +00:00
|
|
|
if ( $ims !== false && $mtime <= wfTimestamp( TS_UNIX, $ims ) ) {
|
2010-09-04 04:00:09 +00:00
|
|
|
header( 'HTTP/1.0 304 Not Modified' );
|
|
|
|
|
header( 'Status: 304 Not Modified' );
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2010-09-04 04:00:09 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2010-10-20 00:22:25 +00:00
|
|
|
|
|
|
|
|
// Generate a response
|
2010-10-18 20:16:19 +00:00
|
|
|
$response = $this->makeModuleResponse( $context, $modules, $missing );
|
2010-10-20 00:22:25 +00:00
|
|
|
|
|
|
|
|
// Tack on PHP warnings as a comment in debug mode
|
2010-10-19 17:52:01 +00:00
|
|
|
if ( $context->getDebug() && strlen( $warnings = ob_get_contents() ) ) {
|
|
|
|
|
$response .= "/*\n$warnings\n*/";
|
|
|
|
|
}
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-10-18 20:16:19 +00:00
|
|
|
// Clear any warnings from the buffer
|
|
|
|
|
ob_clean();
|
|
|
|
|
echo $response;
|
2010-09-24 22:10:25 +00:00
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 20:45:02 +00:00
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Generates code for a response
|
|
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $context ResourceLoaderContext: Context in which to generate a response
|
|
|
|
|
* @param $modules Array: List of module objects keyed by module name
|
|
|
|
|
* @param $missing Array: List of unavailable modules (optional)
|
|
|
|
|
* @return String: Response data
|
2010-10-19 20:45:02 +00:00
|
|
|
*/
|
2010-11-03 07:58:03 +00:00
|
|
|
public function makeModuleResponse( ResourceLoaderContext $context,
|
|
|
|
|
array $modules, $missing = array() )
|
|
|
|
|
{
|
2010-09-04 04:00:09 +00:00
|
|
|
// Pre-fetch blobs
|
2010-11-03 07:58:03 +00:00
|
|
|
if ( $context->shouldIncludeMessages() ) {
|
|
|
|
|
$blobs = MessageBlobStore::get( $this, $modules, $context->getLanguage() );
|
|
|
|
|
} else {
|
|
|
|
|
$blobs = array();
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
// Generate output
|
2010-09-24 18:49:19 +00:00
|
|
|
$out = '';
|
2010-09-24 22:10:25 +00:00
|
|
|
foreach ( $modules as $name => $module ) {
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileIn( __METHOD__ . '-' . $name );
|
2010-09-24 18:49:19 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
// Scripts
|
|
|
|
|
$scripts = '';
|
|
|
|
|
if ( $context->shouldIncludeScripts() ) {
|
2010-09-24 22:10:25 +00:00
|
|
|
$scripts .= $module->getScript( $context ) . "\n";
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
// Styles
|
2010-09-10 00:21:36 +00:00
|
|
|
$styles = array();
|
2010-11-03 07:58:03 +00:00
|
|
|
if ( $context->shouldIncludeStyles() ) {
|
|
|
|
|
$styles = $module->getStyles( $context );
|
2010-09-24 18:49:19 +00:00
|
|
|
// Flip CSS on a per-module basis
|
2010-11-03 07:58:03 +00:00
|
|
|
if ( $styles && $this->modules[$name]->getFlip( $context ) ) {
|
2010-09-24 18:49:19 +00:00
|
|
|
foreach ( $styles as $media => $style ) {
|
2010-09-29 19:04:04 +00:00
|
|
|
$styles[$media] = $this->filter( 'flip-css', $style );
|
2010-09-10 00:21:36 +00:00
|
|
|
}
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
// Messages
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
$messagesBlob = isset( $blobs[$name] ) ? $blobs[$name] : array();
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-24 18:49:19 +00:00
|
|
|
// Append output
|
|
|
|
|
switch ( $context->getOnly() ) {
|
|
|
|
|
case 'scripts':
|
|
|
|
|
$out .= $scripts;
|
|
|
|
|
break;
|
|
|
|
|
case 'styles':
|
|
|
|
|
$out .= self::makeCombinedStyles( $styles );
|
|
|
|
|
break;
|
|
|
|
|
case 'messages':
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
$out .= self::makeMessageSetScript( new XmlJsCode( $messagesBlob ) );
|
2010-09-24 18:49:19 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2010-11-03 07:58:03 +00:00
|
|
|
// Minify CSS before embedding in mediaWiki.loader.implement call
|
|
|
|
|
// (unless in debug mode)
|
2010-09-24 18:49:19 +00:00
|
|
|
if ( !$context->getDebug() ) {
|
|
|
|
|
foreach ( $styles as $media => $style ) {
|
2010-09-29 19:04:04 +00:00
|
|
|
$styles[$media] = $this->filter( 'minify-css', $style );
|
2010-09-10 20:18:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
$out .= self::makeLoaderImplementScript( $name, $scripts, $styles,
|
|
|
|
|
new XmlJsCode( $messagesBlob ) );
|
2010-09-24 18:49:19 +00:00
|
|
|
break;
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-17 11:45:49 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-' . $name );
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-24 18:49:19 +00:00
|
|
|
// Update module states
|
2010-09-04 04:00:09 +00:00
|
|
|
if ( $context->shouldIncludeScripts() ) {
|
2010-09-24 18:49:19 +00:00
|
|
|
// Set the state of modules loaded as only scripts to ready
|
2010-11-03 07:58:03 +00:00
|
|
|
if ( count( $modules ) && $context->getOnly() === 'scripts'
|
|
|
|
|
&& !isset( $modules['startup'] ) )
|
|
|
|
|
{
|
|
|
|
|
$out .= self::makeLoaderStateScript(
|
|
|
|
|
array_fill_keys( array_keys( $modules ), 'ready' ) );
|
2010-09-24 18:49:19 +00:00
|
|
|
}
|
|
|
|
|
// Set the state of modules which were requested but unavailable as missing
|
2010-09-24 22:10:25 +00:00
|
|
|
if ( is_array( $missing ) && count( $missing ) ) {
|
2010-09-24 18:49:19 +00:00
|
|
|
$out .= self::makeLoaderStateScript( array_fill_keys( $missing, 'missing' ) );
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-24 18:49:19 +00:00
|
|
|
if ( $context->getDebug() ) {
|
2010-09-24 22:10:25 +00:00
|
|
|
return $out;
|
2010-09-24 18:49:19 +00:00
|
|
|
} else {
|
|
|
|
|
if ( $context->getOnly() === 'styles' ) {
|
2010-09-29 19:04:04 +00:00
|
|
|
return $this->filter( 'minify-css', $out );
|
2010-09-04 04:00:09 +00:00
|
|
|
} else {
|
2010-09-29 19:04:04 +00:00
|
|
|
return $this->filter( 'minify-js', $out );
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-20 00:22:25 +00:00
|
|
|
|
2010-09-29 19:04:04 +00:00
|
|
|
/* Static Methods */
|
2010-10-20 00:22:25 +00:00
|
|
|
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
/**
|
|
|
|
|
* Returns JS code to call to mediaWiki.loader.implement for a module with
|
|
|
|
|
* given properties.
|
|
|
|
|
*
|
|
|
|
|
* @param $name Module name
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $scripts Array: List of JavaScript code snippets to be executed after the
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
* module is loaded
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $styles Array: List of CSS strings keyed by media type
|
|
|
|
|
* @param $messages Mixed: List of messages associated with this module. May either be an
|
|
|
|
|
* associative array mapping message key to value, or a JSON-encoded message blob containing
|
|
|
|
|
* the same data, wrapped in an XmlJsCode object.
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
*/
|
2010-09-24 18:49:19 +00:00
|
|
|
public static function makeLoaderImplementScript( $name, $scripts, $styles, $messages ) {
|
|
|
|
|
if ( is_array( $scripts ) ) {
|
|
|
|
|
$scripts = implode( $scripts, "\n" );
|
|
|
|
|
}
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
return Xml::encodeJsCall(
|
|
|
|
|
'mediaWiki.loader.implement',
|
|
|
|
|
array(
|
|
|
|
|
$name,
|
|
|
|
|
new XmlJsCode( "function() {{$scripts}}" ),
|
|
|
|
|
(object)$styles,
|
|
|
|
|
(object)$messages
|
|
|
|
|
) );
|
2010-09-24 18:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
/**
|
|
|
|
|
* Returns JS code which, when called, will register a given list of messages.
|
|
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $messages Mixed: Either an associative array mapping message key to value, or a
|
|
|
|
|
* JSON-encoded message blob containing the same data, wrapped in an XmlJsCode object.
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
*/
|
2010-09-24 18:49:19 +00:00
|
|
|
public static function makeMessageSetScript( $messages ) {
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
return Xml::encodeJsCall( 'mediaWiki.messages.set', array( (object)$messages ) );
|
2010-09-24 18:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
/**
|
|
|
|
|
* Combines an associative array mapping media type to CSS into a
|
|
|
|
|
* single stylesheet with @media blocks.
|
|
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $styles Array: List of CSS strings keyed by media type
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
*/
|
2010-09-24 18:49:19 +00:00
|
|
|
public static function makeCombinedStyles( array $styles ) {
|
|
|
|
|
$out = '';
|
|
|
|
|
foreach ( $styles as $media => $style ) {
|
|
|
|
|
$out .= "@media $media {\n" . str_replace( "\n", "\n\t", "\t" . $style ) . "\n}\n";
|
|
|
|
|
}
|
|
|
|
|
return $out;
|
|
|
|
|
}
|
|
|
|
|
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
/**
|
|
|
|
|
* Returns a JS call to mediaWiki.loader.state, which sets the state of a
|
|
|
|
|
* module or modules to a given value. Has two calling conventions:
|
|
|
|
|
*
|
|
|
|
|
* - ResourceLoader::makeLoaderStateScript( $name, $state ):
|
|
|
|
|
* Set the state of a single module called $name to $state
|
|
|
|
|
*
|
|
|
|
|
* - ResourceLoader::makeLoaderStateScript( array( $name => $state, ... ) ):
|
|
|
|
|
* Set the state of modules with the given names to the given states
|
|
|
|
|
*/
|
2010-09-24 18:49:19 +00:00
|
|
|
public static function makeLoaderStateScript( $name, $state = null ) {
|
|
|
|
|
if ( is_array( $name ) ) {
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
return Xml::encodeJsCall( 'mediaWiki.loader.state', array( $name ) );
|
2010-09-24 18:49:19 +00:00
|
|
|
} else {
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
return Xml::encodeJsCall( 'mediaWiki.loader.state', array( $name, $state ) );
|
2010-09-24 18:49:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-09-24 22:10:25 +00:00
|
|
|
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
/**
|
|
|
|
|
* Returns JS code which calls the script given by $script. The script will
|
|
|
|
|
* be called with local variables name, version, dependencies and group,
|
|
|
|
|
* which will have values corresponding to $name, $version, $dependencies
|
|
|
|
|
* and $group as supplied.
|
|
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $name String: Module name
|
|
|
|
|
* @param $version Integer: Module version number as a timestamp
|
|
|
|
|
* @param $dependencies Array: List of module names on which this module depends
|
|
|
|
|
* @param $group String: Group which the module is in.
|
|
|
|
|
* @param $script String: JavaScript code
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
*/
|
2010-09-24 21:03:29 +00:00
|
|
|
public static function makeCustomLoaderScript( $name, $version, $dependencies, $group, $script ) {
|
|
|
|
|
$script = str_replace( "\n", "\n\t", trim( $script ) );
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
return Xml::encodeJsCall(
|
|
|
|
|
"( function( name, version, dependencies, group ) {\n\t$script\n} )",
|
|
|
|
|
array( $name, $version, $dependencies, $group ) );
|
2010-09-24 21:03:29 +00:00
|
|
|
}
|
2010-09-24 22:10:25 +00:00
|
|
|
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
/**
|
|
|
|
|
* Returns JS code which calls mediaWiki.loader.register with the given
|
|
|
|
|
* parameters. Has three calling conventions:
|
|
|
|
|
*
|
|
|
|
|
* - ResourceLoader::makeLoaderRegisterScript( $name, $version, $dependencies, $group ):
|
|
|
|
|
* Register a single module.
|
|
|
|
|
*
|
|
|
|
|
* - ResourceLoader::makeLoaderRegisterScript( array( $name1, $name2 ) ):
|
|
|
|
|
* Register modules with the given names.
|
|
|
|
|
*
|
|
|
|
|
* - ResourceLoader::makeLoaderRegisterScript( array(
|
|
|
|
|
* array( $name1, $version1, $dependencies1, $group1 ),
|
|
|
|
|
* array( $name2, $version2, $dependencies1, $group2 ),
|
|
|
|
|
* ...
|
|
|
|
|
* ) ):
|
|
|
|
|
* Registers modules with the given names and parameters.
|
|
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $name String: Module name
|
|
|
|
|
* @param $version Integer: Module version number as a timestamp
|
|
|
|
|
* @param $dependencies Array: List of module names on which this module depends
|
|
|
|
|
* @param $group String: group which the module is in.
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
*/
|
2010-11-03 07:58:03 +00:00
|
|
|
public static function makeLoaderRegisterScript( $name, $version = null,
|
|
|
|
|
$dependencies = null, $group = null )
|
|
|
|
|
{
|
2010-09-24 21:03:29 +00:00
|
|
|
if ( is_array( $name ) ) {
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
return Xml::encodeJsCall( 'mediaWiki.loader.register', array( $name ) );
|
2010-09-24 21:03:29 +00:00
|
|
|
} else {
|
|
|
|
|
$version = (int) $version > 1 ? (int) $version : 1;
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
return Xml::encodeJsCall( 'mediaWiki.loader.register',
|
|
|
|
|
array( $name, $version, $dependencies, $group ) );
|
2010-09-24 21:03:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-09-24 22:10:25 +00:00
|
|
|
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
/**
|
|
|
|
|
* Returns JS code which runs given JS code if the client-side framework is
|
|
|
|
|
* present.
|
|
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $script String: JavaScript code
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
*/
|
2010-09-24 22:10:25 +00:00
|
|
|
public static function makeLoaderConditionalScript( $script ) {
|
|
|
|
|
$script = str_replace( "\n", "\n\t", trim( $script ) );
|
|
|
|
|
return "if ( window.mediaWiki ) {\n\t$script\n}\n";
|
|
|
|
|
}
|
|
|
|
|
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
/**
|
|
|
|
|
* Returns JS code which will set the MediaWiki configuration array to
|
|
|
|
|
* the given value.
|
|
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $configuration Array: List of configuration values keyed by variable name
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
*/
|
2010-09-24 22:10:25 +00:00
|
|
|
public static function makeConfigSetScript( array $configuration ) {
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
return Xml::encodeJsCall( 'mediaWiki.config.set', array( $configuration ) );
|
2010-09-24 22:10:25 +00:00
|
|
|
}
|
2010-11-05 20:36:13 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether debug mode was requested
|
|
|
|
|
* Order of priority is 1) request param, 2) cookie, 3) $wg setting
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function inDebugMode() {
|
|
|
|
|
global $wgRequest, $wgResourceLoaderDebug;
|
|
|
|
|
static $retval = null;
|
|
|
|
|
if ( !is_null( $retval ) )
|
|
|
|
|
return $retval;
|
|
|
|
|
return $retval = $wgRequest->getFuzzyBool( 'debug',
|
|
|
|
|
$wgRequest->getCookie( 'resourceLoaderDebug', '', $wgResourceLoaderDebug ) );
|
|
|
|
|
}
|
2010-09-17 11:45:49 +00:00
|
|
|
}
|