26use Psr\Log\LoggerAwareInterface;
27use Psr\Log\LoggerInterface;
28use Psr\Log\NullLogger;
29use WrappedString\WrappedString;
102 const FILTER_NOMIN =
'/*@nomin*/';
119 if ( !$moduleNames ) {
128 $vary =
"$skin|$lang";
129 $res =
$dbr->select(
'module_deps', [
'md_module',
'md_deps' ], [
130 'md_module' => $moduleNames,
136 $modulesWithDeps = [];
137 foreach (
$res as $row ) {
138 $module = $this->
getModule( $row->md_module );
141 FormatJson::decode( $row->md_deps,
true )
143 $modulesWithDeps[] = $row->md_module;
147 foreach ( array_diff( $moduleNames, $modulesWithDeps ) as $name ) {
159 foreach ( $moduleNames as $name ) {
161 if ( $module && $module->getMessages() ) {
167 foreach ( $blobs as $name =>
$blob ) {
190 if ( strpos( $data, self::FILTER_NOMIN ) !==
false ) {
198 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
201 $key =
$cache->makeGlobalKey(
205 self::$filterCacheVersion, md5( $data )
208 $result =
$cache->get( $key );
209 if ( $result ===
false ) {
210 $stats->increment(
"resourceloader_cache.$filter.miss" );
212 $cache->set( $key, $result, 24 * 3600 );
214 $stats->increment(
"resourceloader_cache.$filter.hit" );
216 if ( $result ===
null ) {
225 $data = trim( $data );
228 $data = ( $filter ===
'minify-css' )
229 ? CSSMin::minify( $data )
231 }
catch ( Exception
$e ) {
232 MWExceptionHandler::logException(
$e );
249 $this->logger =
$logger ?:
new NullLogger();
252 $this->logger->debug( __METHOD__ .
' was called without providing a Config instance' );
253 $config = MediaWikiServices::getInstance()->getMainConfig();
264 $this->
register( include
"$IP/resources/Resources.php" );
266 $this->
register(
$config->get(
'ResourceModules' ) );
270 Hooks::run(
'ResourceLoaderRegisterModules', [ &$rl ] );
272 if (
$config->get(
'EnableJavaScriptTest' ) ===
true ) {
331 public function register(
$name, $info = null ) {
332 $moduleSkinStyles = $this->config->
get(
'ResourceModuleSkinStyles' );
335 $registrations = is_array( $name ) ?
$name : [ $name => $info ];
336 foreach ( $registrations as $name => $info ) {
338 if ( isset( $this->moduleInfos[$name] ) ) {
340 $this->logger->warning(
341 'ResourceLoader duplicate registration warning. ' .
342 'Another module has already been registered as ' . $name
347 if ( !self::isValidModuleName( $name ) ) {
348 throw new MWException(
"ResourceLoader module name '$name' is invalid, "
349 .
"see ResourceLoader::isValidModuleName()" );
354 $this->moduleInfos[
$name] = [
'object' => $info ];
355 $info->setName( $name );
356 $this->modules[
$name] = $info;
357 } elseif ( is_array( $info ) ) {
359 $this->moduleInfos[
$name] = $info;
362 'ResourceLoader module info type error for module \'' . $name .
367 // Last-minute changes
369 // Apply custom skin-defined styles to existing modules.
370 if ( $this->isFileModule( $name ) ) {
371 foreach ( $moduleSkinStyles as $skinName => $skinStyles ) {
372 // If this module already defines skinStyles for this skin, ignore $wgResourceModuleSkinStyles.
373 if ( isset( $this->moduleInfos[$name]['skinStyles
'][$skinName] ) ) {
377 // If $name is preceded with a '+
', the defined style files will be added to 'default'
378 // skinStyles, otherwise 'default' will be ignored as it normally would be.
379 if ( isset( $skinStyles[$name] ) ) {
380 $paths = (array)$skinStyles[$name];
382 } elseif ( isset( $skinStyles['+
' . $name] ) ) {
383 $paths = (array)$skinStyles['+
' . $name];
384 $styleFiles = isset( $this->moduleInfos[$name]['skinStyles
']['default'] ) ?
385 (array)$this->moduleInfos[$name]['skinStyles
']['default'] :
391 // Add new file paths, remapping them to refer to our directories and not use settings
392 // from the module we're modifying, which come from the base
definition.
393 list( $localBasePath, $remoteBasePath ) =
394 ResourceLoaderFileModule::extractBasePaths( $skinStyles );
396 foreach ( $paths as $path ) {
400 $this->moduleInfos[
$name][
'skinStyles'][$skinName] = $styleFiles;
409 if ( $this->config->get(
'EnableJavaScriptTest' ) !==
true ) {
410 throw new MWException(
'Attempt to register JavaScript test modules '
411 .
'but <code>$wgEnableJavaScriptTest</code> is false. '
412 .
'Edit your <code>LocalSettings.php</code> to enable it.' );
417 $testModules[
'qunit'] = [];
421 Hooks::run(
'ResourceLoaderTestModules', [ &$testModules, &$rl ] );
425 foreach ( $testModules[
'qunit'] as &$module ) {
429 $module[
'position'] =
'top';
430 $module[
'dependencies'][] =
'test.mediawiki.qunit.testrunner';
433 $testModules[
'qunit'] =
434 ( include
"$IP/tests/qunit/QUnitTestResources.php" ) + $testModules[
'qunit'];
436 foreach ( $testModules as $id => $names ) {
438 $this->
register( $testModules[$id] );
441 $this->testModuleNames[$id] = array_keys( $testModules[$id] );
457 if ( is_array( $id ) ) {
458 foreach ( $id as $key =>
$value ) {
459 $this->addSource( $key,
$value );
465 if ( isset( $this->sources[$id] ) ) {
467 'ResourceLoader duplicate source addition error. ' .
468 'Another source has already been registered as ' . $id
473 if ( is_array( $loadUrl ) ) {
474 if ( !isset( $loadUrl[
'loadScript'] ) ) {
476 __METHOD__ .
' was passed an array with no "loadScript" key.'
480 $loadUrl = $loadUrl[
'loadScript'];
483 $this->sources[$id] = $loadUrl;
492 return array_keys( $this->moduleInfos );
507 if ( $framework ==
'all' ) {
508 return $this->testModuleNames;
509 } elseif ( isset( $this->testModuleNames[$framework] )
510 && is_array( $this->testModuleNames[$framework] )
512 return $this->testModuleNames[$framework];
526 return isset( $this->moduleInfos[$name] );
541 if ( !isset( $this->modules[$name] ) ) {
542 if ( !isset( $this->moduleInfos[$name] ) ) {
547 $info = $this->moduleInfos[
$name];
549 if ( isset( $info[
'object'] ) ) {
551 $object = $info[
'object'];
552 } elseif ( isset( $info[
'factory'] ) ) {
553 $object = call_user_func( $info[
'factory'], $info );
554 $object->setConfig( $this->getConfig() );
555 $object->setLogger( $this->logger );
557 if ( !isset( $info[
'class'] ) ) {
558 $class =
'ResourceLoaderFileModule';
560 $class = $info[
'class'];
563 $object =
new $class( $info );
564 $object->setConfig( $this->getConfig() );
565 $object->setLogger( $this->logger );
567 $object->setName( $name );
568 $this->modules[
$name] = $object;
571 return $this->modules[
$name];
582 if ( !isset( $this->moduleInfos[$name] ) ) {
585 $info = $this->moduleInfos[
$name];
586 if ( isset( $info[
'object'] ) ) {
590 isset( $info[
'class'] ) &&
591 $info[
'class'] !==
'ResourceLoaderFileModule' &&
592 !is_subclass_of( $info[
'class'],
'ResourceLoaderFileModule' )
605 return $this->sources;
618 if ( !isset( $this->sources[
$source] ) ) {
619 throw new MWException(
"The $source source was never registered in ResourceLoader." );
621 return $this->sources[
$source];
630 $hash = hash(
'fnv132',
$value );
631 return Wikimedia\base_convert( $hash, 16, 36, 7 );
645 MWExceptionHandler::logException(
$e );
646 $this->logger->warning(
650 $this->errors[] = self::formatExceptionNoComment(
$e );
662 if ( !$moduleNames ) {
667 return $this->getModule( $module )->getVersionHash(
$context );
668 }
catch ( Exception
$e ) {
672 $this->outputErrorAndLog(
$e,
673 'Calculating version for "{module}" failed: {exception}',
681 return self::makeHash( implode(
'',
$hashes ) );
705 foreach (
$context->getModules() as $name ) {
706 if ( !$this->getModule( $name ) ) {
711 $moduleNames[] =
$name;
713 return $this->getCombinedVersion(
$context, $moduleNames );
734 foreach (
$context->getModules() as $name ) {
735 $module = $this->getModule( $name );
739 if ( $module->getGroup() ===
'private' ) {
740 $this->logger->debug(
"Request for private module '$name' denied" );
741 $this->errors[] =
"Cannot show private module \"$name\"";
753 }
catch ( Exception
$e ) {
754 $this->outputErrorAndLog(
$e,
'Preloading module info failed: {exception}' );
760 $versionHash = $this->getCombinedVersion(
$context, array_keys(
$modules ) );
761 }
catch ( Exception
$e ) {
762 $this->outputErrorAndLog(
$e,
'Calculating version hash failed: {exception}' );
767 $etag =
'W/"' . $versionHash .
'"';
770 if ( $this->tryRespondNotModified(
$context, $etag ) ) {
775 if ( $this->config->get(
'UseFileCache' ) ) {
777 if ( $this->tryRespondFromFileCache( $fileCache,
$context, $etag ) ) {
788 $warnings = ob_get_contents();
789 if ( strlen( $warnings ) ) {
790 $this->errors[] = $warnings;
795 if ( isset( $fileCache ) && !$this->errors && !count( $missing ) ) {
798 if ( $fileCache->isCacheWorthy() ) {
801 $fileCache->incrMissesRecent(
$context->getRequest() );
806 $this->sendResponseHeaders(
$context, $etag, (
bool)$this->errors, $this->extraHeaders );
811 if (
$context->getImageObj() && $this->errors ) {
813 $response = implode(
"\n\n", $this->errors );
814 } elseif ( $this->errors ) {
815 $errorText = implode(
"\n\n", $this->errors );
816 $errorResponse = self::makeComment( $errorText );
817 if (
$context->shouldIncludeScripts() ) {
818 $errorResponse .=
'if (window.console && console.error) {'
819 . Xml::encodeJsCall(
'console.error', [ $errorText ] )
845 \MediaWiki\HeaderCallback::warnIfHeadersSent();
846 $rlMaxage = $this->config->get(
'ResourceLoaderMaxage' );
851 if ( is_null(
$context->getVersion() )
855 $maxage = $rlMaxage[
'unversioned'][
'client'];
856 $smaxage = $rlMaxage[
'unversioned'][
'server'];
860 $maxage = $rlMaxage[
'versioned'][
'client'];
861 $smaxage = $rlMaxage[
'versioned'][
'server'];
866 header(
'Content-Type: text/plain; charset=utf-8' );
870 } elseif (
$context->getOnly() ===
'styles' ) {
871 header(
'Content-Type: text/css; charset=utf-8' );
872 header(
'Access-Control-Allow-Origin: *' );
874 header(
'Content-Type: text/javascript; charset=utf-8' );
878 header(
'ETag: ' . $etag );
881 header(
'Cache-Control: private, no-cache, must-revalidate' );
882 header(
'Pragma: no-cache' );
884 header(
"Cache-Control: public, max-age=$maxage, s-maxage=$smaxage" );
885 $exp = min( $maxage, $smaxage );
886 header(
'Expires: ' .
wfTimestamp( TS_RFC2822, $exp + time() ) );
888 foreach ( $extra as
$header ) {
906 $clientKeys =
$context->getRequest()->getHeader(
'If-None-Match', WebRequest::GETHEADER_LIST );
908 if ( $clientKeys !==
false && !
$context->getDebug() && in_array( $etag, $clientKeys ) ) {
922 $this->sendResponseHeaders(
$context, $etag,
false );
941 $rlMaxage = $this->config->get(
'ResourceLoaderMaxage' );
945 $maxage = is_null(
$context->getVersion() )
946 ? $rlMaxage[
'unversioned'][
'server']
947 : $rlMaxage[
'versioned'][
'server'];
960 $this->sendResponseHeaders(
$context, $etag,
false );
965 $warnings = ob_get_contents();
966 if ( strlen( $warnings ) ) {
990 $encText = str_replace(
'*/',
'* /', $text );
991 return "/*\n$encText\n*/\n";
1001 return self::makeComment( self::formatExceptionNoComment(
$e ) );
1015 return MWExceptionHandler::getPublicLogMessage(
$e );
1018 return MWExceptionHandler::getLogMessage(
$e ) .
1020 MWExceptionHandler::getRedactedTraceAsString(
$e );
1035 array
$modules, array $missing = []
1040 if ( !count(
$modules ) && !count( $missing ) ) {
1051 if ( $data ===
false ) {
1053 $this->errors[] =
'Image generation failed';
1058 foreach ( $missing as $name ) {
1059 $states[
$name] =
'missing';
1065 $filter =
$context->getOnly() ===
'styles' ?
'minify-css' :
'minify-js';
1067 foreach (
$modules as $name => $module ) {
1069 $content = $module->getModuleContent(
$context );
1070 $implementKey = $name .
'@' . $module->getVersionHash(
$context );
1073 if ( isset( $content[
'headers'] ) ) {
1074 $this->extraHeaders = array_merge( $this->extraHeaders, $content[
'headers'] );
1080 $scripts = $content[
'scripts'];
1081 if ( is_string( $scripts ) ) {
1083 $strContent = $scripts;
1084 } elseif ( is_array( $scripts ) ) {
1086 $strContent = self::makeLoaderImplementScript( $implementKey, $scripts, [], [], [] );
1090 $styles = $content[
'styles'];
1094 $strContent = isset( $styles[
'css'] ) ? implode(
'', $styles[
'css'] ) :
'';
1097 $scripts = isset( $content[
'scripts'] ) ? $content[
'scripts'] :
'';
1098 if ( is_string( $scripts ) ) {
1099 if ( $name ===
'site' || $name ===
'user' ) {
1104 if ( !self::inDebugMode() ) {
1105 $scripts = self::filter(
'minify-js', $scripts );
1111 $strContent = self::makeLoaderImplementScript(
1114 isset( $content[
'styles'] ) ? $content[
'styles'] : [],
1115 isset( $content[
'messagesBlob'] ) ?
new XmlJsCode( $content[
'messagesBlob'] ) : [],
1116 isset( $content[
'templates'] ) ? $content[
'templates'] : []
1122 $strContent = self::filter( $filter, $strContent );
1125 if (
$context->getOnly() ===
'scripts' ) {
1127 $out .= $this->ensureNewline( $strContent );
1129 $out .= $strContent;
1132 }
catch ( Exception
$e ) {
1133 $this->outputErrorAndLog(
$e,
'Generating module package failed: {exception}' );
1136 $states[
$name] =
'error';
1139 $isRaw |= $module->isRaw();
1143 if (
$context->shouldIncludeScripts() && !
$context->getRaw() && !$isRaw ) {
1147 foreach (
$modules as $name => $module ) {
1148 $states[
$name] =
'ready';
1153 if ( count( $states ) ) {
1154 $stateScript = self::makeLoaderStateScript( $states );
1156 $stateScript = self::filter(
'minify-js', $stateScript );
1159 $out = $this->ensureNewline(
$out ) . $stateScript;
1162 if ( count( $states ) ) {
1163 $this->errors[] =
'Problematic modules: ' .
1164 FormatJson::encode( $states, self::inDebugMode() );
1176 private function ensureNewline( $str ) {
1177 $end = substr( $str, -1 );
1178 if ( $end ===
false || $end ===
"\n" ) {
1190 public function getModulesByMessage( $messageKey ) {
1192 foreach ( $this->getModuleNames() as $moduleName ) {
1193 $module = $this->getModule( $moduleName );
1194 if ( in_array( $messageKey, $module->getMessages() ) ) {
1195 $moduleNames[] = $moduleName;
1198 return $moduleNames;
1219 protected static function makeLoaderImplementScript(
1220 $name, $scripts, $styles,
$messages, $templates
1223 $scripts =
new XmlJsCode(
"function ( $, jQuery, require, module ) {\n{$scripts->value}\n}" );
1224 } elseif ( !is_string( $scripts ) && !is_array( $scripts ) ) {
1225 throw new MWException(
'Invalid scripts error. Array of URLs or string of code expected.' );
1237 self::trimArray( $module );
1239 return Xml::encodeJsCall(
'mw.loader.implement', $module, self::inDebugMode() );
1249 public static function makeMessageSetScript(
$messages ) {
1264 public static function makeCombinedStyles( array $stylePairs ) {
1266 foreach ( $stylePairs as $media => $styles ) {
1270 $styles = (
array)$styles;
1271 foreach ( $styles as $style ) {
1272 $style = trim( $style );
1274 if ( $style !==
'' ) {
1279 if ( $media ===
'' || $media ==
'all' ) {
1281 } elseif ( is_string( $media ) ) {
1282 $out[] =
"@media $media {\n" . str_replace(
"\n",
"\n\t",
"\t" . $style ) .
"}";
1305 public static function makeLoaderStateScript( $name, $state =
null ) {
1306 if ( is_array( $name ) ) {
1335 public static function makeCustomLoaderScript( $name, $version, $dependencies,
1338 $script = str_replace(
"\n",
"\n\t", trim( $script ) );
1340 "( function ( name, version, dependencies, group, source ) {\n\t$script\n} )",
1341 [ $name, $version, $dependencies, $group,
$source ],
1346 private static function isEmptyObject( stdClass $obj ) {
1347 foreach ( $obj as $key =>
$value ) {
1365 private static function trimArray( array &$array ) {
1366 $i = count( $array );
1368 if ( $array[$i] ===
null
1369 || $array[$i] === []
1370 || ( $array[$i] instanceof
XmlJsCode && $array[$i]->value ===
'{}' )
1371 || ( $array[$i] instanceof stdClass && self::isEmptyObject( $array[$i] ) )
1373 unset( $array[$i] );
1407 public static function makeLoaderRegisterScript( $name, $version =
null,
1408 $dependencies =
null, $group =
null,
$source =
null, $skip =
null
1410 if ( is_array( $name ) ) {
1413 foreach ( $name as $i => &$module ) {
1414 $index[$module[0]] = $i;
1419 foreach ( $name as &$module ) {
1420 if ( isset( $module[2] ) ) {
1421 foreach ( $module[2] as &$dependency ) {
1422 if ( isset( $index[$dependency] ) ) {
1423 $dependency = $index[$dependency];
1429 array_walk( $name, [
'self',
'trimArray' ] );
1432 'mw.loader.register',
1437 $registration = [
$name, $version, $dependencies, $group,
$source, $skip ];
1438 self::trimArray( $registration );
1440 'mw.loader.register',
1461 public static function makeLoaderSourcesScript( $id, $loadUrl =
null ) {
1462 if ( is_array( $id ) ) {
1464 'mw.loader.addSource',
1470 'mw.loader.addSource',
1485 public static function makeLoaderConditionalScript( $script ) {
1486 return '(window.RLQ=window.RLQ||[]).push(function(){' .
1487 trim( $script ) .
'});';
1499 public static function makeInlineScript( $script ) {
1500 $js = self::makeLoaderConditionalScript( $script );
1501 return new WrappedString(
1502 Html::inlineScript( $js ),
1503 '<script>(window.RLQ=window.RLQ||[]).push(function(){',
1515 public static function makeConfigSetScript( array $configuration ) {
1531 public static function makePackedModulesString(
$modules ) {
1534 $pos = strrpos( $module,
'.' );
1535 $prefix = $pos ===
false ?
'' : substr( $module, 0, $pos );
1536 $suffix = $pos ===
false ? $module : substr( $module, $pos + 1 );
1537 $groups[$prefix][] = $suffix;
1541 foreach ( $groups as $prefix => $suffixes ) {
1542 $p = $prefix ===
'' ?
'' : $prefix .
'.';
1543 $arr[] = $p . implode(
',', $suffixes );
1545 $str = implode(
'|', $arr );
1554 public static function inDebugMode() {
1555 if ( self::$debugMode ===
null ) {
1557 self::$debugMode =
$wgRequest->getFuzzyBool(
'debug',
1561 return self::$debugMode;
1571 public static function clearCache() {
1572 self::$debugMode =
null;
1588 $script = $this->getLoadScript(
$source );
1603 return self::makeLoaderQuery(
1611 $context->getRequest()->getBool(
'printable' ),
1612 $context->getRequest()->getBool(
'handheld' ),
1634 public static function makeLoaderQuery(
$modules,
$lang, $skin, $user =
null,
1635 $version =
null,
$debug =
false, $only =
null, $printable =
false,
1636 $handheld =
false, $extraQuery = []
1639 'modules' => self::makePackedModulesString(
$modules ),
1642 'debug' =>
$debug ?
'true' :
'false',
1644 if ( $user !==
null ) {
1647 if ( $version !==
null ) {
1648 $query[
'version'] = $version;
1650 if ( $only !==
null ) {
1675 public static function isValidModuleName( $moduleName ) {
1676 return strcspn( $moduleName,
'!,|', 0, 255 ) === strlen( $moduleName );
1688 public function getLessCompiler( $extraVars = [] ) {
1692 if ( !class_exists(
'Less_Parser' ) ) {
1693 throw new MWException(
'MediaWiki requires the less.php parser' );
1697 $parser->ModifyVars( array_merge( $this->getLessVars(), $extraVars ) );
1699 array_fill_keys( $this->config->get(
'ResourceLoaderLESSImportPaths' ),
'' )
1701 $parser->SetOption(
'relativeUrls',
false );
1712 public function getLessVars() {
1713 if ( !$this->lessVars ) {
1714 $lessVars = $this->config->get(
'ResourceLoaderLESSVars' );
1715 Hooks::run(
'ResourceLoaderGetLessVars', [ &$lessVars ] );
1716 $this->lessVars = $lessVars;
1718 return $this->lessVars;
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 a complete stack trace to output.
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 run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
static header( $code)
Output an HTTP status code header.
static minify( $s, $statementsOnOwnLine=false, $maxLineLength=1000)
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.
static preloadTitleInfo(ResourceLoaderContext $context, IDatabase $db, array $moduleNames)
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)
Return whether the definition of a module corresponds to a simple ResourceLoaderFileModule or one of ...
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.
static int $filterCacheVersion
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)
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.
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.
the array() calling protocol came about after MediaWiki 1.4rc1.
namespace being checked & $result
do that in ParserLimitReportFormat instead $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 For a description of the see design txt $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
if(!isset( $args[0])) $lang