26use Psr\Log\LoggerAwareInterface;
27use Psr\Log\LoggerInterface;
28use Psr\Log\NullLogger;
30use Wikimedia\WrappedString;
40 const CACHE_VERSION = 8;
99 const FILTER_NOMIN =
'/*@nomin*/';
116 if ( !$moduleNames ) {
125 $vary =
"$skin|$lang";
126 $res =
$dbr->select(
'module_deps', [
'md_module',
'md_deps' ], [
127 'md_module' => $moduleNames,
133 $modulesWithDeps = [];
134 foreach (
$res as $row ) {
135 $module = $this->
getModule( $row->md_module );
138 json_decode( $row->md_deps,
true )
140 $modulesWithDeps[] = $row->md_module;
144 foreach ( array_diff( $moduleNames, $modulesWithDeps ) as $name ) {
152 ResourceLoaderWikiModule::preloadTitleInfo(
$context,
$dbr, $moduleNames );
156 foreach ( $moduleNames as $name ) {
158 if ( $module && $module->getMessages() ) {
164 foreach ( $blobs as $name =>
$blob ) {
187 if ( strpos( $data, self::FILTER_NOMIN ) !==
false ) {
195 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
198 $key =
$cache->makeGlobalKey(
206 $result =
$cache->get( $key );
207 if ( $result ===
false ) {
208 $stats->increment(
"resourceloader_cache.$filter.miss" );
210 $cache->set( $key, $result, 24 * 3600 );
212 $stats->increment(
"resourceloader_cache.$filter.hit" );
214 if ( $result ===
null ) {
223 $data = trim( $data );
226 $data = ( $filter ===
'minify-css' )
227 ? CSSMin::minify( $data )
229 }
catch ( Exception
$e ) {
230 MWExceptionHandler::logException(
$e );
245 $this->logger =
$logger ?:
new NullLogger();
248 $this->logger->debug( __METHOD__ .
' was called without providing a Config instance' );
249 $config = MediaWikiServices::getInstance()->getMainConfig();
260 $this->
register( include
"$IP/resources/Resources.php" );
262 $this->
register(
$config->get(
'ResourceModules' ) );
266 Hooks::run(
'ResourceLoaderRegisterModules', [ &$rl ] );
268 if (
$config->get(
'EnableJavaScriptTest' ) ===
true ) {
327 public function register(
$name, $info = null ) {
328 $moduleSkinStyles = $this->config->
get(
'ResourceModuleSkinStyles' );
331 $registrations = is_array( $name ) ?
$name : [ $name => $info ];
332 foreach ( $registrations as $name => $info ) {
334 if ( isset( $this->moduleInfos[$name] ) ) {
336 $this->logger->warning(
337 'ResourceLoader duplicate registration warning. ' .
338 'Another module has already been registered as ' . $name
343 if ( !self::isValidModuleName( $name ) ) {
344 throw new MWException(
"ResourceLoader module name '$name' is invalid, "
345 .
"see ResourceLoader::isValidModuleName()" );
350 $this->moduleInfos[
$name] = [
'object' => $info ];
351 $info->setName( $name );
352 $this->modules[
$name] = $info;
353 } elseif ( is_array( $info ) ) {
355 $this->moduleInfos[
$name] = $info;
358 'ResourceLoader module info type error for module \'' . $name .
363 // Last-minute changes
365 // Apply custom skin-defined styles to existing modules.
366 if ( $this->isFileModule( $name ) ) {
367 foreach ( $moduleSkinStyles as $skinName => $skinStyles ) {
368 // If this module already defines skinStyles for this skin, ignore $wgResourceModuleSkinStyles.
369 if ( isset( $this->moduleInfos[$name]['skinStyles
'][$skinName] ) ) {
373 // If $name is preceded with a '+
', the defined style files will be added to 'default'
374 // skinStyles, otherwise 'default' will be ignored as it normally would be.
375 if ( isset( $skinStyles[$name] ) ) {
376 $paths = (array)$skinStyles[$name];
378 } elseif ( isset( $skinStyles['+
' . $name] ) ) {
379 $paths = (array)$skinStyles['+
' . $name];
380 $styleFiles = isset( $this->moduleInfos[$name]['skinStyles
']['default'] ) ?
381 (array)$this->moduleInfos[$name]['skinStyles
']['default'] :
387 // Add new file paths, remapping them to refer to our directories and not use settings
388 // from the module we're modifying, which come from the base
definition.
389 list( $localBasePath, $remoteBasePath ) =
390 ResourceLoaderFileModule::extractBasePaths( $skinStyles );
392 foreach ( $paths as $path ) {
396 $this->moduleInfos[
$name][
'skinStyles'][$skinName] = $styleFiles;
405 if ( $this->config->get(
'EnableJavaScriptTest' ) !==
true ) {
406 throw new MWException(
'Attempt to register JavaScript test modules '
407 .
'but <code>$wgEnableJavaScriptTest</code> is false. '
408 .
'Edit your <code>LocalSettings.php</code> to enable it.' );
413 $testModules[
'qunit'] = [];
417 Hooks::run(
'ResourceLoaderTestModules', [ &$testModules, &$rl ] );
421 foreach ( $testModules[
'qunit'] as &$module ) {
425 $module[
'position'] =
'top';
426 $module[
'dependencies'][] =
'test.mediawiki.qunit.testrunner';
429 $testModules[
'qunit'] =
430 ( include
"$IP/tests/qunit/QUnitTestResources.php" ) + $testModules[
'qunit'];
432 foreach ( $testModules as $id => $names ) {
434 $this->
register( $testModules[$id] );
437 $this->testModuleNames[$id] = array_keys( $testModules[$id] );
453 if ( is_array( $id ) ) {
454 foreach ( $id as $key =>
$value ) {
455 $this->addSource( $key,
$value );
461 if ( isset( $this->sources[$id] ) ) {
463 'ResourceLoader duplicate source addition error. ' .
464 'Another source has already been registered as ' . $id
469 if ( is_array( $loadUrl ) ) {
470 if ( !isset( $loadUrl[
'loadScript'] ) ) {
472 __METHOD__ .
' was passed an array with no "loadScript" key.'
476 $loadUrl = $loadUrl[
'loadScript'];
479 $this->sources[$id] = $loadUrl;
488 return array_keys( $this->moduleInfos );
503 if ( $framework ==
'all' ) {
504 return $this->testModuleNames;
505 } elseif ( isset( $this->testModuleNames[$framework] )
506 && is_array( $this->testModuleNames[$framework] )
508 return $this->testModuleNames[$framework];
522 return isset( $this->moduleInfos[$name] );
537 if ( !isset( $this->modules[$name] ) ) {
538 if ( !isset( $this->moduleInfos[$name] ) ) {
543 $info = $this->moduleInfos[
$name];
545 if ( isset( $info[
'object'] ) ) {
547 $object = $info[
'object'];
548 } elseif ( isset( $info[
'factory'] ) ) {
549 $object = call_user_func( $info[
'factory'], $info );
550 $object->setConfig( $this->getConfig() );
551 $object->setLogger( $this->logger );
553 if ( !isset( $info[
'class'] ) ) {
554 $class = ResourceLoaderFileModule::class;
556 $class = $info[
'class'];
559 $object =
new $class( $info );
560 $object->setConfig( $this->getConfig() );
561 $object->setLogger( $this->logger );
563 $object->setName( $name );
564 $this->modules[
$name] = $object;
567 return $this->modules[
$name];
577 if ( !isset( $this->moduleInfos[$name] ) ) {
580 $info = $this->moduleInfos[
$name];
581 if ( isset( $info[
'object'] ) ) {
586 !isset( $info[
'class'] ) ||
588 $info[
'class'] === ResourceLoaderFileModule::class ||
589 is_subclass_of( $info[
'class'], ResourceLoaderFileModule::class )
599 return $this->sources;
612 if ( !isset( $this->sources[
$source] ) ) {
613 throw new MWException(
"The $source source was never registered in ResourceLoader." );
615 return $this->sources[
$source];
624 $hash = hash(
'fnv132',
$value );
625 return Wikimedia\base_convert( $hash, 16, 36, 7 );
638 MWExceptionHandler::logException(
$e );
639 $this->logger->warning(
643 $this->errors[] = self::formatExceptionNoComment(
$e );
655 if ( !$moduleNames ) {
660 return $this->getModule( $module )->getVersionHash(
$context );
661 }
catch ( Exception
$e ) {
664 $this->outputErrorAndLog(
$e,
665 'Calculating version for "{module}" failed: {exception}',
673 return self::makeHash( implode(
'',
$hashes ) );
696 foreach (
$context->getModules() as $name ) {
697 if ( !$this->getModule( $name ) ) {
702 $moduleNames[] =
$name;
704 return $this->getCombinedVersion(
$context, $moduleNames );
722 $this->measureResponseTime( RequestContext::getMain()->getTiming() );
727 foreach (
$context->getModules() as $name ) {
728 $module = $this->getModule( $name );
732 if ( $module->getGroup() ===
'private' ) {
733 $this->logger->debug(
"Request for private module '$name' denied" );
734 $this->errors[] =
"Cannot show private module \"$name\"";
746 }
catch ( Exception
$e ) {
747 $this->outputErrorAndLog(
$e,
'Preloading module info failed: {exception}' );
753 $versionHash = $this->getCombinedVersion(
$context, array_keys(
$modules ) );
754 }
catch ( Exception
$e ) {
755 $this->outputErrorAndLog(
$e,
'Calculating version hash failed: {exception}' );
760 $etag =
'W/"' . $versionHash .
'"';
763 if ( $this->tryRespondNotModified(
$context, $etag ) ) {
768 if ( $this->config->get(
'UseFileCache' ) ) {
770 if ( $this->tryRespondFromFileCache( $fileCache,
$context, $etag ) ) {
781 $warnings = ob_get_contents();
782 if ( strlen( $warnings ) ) {
783 $this->errors[] = $warnings;
788 if ( isset( $fileCache ) && !$this->errors && !count( $missing ) ) {
791 if ( $fileCache->isCacheWorthy() ) {
794 $fileCache->incrMissesRecent(
$context->getRequest() );
799 $this->sendResponseHeaders(
$context, $etag, (
bool)$this->errors, $this->extraHeaders );
804 if (
$context->getImageObj() && $this->errors ) {
806 $response = implode(
"\n\n", $this->errors );
807 } elseif ( $this->errors ) {
808 $errorText = implode(
"\n\n", $this->errors );
809 $errorResponse = self::makeComment( $errorText );
810 if (
$context->shouldIncludeScripts() ) {
811 $errorResponse .=
'if (window.console && console.error) {'
812 . Xml::encodeJsCall(
'console.error', [ $errorText ] )
825 DeferredUpdates::addCallableUpdate(
function () use ( $timing ) {
826 $measure = $timing->
measure(
'responseTime',
'requestStart',
'requestShutdown' );
827 if ( $measure !==
false ) {
828 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
829 $stats->timing(
'resourceloader.responseTime', $measure[
'duration'] * 1000 );
848 \MediaWiki\HeaderCallback::warnIfHeadersSent();
849 $rlMaxage = $this->config->get(
'ResourceLoaderMaxage' );
854 if ( is_null(
$context->getVersion() )
858 $maxage = $rlMaxage[
'unversioned'][
'client'];
859 $smaxage = $rlMaxage[
'unversioned'][
'server'];
863 $maxage = $rlMaxage[
'versioned'][
'client'];
864 $smaxage = $rlMaxage[
'versioned'][
'server'];
869 header(
'Content-Type: text/plain; charset=utf-8' );
873 } elseif (
$context->getOnly() ===
'styles' ) {
874 header(
'Content-Type: text/css; charset=utf-8' );
875 header(
'Access-Control-Allow-Origin: *' );
877 header(
'Content-Type: text/javascript; charset=utf-8' );
881 header(
'ETag: ' . $etag );
884 header(
'Cache-Control: private, no-cache, must-revalidate' );
885 header(
'Pragma: no-cache' );
887 header(
"Cache-Control: public, max-age=$maxage, s-maxage=$smaxage" );
888 $exp = min( $maxage, $smaxage );
889 header(
'Expires: ' .
wfTimestamp( TS_RFC2822, $exp + time() ) );
891 foreach ( $extra as
$header ) {
909 $clientKeys =
$context->getRequest()->getHeader(
'If-None-Match', WebRequest::GETHEADER_LIST );
911 if ( $clientKeys !==
false && !
$context->getDebug() && in_array( $etag, $clientKeys ) ) {
925 $this->sendResponseHeaders(
$context, $etag,
false );
944 $rlMaxage = $this->config->get(
'ResourceLoaderMaxage' );
948 $maxage = is_null(
$context->getVersion() )
949 ? $rlMaxage[
'unversioned'][
'server']
950 : $rlMaxage[
'versioned'][
'server'];
963 $this->sendResponseHeaders(
$context, $etag,
false );
968 $warnings = ob_get_contents();
969 if ( strlen( $warnings ) ) {
993 $encText = str_replace(
'*/',
'* /', $text );
994 return "/*\n$encText\n*/\n";
1004 return self::makeComment( self::formatExceptionNoComment(
$e ) );
1018 return MWExceptionHandler::getPublicLogMessage(
$e );
1021 return MWExceptionHandler::getLogMessage(
$e ) .
1023 MWExceptionHandler::getRedactedTraceAsString(
$e );
1043 if ( !count(
$modules ) && !count( $missing ) ) {
1054 if ( $data ===
false ) {
1056 $this->errors[] =
'Image generation failed';
1061 foreach ( $missing as $name ) {
1062 $states[
$name] =
'missing';
1068 $filter =
$context->getOnly() ===
'styles' ?
'minify-css' :
'minify-js';
1070 foreach (
$modules as $name => $module ) {
1073 $implementKey = $name .
'@' . $module->getVersionHash(
$context );
1076 if ( isset(
$content[
'headers'] ) ) {
1077 $this->extraHeaders = array_merge( $this->extraHeaders,
$content[
'headers'] );
1084 if ( is_string( $scripts ) ) {
1086 $strContent = $scripts;
1087 } elseif ( is_array( $scripts ) ) {
1089 $strContent = self::makeLoaderImplementScript( $implementKey, $scripts, [], [], [] );
1097 $strContent = isset( $styles[
'css'] ) ? implode(
'', $styles[
'css'] ) :
'';
1100 $scripts =
$content[
'scripts'] ??
'';
1101 if ( is_string( $scripts ) ) {
1102 if ( $name ===
'site' || $name ===
'user' ) {
1107 if ( !self::inDebugMode() ) {
1108 $scripts = self::filter(
'minify-js', $scripts );
1114 $strContent = self::makeLoaderImplementScript(
1125 $strContent = self::filter( $filter, $strContent );
1128 if (
$context->getOnly() ===
'scripts' ) {
1130 $out .= $this->ensureNewline( $strContent );
1132 $out .= $strContent;
1135 }
catch ( Exception
$e ) {
1136 $this->outputErrorAndLog(
$e,
'Generating module package failed: {exception}' );
1139 $states[
$name] =
'error';
1142 $isRaw |= $module->isRaw();
1146 if (
$context->shouldIncludeScripts() && !
$context->getRaw() && !$isRaw ) {
1150 foreach (
$modules as $name => $module ) {
1151 $states[
$name] =
'ready';
1156 if ( count( $states ) ) {
1157 $stateScript = self::makeLoaderStateScript( $states );
1159 $stateScript = self::filter(
'minify-js', $stateScript );
1162 $out = $this->ensureNewline(
$out ) . $stateScript;
1166 $this->errors[] =
'Problematic modules: '
1167 . self::encodeJsonForScript( $states );
1179 private function ensureNewline( $str ) {
1180 $end = substr( $str, -1 );
1181 if ( $end ===
false || $end ===
"\n" ) {
1193 public function getModulesByMessage( $messageKey ) {
1195 foreach ( $this->getModuleNames() as $moduleName ) {
1196 $module = $this->getModule( $moduleName );
1197 if ( in_array( $messageKey, $module->getMessages() ) ) {
1198 $moduleNames[] = $moduleName;
1201 return $moduleNames;
1220 protected static function makeLoaderImplementScript(
1221 $name, $scripts, $styles,
$messages, $templates
1224 if ( self::inDebugMode() ) {
1225 $scripts =
new XmlJsCode(
"function ( $, jQuery, require, module ) {\n{$scripts->value}\n}" );
1227 $scripts =
new XmlJsCode(
'function($,jQuery,require,module){' . $scripts->value .
'}' );
1229 } elseif ( !is_string( $scripts ) && !is_array( $scripts ) ) {
1230 throw new MWException(
'Invalid scripts error. Array of URLs or string of code expected.' );
1242 self::trimArray( $module );
1244 return Xml::encodeJsCall(
'mw.loader.implement', $module, self::inDebugMode() );
1254 public static function makeMessageSetScript(
$messages ) {
1269 public static function makeCombinedStyles(
array $stylePairs ) {
1271 foreach ( $stylePairs as $media => $styles ) {
1275 $styles = (
array)$styles;
1276 foreach ( $styles as $style ) {
1277 $style = trim( $style );
1279 if ( $style !==
'' ) {
1284 if ( $media ===
'' || $media ==
'all' ) {
1286 } elseif ( is_string( $media ) ) {
1287 $out[] =
"@media $media {\n" . str_replace(
"\n",
"\n\t",
"\t" . $style ) .
"}";
1305 public static function encodeJsonForScript( $data ) {
1315 $jsonFlags = JSON_UNESCAPED_SLASHES |
1316 JSON_UNESCAPED_UNICODE |
1319 if ( self::inDebugMode() ) {
1320 $jsonFlags |= JSON_PRETTY_PRINT;
1322 return json_encode( $data, $jsonFlags );
1339 public static function makeLoaderStateScript( $states, $state =
null ) {
1340 if ( !is_array( $states ) ) {
1341 $states = [ $states => $state ];
1350 private static function isEmptyObject( stdClass $obj ) {
1351 foreach ( $obj as $key =>
$value ) {
1369 private static function trimArray(
array &$array ) {
1370 $i = count( $array );
1372 if ( $array[$i] ===
null
1373 || $array[$i] === []
1374 || ( $array[$i] instanceof
XmlJsCode && $array[$i]->value ===
'{}' )
1375 || ( $array[$i] instanceof stdClass && self::isEmptyObject( $array[$i] ) )
1377 unset( $array[$i] );
1409 public static function makeLoaderRegisterScript(
array $modules ) {
1414 foreach (
$modules as $i => &$module ) {
1416 $index[$module[0]] = $i;
1419 if ( isset( $module[2] ) ) {
1420 foreach ( $module[2] as &$dependency ) {
1421 if ( isset( $index[$dependency] ) ) {
1423 $dependency = $index[$dependency];
1429 array_walk(
$modules, [
'self',
'trimArray' ] );
1432 'mw.loader.register',
1452 public static function makeLoaderSourcesScript( $sources, $loadUrl =
null ) {
1453 if ( !is_array( $sources ) ) {
1454 $sources = [ $sources => $loadUrl ];
1457 'mw.loader.addSource',
1469 public static function makeLoaderConditionalScript( $script ) {
1471 return '(window.RLQ=window.RLQ||[]).push(function(){' .
1472 trim( $script ) .
'});';
1483 public static function makeInlineCodeWithModule(
$modules, $script ) {
1485 return '(window.RLQ=window.RLQ||[]).push(['
1486 . self::encodeJsonForScript(
$modules ) .
','
1487 .
'function(){' . trim( $script ) .
'}'
1502 public static function makeInlineScript( $script, $nonce =
null ) {
1503 $js = self::makeLoaderConditionalScript( $script );
1505 if ( $nonce ===
null ) {
1506 wfWarn( __METHOD__ .
" did not get nonce. Will break CSP" );
1507 } elseif ( $nonce !==
false ) {
1511 $escNonce =
' nonce="' . htmlspecialchars( $nonce ) .
'"';
1514 return new WrappedString(
1515 Html::inlineScript( $js, $nonce ),
1516 "<script$escNonce>(window.RLQ=window.RLQ||[]).push(function(){",
1529 public static function makeConfigSetScript(
array $configuration ) {
1535 if ( $js ===
false ) {
1536 throw new Exception(
1537 'JSON serialization of config data failed. ' .
1538 'This usually means the config data is not valid UTF-8.'
1557 public static function makePackedModulesString(
$modules ) {
1560 $pos = strrpos( $module,
'.' );
1561 $prefix = $pos ===
false ?
'' : substr( $module, 0, $pos );
1562 $suffix = $pos ===
false ? $module : substr( $module, $pos + 1 );
1563 $moduleMap[$prefix][] = $suffix;
1567 foreach ( $moduleMap as $prefix => $suffixes ) {
1568 $p = $prefix ===
'' ?
'' : $prefix .
'.';
1569 $arr[] = $p . implode(
',', $suffixes );
1571 return implode(
'|', $arr );
1579 public static function inDebugMode() {
1580 if ( self::$debugMode ===
null ) {
1582 self::$debugMode =
$wgRequest->getFuzzyBool(
'debug',
1586 return self::$debugMode;
1599 public static function clearCache() {
1600 self::$debugMode =
null;
1616 $script = $this->getLoadScript(
$source );
1631 return self::makeLoaderQuery(
1639 $context->getRequest()->getBool(
'printable' ),
1640 $context->getRequest()->getBool(
'handheld' ),
1662 public static function makeLoaderQuery(
$modules,
$lang, $skin, $user =
null,
1663 $version =
null,
$debug =
false, $only =
null, $printable =
false,
1664 $handheld =
false, $extraQuery = []
1667 'modules' => self::makePackedModulesString(
$modules ),
1670 'debug' =>
$debug ?
'true' :
'false',
1672 if ( $user !==
null ) {
1675 if ( $version !==
null ) {
1676 $query[
'version'] = $version;
1678 if ( $only !==
null ) {
1703 public static function isValidModuleName( $moduleName ) {
1704 return strcspn( $moduleName,
'!,|', 0, 255 ) === strlen( $moduleName );
1717 public function getLessCompiler(
$vars = [] ) {
1722 if ( !class_exists(
'Less_Parser' ) ) {
1723 throw new MWException(
'MediaWiki requires the less.php parser' );
1729 "$IP/resources/src/mediawiki.less/" =>
'',
1731 $parser->SetOption(
'relativeUrls',
false );
1743 public function getLessVars() {
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this definition
$wgResourceLoaderDebug
The default debug mode (on/off) for of ResourceLoader requests.
$wgShowExceptionDetails
If set to true, uncaught exceptions will print the exception message and a complete stack trace to ou...
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfResetOutputBuffers( $resetGzipEncoding=true)
Clear away any user-level output buffers, discarding contents.
if(! $wgDBerrorLogTZ) $wgRequest
isCacheGood( $timestamp='')
Check if up to date cache file exists.
fetchText()
Get the uncompressed text from the cache.
cacheTimestamp()
Get the last-modified timestamp of the cache file.
static header( $code)
Output an HTTP status code header.
static minify( $s)
Returns minified JavaScript code.
This class generates message blobs for use by ResourceLoader modules.
get(ResourceLoader $resourceLoader, $modules, $lang)
static transformCssMedia( $media)
Transform "media" attribute based on request parameters.
ResourceLoader request result caching in the file system.
static useFileCache(ResourceLoaderContext $context)
Check if an RL request can be cached.
static newFromContext(ResourceLoaderContext $context)
Construct an ResourceFileCache from a context.
Object passed around to modules which contains information about the state of a specific loader reque...
An object to represent a path to a JavaScript/CSS file, along with a remote and local base path,...
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
static expandRelativePaths(array $filePaths)
Expand directories relative to $IP.
Dynamic JavaScript and CSS resource loading system.
__construct(Config $config=null, LoggerInterface $logger=null)
Register core modules and runs registration hooks.
static formatExceptionNoComment( $e)
Handle exception display.
tryRespondFromFileCache(ResourceFileCache $fileCache, ResourceLoaderContext $context, $etag)
Send out code for a response from file cache if possible.
isFileModule( $name)
Whether the module is a ResourceLoaderFileModule (including subclasses).
getModuleNames()
Get a list of module names.
setMessageBlobStore(MessageBlobStore $blobStore)
makeModuleResponse(ResourceLoaderContext $context, array $modules, array $missing=[])
Generate code for a response.
setLogger(LoggerInterface $logger)
getTestModuleNames( $framework='all')
Get a list of test module names for one (or all) frameworks.
getLoadScript( $source)
Get the URL to the load.php endpoint for the given ResourceLoader source.
sendResponseHeaders(ResourceLoaderContext $context, $etag, $errors, array $extra=[])
Send main response headers to the client.
array $extraHeaders
List of extra HTTP response headers provided by loaded modules.
tryRespondNotModified(ResourceLoaderContext $context, $etag)
Respond with HTTP 304 Not Modified if appropiate.
getSources()
Get the list of sources.
addSource( $id, $loadUrl=null)
Add a foreign source of modules.
array $moduleInfos
Associative array mapping module name to info associative array.
outputErrorAndLog(Exception $e, $msg, array $context=[])
Add an error to the 'errors' array and log it.
array $testModuleNames
Associative array mapping framework ids to a list of names of test suite modules like [ 'qunit' => [ ...
makeVersionQuery(ResourceLoaderContext $context)
Get the expected value of the 'version' query parameter.
getModule( $name)
Get the ResourceLoaderModule object for a given module name.
array $modules
Module name/ResourceLoaderModule object pairs.
isModuleRegistered( $name)
Check whether a ResourceLoader module is registered.
static applyFilter( $filter, $data)
measureResponseTime(Timing $timing)
static formatException( $e)
Handle exception display.
MessageBlobStore $blobStore
array $errors
Errors accumulated during current respond() call.
static makeComment( $text)
Generate a CSS or JS comment block.
getCombinedVersion(ResourceLoaderContext $context, array $moduleNames)
Helper method to get and combine versions of multiple modules.
respond(ResourceLoaderContext $context)
Output a response to a load request, including the content-type header.
static filter( $filter, $data, array $options=[])
Run JavaScript or CSS data through a filter, caching the filtered result for future calls.
preloadModuleInfo(array $moduleNames, ResourceLoaderContext $context)
Load information stored in the database about modules.
An interface to help developers measure the performance of their applications.
measure( $measureName, $startMark='requestStart', $endMark=null)
This method stores the duration between two marks along with the associated name (a "measure").
A wrapper class which causes Xml::encodeJsVar() and Xml::encodeJsCall() to interpret a given string a...
static encodeJsCall( $name, $args, $pretty=false)
Create a call to a JavaScript function.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
namespace being checked & $result
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check $image
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Allows to change the fields on the form that will be generated $name
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
this hook is for auditing only $response
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
returning false will NOT prevent logging $e
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Interface for configuration instances.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(!isset( $args[0])) $lang