Go to the documentation of this file.
26 use Psr\Log\LoggerAwareInterface;
27 use Psr\Log\LoggerInterface;
28 use Psr\Log\NullLogger;
30 use Wikimedia\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 );
143 $modulesWithDeps[] = $row->md_module;
147 foreach ( array_diff( $moduleNames, $modulesWithDeps )
as $name ) {
159 foreach ( $moduleNames
as $name ) {
161 if ( $module && $module->getMessages() ) {
190 if ( strpos( $data, self::FILTER_NOMIN ) !==
false ) {
198 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
201 $key =
$cache->makeGlobalKey(
205 self::$filterCacheVersion, md5( $data )
210 $stats->increment(
"resourceloader_cache.$filter.miss" );
214 $stats->increment(
"resourceloader_cache.$filter.hit" );
225 $data = trim( $data );
228 $data = ( $filter ===
'minify-css' )
231 }
catch ( Exception
$e ) {
247 $this->logger =
$logger ?:
new NullLogger();
250 $this->logger->debug( __METHOD__ .
' was called without providing a Config instance' );
251 $config = MediaWikiServices::getInstance()->getMainConfig();
262 $this->
register( include
"$IP/resources/Resources.php" );
264 $this->
register(
$config->get(
'ResourceModules' ) );
268 Hooks::run(
'ResourceLoaderRegisterModules', [ &$rl ] );
270 if (
$config->get(
'EnableJavaScriptTest' ) ===
true ) {
329 public function register(
$name, $info = null ) {
330 $moduleSkinStyles = $this->config->
get(
'ResourceModuleSkinStyles' );
334 foreach ( $registrations
as $name => $info ) {
336 if ( isset( $this->moduleInfos[
$name] ) ) {
338 $this->logger->warning(
339 'ResourceLoader duplicate registration warning. ' .
340 'Another module has already been registered as ' .
$name
345 if ( !self::isValidModuleName(
$name ) ) {
346 throw new MWException(
"ResourceLoader module name '$name' is invalid, "
347 .
"see ResourceLoader::isValidModuleName()" );
352 $this->moduleInfos[
$name] = [
'object' => $info ];
353 $info->setName(
$name );
354 $this->modules[
$name] = $info;
355 } elseif ( is_array( $info ) ) {
357 $this->moduleInfos[
$name] = $info;
360 'ResourceLoader module info type error for module \'' .
$name .
365 // Last-minute changes
367 // Apply custom skin-defined styles to existing modules.
368 if ( $this->isFileModule( $name ) ) {
369 foreach ( $moduleSkinStyles as $skinName => $skinStyles ) {
370 // If this module already defines skinStyles for this skin, ignore $wgResourceModuleSkinStyles.
371 if ( isset( $this->moduleInfos[$name]['skinStyles
'][$skinName] ) ) {
375 // If $name is preceded with a '+
', the defined style files will be added to 'default'
376 // skinStyles, otherwise 'default' will be ignored as it normally would be.
377 if ( isset( $skinStyles[$name] ) ) {
378 $paths = (array)$skinStyles[$name];
380 } elseif ( isset( $skinStyles['+
' . $name] ) ) {
381 $paths = (array)$skinStyles['+
' . $name];
382 $styleFiles = isset( $this->moduleInfos[$name]['skinStyles
']['default'] ) ?
383 (array)$this->moduleInfos[$name]['skinStyles
']['default'] :
389 // Add new file paths, remapping them to refer to our directories and not use settings
390 // from the module we're modifying, which come
from the base
definition.
391 list( $localBasePath, $remoteBasePath ) =
398 $this->moduleInfos[
$name][
'skinStyles'][$skinName] = $styleFiles;
407 if ( $this->config->get(
'EnableJavaScriptTest' ) !==
true ) {
408 throw new MWException(
'Attempt to register JavaScript test modules '
409 .
'but <code>$wgEnableJavaScriptTest</code> is false. '
410 .
'Edit your <code>LocalSettings.php</code> to enable it.' );
415 $testModules[
'qunit'] = [];
419 Hooks::run(
'ResourceLoaderTestModules', [ &$testModules, &$rl ] );
423 foreach ( $testModules[
'qunit']
as &$module ) {
427 $module[
'position'] =
'top';
428 $module[
'dependencies'][] =
'test.mediawiki.qunit.testrunner';
431 $testModules[
'qunit'] =
432 ( include
"$IP/tests/qunit/QUnitTestResources.php" ) + $testModules[
'qunit'];
434 foreach ( $testModules
as $id => $names ) {
436 $this->
register( $testModules[$id] );
439 $this->testModuleNames[$id] = array_keys( $testModules[$id] );
455 if ( is_array( $id ) ) {
457 $this->addSource( $key,
$value );
463 if ( isset( $this->sources[$id] ) ) {
465 'ResourceLoader duplicate source addition error. ' .
466 'Another source has already been registered as ' . $id
471 if ( is_array( $loadUrl ) ) {
472 if ( !isset( $loadUrl[
'loadScript'] ) ) {
474 __METHOD__ .
' was passed an array with no "loadScript" key.'
478 $loadUrl = $loadUrl[
'loadScript'];
481 $this->sources[$id] = $loadUrl;
490 return array_keys( $this->moduleInfos );
505 if ( $framework ==
'all' ) {
506 return $this->testModuleNames;
507 } elseif ( isset( $this->testModuleNames[$framework] )
508 && is_array( $this->testModuleNames[$framework] )
510 return $this->testModuleNames[$framework];
524 return isset( $this->moduleInfos[
$name] );
539 if ( !isset( $this->modules[
$name] ) ) {
540 if ( !isset( $this->moduleInfos[
$name] ) ) {
545 $info = $this->moduleInfos[
$name];
547 if ( isset( $info[
'object'] ) ) {
549 $object = $info[
'object'];
550 } elseif ( isset( $info[
'factory'] ) ) {
551 $object = call_user_func( $info[
'factory'], $info );
552 $object->setConfig( $this->getConfig() );
553 $object->setLogger( $this->logger );
555 if ( !isset( $info[
'class'] ) ) {
558 $class = $info[
'class'];
561 $object =
new $class( $info );
562 $object->setConfig( $this->getConfig() );
563 $object->setLogger( $this->logger );
565 $object->setName(
$name );
566 $this->modules[
$name] = $object;
569 return $this->modules[
$name];
580 if ( !isset( $this->moduleInfos[
$name] ) ) {
583 $info = $this->moduleInfos[
$name];
584 if ( isset( $info[
'object'] ) ) {
588 isset( $info[
'class'] ) &&
603 return $this->sources;
616 if ( !isset( $this->sources[
$source] ) ) {
617 throw new MWException(
"The $source source was never registered in ResourceLoader." );
619 return $this->sources[
$source];
628 $hash = hash(
'fnv132',
$value );
629 return Wikimedia\base_convert( $hash, 16, 36, 7 );
644 $this->logger->warning(
648 $this->
errors[] = self::formatExceptionNoComment(
$e );
660 if ( !$moduleNames ) {
665 return $this->getModule( $module )->getVersionHash(
$context );
666 }
catch ( Exception
$e ) {
670 $this->outputErrorAndLog(
$e,
671 'Calculating version for "{module}" failed: {exception}',
679 return self::makeHash( implode(
'',
$hashes ) );
703 if ( !$this->getModule(
$name ) ) {
708 $moduleNames[] =
$name;
710 return $this->getCombinedVersion(
$context, $moduleNames );
734 $module = $this->getModule(
$name );
738 if ( $module->getGroup() ===
'private' ) {
739 $this->logger->debug(
"Request for private module '$name' denied" );
740 $this->
errors[] =
"Cannot show private module \"$name\"";
752 }
catch ( Exception
$e ) {
753 $this->outputErrorAndLog(
$e,
'Preloading module info failed: {exception}' );
759 $versionHash = $this->getCombinedVersion(
$context, array_keys(
$modules ) );
760 }
catch ( Exception
$e ) {
761 $this->outputErrorAndLog(
$e,
'Calculating version hash failed: {exception}' );
766 $etag =
'W/"' . $versionHash .
'"';
769 if ( $this->tryRespondNotModified(
$context, $etag ) ) {
774 if ( $this->config->get(
'UseFileCache' ) ) {
776 if ( $this->tryRespondFromFileCache( $fileCache,
$context, $etag ) ) {
787 $warnings = ob_get_contents();
788 if ( strlen( $warnings ) ) {
789 $this->
errors[] = $warnings;
794 if ( isset( $fileCache ) && !$this->
errors && !count( $missing ) ) {
797 if ( $fileCache->isCacheWorthy() ) {
800 $fileCache->incrMissesRecent(
$context->getRequest() );
805 $this->sendResponseHeaders(
$context, $etag, (
bool)$this->
errors, $this->extraHeaders );
810 if (
$context->getImageObj() && $this->errors ) {
812 $response = implode(
"\n\n", $this->errors );
813 } elseif ( $this->errors ) {
814 $errorText = implode(
"\n\n", $this->errors );
815 $errorResponse = self::makeComment( $errorText );
816 if (
$context->shouldIncludeScripts() ) {
817 $errorResponse .=
'if (window.console && console.error) {'
832 $measure = $timing->
measure(
'responseTime',
'requestStart',
'requestShutdown' );
833 if ( $measure !==
false ) {
834 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
835 $stats->timing(
'resourceloader.responseTime', $measure[
'duration'] * 1000 );
855 $rlMaxage = $this->config->get(
'ResourceLoaderMaxage' );
860 if ( is_null(
$context->getVersion() )
864 $maxage = $rlMaxage[
'unversioned'][
'client'];
865 $smaxage = $rlMaxage[
'unversioned'][
'server'];
869 $maxage = $rlMaxage[
'versioned'][
'client'];
870 $smaxage = $rlMaxage[
'versioned'][
'server'];
875 header(
'Content-Type: text/plain; charset=utf-8' );
879 } elseif (
$context->getOnly() ===
'styles' ) {
880 header(
'Content-Type: text/css; charset=utf-8' );
881 header(
'Access-Control-Allow-Origin: *' );
883 header(
'Content-Type: text/javascript; charset=utf-8' );
887 header(
'ETag: ' . $etag );
890 header(
'Cache-Control: private, no-cache, must-revalidate' );
891 header(
'Pragma: no-cache' );
893 header(
"Cache-Control: public, max-age=$maxage, s-maxage=$smaxage" );
894 $exp = min( $maxage, $smaxage );
895 header(
'Expires: ' .
wfTimestamp( TS_RFC2822, $exp + time() ) );
917 if ( $clientKeys !==
false && !
$context->getDebug() && in_array( $etag, $clientKeys ) ) {
931 $this->sendResponseHeaders(
$context, $etag,
false );
950 $rlMaxage = $this->config->get(
'ResourceLoaderMaxage' );
954 $maxage = is_null(
$context->getVersion() )
955 ? $rlMaxage[
'unversioned'][
'server']
956 : $rlMaxage[
'versioned'][
'server'];
969 $this->sendResponseHeaders(
$context, $etag,
false );
974 $warnings = ob_get_contents();
975 if ( strlen( $warnings ) ) {
999 $encText = str_replace(
'*/',
'* /', $text );
1000 return "/*\n$encText\n*/\n";
1010 return self::makeComment( self::formatExceptionNoComment(
$e ) );
1049 if ( !count(
$modules ) && !count( $missing ) ) {
1060 if ( $data ===
false ) {
1062 $this->
errors[] =
'Image generation failed';
1067 foreach ( $missing
as $name ) {
1068 $states[
$name] =
'missing';
1074 $filter =
$context->getOnly() ===
'styles' ?
'minify-css' :
'minify-js';
1078 $content = $module->getModuleContent(
$context );
1079 $implementKey =
$name .
'@' . $module->getVersionHash(
$context );
1082 if ( isset( $content[
'headers'] ) ) {
1083 $this->extraHeaders = array_merge( $this->extraHeaders, $content[
'headers'] );
1089 $scripts = $content[
'scripts'];
1090 if ( is_string( $scripts ) ) {
1092 $strContent = $scripts;
1093 } elseif ( is_array( $scripts ) ) {
1095 $strContent = self::makeLoaderImplementScript( $implementKey, $scripts, [], [], [] );
1099 $styles = $content[
'styles'];
1103 $strContent = isset( $styles[
'css'] ) ? implode(
'', $styles[
'css'] ) :
'';
1106 $scripts = isset( $content[
'scripts'] ) ? $content[
'scripts'] :
'';
1107 if ( is_string( $scripts ) ) {
1108 if (
$name ===
'site' ||
$name ===
'user' ) {
1113 if ( !self::inDebugMode() ) {
1114 $scripts = self::filter(
'minify-js', $scripts );
1120 $strContent = self::makeLoaderImplementScript(
1123 isset( $content[
'styles'] ) ? $content[
'styles'] : [],
1124 isset( $content[
'messagesBlob'] ) ?
new XmlJsCode( $content[
'messagesBlob'] ) : [],
1125 isset( $content[
'templates'] ) ? $content[
'templates'] : []
1131 $strContent = self::filter( $filter, $strContent );
1134 if (
$context->getOnly() ===
'scripts' ) {
1136 $out .= $this->ensureNewline( $strContent );
1138 $out .= $strContent;
1141 }
catch ( Exception
$e ) {
1142 $this->outputErrorAndLog(
$e,
'Generating module package failed: {exception}' );
1145 $states[
$name] =
'error';
1148 $isRaw |= $module->isRaw();
1152 if (
$context->shouldIncludeScripts() && !
$context->getRaw() && !$isRaw ) {
1157 $states[
$name] =
'ready';
1162 if ( count( $states ) ) {
1163 $stateScript = self::makeLoaderStateScript( $states );
1165 $stateScript = self::filter(
'minify-js', $stateScript );
1168 $out = $this->ensureNewline(
$out ) . $stateScript;
1171 if ( count( $states ) ) {
1172 $this->
errors[] =
'Problematic modules: ' .
1185 private function ensureNewline( $str ) {
1186 $end = substr( $str, -1 );
1187 if ( $end ===
false || $end ===
"\n" ) {
1199 public function getModulesByMessage( $messageKey ) {
1201 foreach ( $this->getModuleNames()
as $moduleName ) {
1202 $module = $this->getModule( $moduleName );
1203 if ( in_array( $messageKey, $module->getMessages() ) ) {
1204 $moduleNames[] = $moduleName;
1207 return $moduleNames;
1226 protected static function makeLoaderImplementScript(
1230 if ( self::inDebugMode() ) {
1231 $scripts =
new XmlJsCode(
"function ( $, jQuery, require, module ) {\n{$scripts->value}\n}" );
1233 $scripts =
new XmlJsCode(
'function($,jQuery,require,module){'. $scripts->value .
'}' );
1235 } elseif ( !is_string( $scripts ) && !is_array( $scripts ) ) {
1236 throw new MWException(
'Invalid scripts error. Array of URLs or string of code expected.' );
1248 self::trimArray( $module );
1250 return Xml::encodeJsCall(
'mw.loader.implement', $module, self::inDebugMode() );
1260 public static function makeMessageSetScript(
$messages ) {
1275 public static function makeCombinedStyles(
array $stylePairs ) {
1277 foreach ( $stylePairs
as $media => $styles ) {
1281 $styles = (
array)$styles;
1282 foreach ( $styles
as $style ) {
1283 $style = trim( $style );
1285 if ( $style !==
'' ) {
1290 if ( $media ===
'' || $media ==
'all' ) {
1292 } elseif ( is_string( $media ) ) {
1293 $out[] =
"@media $media {\n" . str_replace(
"\n",
"\n\t",
"\t" . $style ) .
"}";
1316 public static function makeLoaderStateScript(
$name, $state =
null ) {
1317 if ( is_array(
$name ) ) {
1346 public static function makeCustomLoaderScript(
$name, $version, $dependencies,
1349 $script = str_replace(
"\n",
"\n\t", trim( $script ) );
1351 "( function ( name, version, dependencies, group, source ) {\n\t$script\n} )",
1357 private static function isEmptyObject( stdClass $obj ) {
1358 foreach ( $obj
as $key =>
$value ) {
1376 private static function trimArray(
array &$array ) {
1377 $i = count( $array );
1379 if ( $array[$i] ===
null
1380 || $array[$i] === []
1381 || ( $array[$i] instanceof
XmlJsCode && $array[$i]->value ===
'{}' )
1382 || ( $array[$i] instanceof stdClass && self::isEmptyObject( $array[$i] ) )
1384 unset( $array[$i] );
1418 public static function makeLoaderRegisterScript(
$name, $version =
null,
1419 $dependencies =
null, $group =
null,
$source =
null, $skip =
null
1421 if ( is_array(
$name ) ) {
1424 foreach (
$name as $i => &$module ) {
1425 $index[$module[0]] = $i;
1430 foreach (
$name as &$module ) {
1431 if ( isset( $module[2] ) ) {
1432 foreach ( $module[2]
as &$dependency ) {
1433 if ( isset( $index[$dependency] ) ) {
1434 $dependency = $index[$dependency];
1440 array_walk(
$name, [
'self',
'trimArray' ] );
1443 'mw.loader.register',
1448 $registration = [
$name, $version, $dependencies, $group,
$source, $skip ];
1449 self::trimArray( $registration );
1451 'mw.loader.register',
1472 public static function makeLoaderSourcesScript( $id, $loadUrl =
null ) {
1473 if ( is_array( $id ) ) {
1475 'mw.loader.addSource',
1481 'mw.loader.addSource',
1494 public static function makeLoaderConditionalScript( $script ) {
1495 return '(window.RLQ=window.RLQ||[]).push(function(){' .
1496 trim( $script ) .
'});';
1508 public static function makeInlineScript( $script ) {
1509 $js = self::makeLoaderConditionalScript( $script );
1510 return new WrappedString(
1512 '<script>(window.RLQ=window.RLQ||[]).push(function(){',
1524 public static function makeConfigSetScript(
array $configuration ) {
1545 public static function makePackedModulesString(
$modules ) {
1548 $pos = strrpos( $module,
'.' );
1549 $prefix = $pos ===
false ?
'' : substr( $module, 0, $pos );
1550 $suffix = $pos ===
false ? $module : substr( $module, $pos + 1 );
1551 $moduleMap[$prefix][] = $suffix;
1555 foreach ( $moduleMap
as $prefix => $suffixes ) {
1556 $p = $prefix ===
'' ?
'' : $prefix .
'.';
1557 $arr[] = $p . implode(
',', $suffixes );
1559 return implode(
'|', $arr );
1567 public static function inDebugMode() {
1568 if ( self::$debugMode ===
null ) {
1570 self::$debugMode =
$wgRequest->getFuzzyBool(
'debug',
1574 return self::$debugMode;
1584 public static function clearCache() {
1585 self::$debugMode =
null;
1601 $script = $this->getLoadScript(
$source );
1616 return self::makeLoaderQuery(
1624 $context->getRequest()->getBool(
'printable' ),
1625 $context->getRequest()->getBool(
'handheld' ),
1648 $version =
null,
$debug =
false, $only =
null, $printable =
false,
1649 $handheld =
false, $extraQuery = []
1652 'modules' => self::makePackedModulesString(
$modules ),
1655 'debug' =>
$debug ?
'true' :
'false',
1657 if (
$user !==
null ) {
1660 if ( $version !==
null ) {
1661 $query[
'version'] = $version;
1663 if ( $only !==
null ) {
1688 public static function isValidModuleName( $moduleName ) {
1689 return strcspn( $moduleName,
'!,|', 0, 255 ) === strlen( $moduleName );
1701 public function getLessCompiler( $extraVars = [] ) {
1705 if ( !class_exists(
'Less_Parser' ) ) {
1706 throw new MWException(
'MediaWiki requires the less.php parser' );
1710 $parser->ModifyVars( array_merge( $this->getLessVars(), $extraVars ) );
1712 array_fill_keys( $this->config->get(
'ResourceLoaderLESSImportPaths' ),
'' )
1714 $parser->SetOption(
'relativeUrls',
false );
1725 public function getLessVars() {
1726 if ( $this->lessVars ===
null ) {
1727 $this->lessVars = $this->config->get(
'ResourceLoaderLESSVars' );
1729 return $this->lessVars;
static filter( $filter, $data, array $options=[])
Run JavaScript or CSS data through a filter, caching the filtered result for future calls.
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 account $user
Object passed around to modules which contains information about the state of a specific loader reque...
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
wfResetOutputBuffers( $resetGzipEncoding=true)
Clear away any user-level output buffers, discarding contents.
sendResponseHeaders(ResourceLoaderContext $context, $etag, $errors, array $extra=[])
Send main response headers to the client.
array $errors
Errors accumulated during current respond() call.
static minify( $css)
Removes whitespace from CSS data.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static newFromContext(ResourceLoaderContext $context)
Construct an ResourceFileCache from a context.
isCacheGood( $timestamp='')
Check if up to date cache file exists.
makeVersionQuery(ResourceLoaderContext $context)
Get the expected value of the 'version' query parameter.
this hook is for auditing only $response
the array() calling protocol came about after MediaWiki 1.4rc1.
static formatException( $e)
Handle exception display.
if(!isset( $args[0])) $lang
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
isFileModule( $name)
Return whether the definition of a module corresponds to a simple ResourceLoaderFileModule or one of ...
An object to represent a path to a JavaScript/CSS file, along with a remote and local base path,...
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
array $moduleInfos
Associative array mapping module name to info associative array.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
getTestModuleNames( $framework='all')
Get a list of test module names for one (or all) frameworks.
static inlineScript( $contents)
Output a "<script>" tag with the given contents.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
preloadModuleInfo(array $moduleNames, ResourceLoaderContext $context)
Load information stored in the database about modules.
static transformCssMedia( $media)
Transform "media" attribute based on request parameters.
array $modules
Module name/ResourceLoaderModule object pairs.
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
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.
setMessageBlobStore(MessageBlobStore $blobStore)
Interface for configuration instances.
static getPublicLogMessage( $e)
makeModuleResponse(ResourceLoaderContext $context, array $modules, array $missing=[])
Generate code for a response.
static preloadTitleInfo(ResourceLoaderContext $context, IDatabase $db, array $moduleNames)
An interface to help developers measure the performance of their applications.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static getLogMessage( $e)
Get a message formatting the exception message and its origin.
do that in ParserLimitReportFormat instead $parser
measure( $measureName, $startMark='requestStart', $endMark=null)
This method stores the duration between two marks along with the associated name (a "measure").
getSources()
Get the list of sources.
static extractBasePaths( $options=[], $localBasePath=null, $remoteBasePath=null)
Extract a pair of local and remote base paths from module definition information.
static makeComment( $text)
Generate a CSS or JS comment block.
when a variable name is used in a it is silently declared as a new masking the global
static expandRelativePaths(array $filePaths)
Expand directories relative to $IP.
fetchText()
Get the uncompressed text from the cache.
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 int $filterCacheVersion
the value of this variable comes from LanguageConverter indexed by page_id indexed by prefixed DB keys can modify can modify can modify this should be populated with an alert message to that effect to be fed to an HTMLForm object and populate $result with the reason in the form of error messages should be plain text with no special etc to show that they re errors
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
getModule( $name)
Get the ResourceLoaderModule object for a given module name.
get(ResourceLoader $resourceLoader, $modules, $lang)
static useFileCache(ResourceLoaderContext $context)
Check if an RL request can be cached.
getLoadScript( $source)
Get the URL to the load.php endpoint for the given ResourceLoader source.
__construct(Config $config=null, LoggerInterface $logger=null)
Register core modules and runs registration hooks.
static applyFilter( $filter, $data)
array $testModuleNames
Associative array mapping framework ids to a list of names of test suite modules like [ 'qunit' => [ ...
isModuleRegistered( $name)
Check whether a ResourceLoader module is registered.
MessageBlobStore $blobStore
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 getMain()
Get the RequestContext object associated with the main request.
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
Allows to change the fields on the form that will be generated $name
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Dynamic JavaScript and CSS resource loading system.
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
static header( $code)
Output an HTTP status code header.
const GETHEADER_LIST
Flag to make WebRequest::getHeader return an array of values.
tryRespondFromFileCache(ResourceFileCache $fileCache, ResourceLoaderContext $context, $etag)
Send out code for a response from file cache if possible.
$wgShowExceptionDetails
If set to true, uncaught exceptions will print a complete stack trace to output.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
static minify( $s)
Returns minified JavaScript code.
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 from
This class generates message blobs for use by ResourceLoader modules.
addSource( $id, $loadUrl=null)
Add a foreign source of modules.
tryRespondNotModified(ResourceLoaderContext $context, $etag)
Respond with HTTP 304 Not Modified if appropiate.
static formatExceptionNoComment( $e)
Handle exception display.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
array $extraHeaders
List of extra HTTP response headers provided by loaded modules.
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
if(! $wgDBerrorLogTZ) $wgRequest
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
null for the 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
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
ResourceLoader request result caching in the file system.
$wgResourceLoaderDebug
The default debug mode (on/off) for of ResourceLoader requests.
static getRedactedTraceAsString( $e)
Generate a string representation of an exception's stack trace.
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
outputErrorAndLog(Exception $e, $msg, array $context=[])
Add an error to the 'errors' array and log it.
getModuleNames()
Get a list of module names.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
setLogger(LoggerInterface $logger)
cacheTimestamp()
Get the last-modified timestamp of the cache file.
measureResponseTime(Timing $timing)
static logException( $e, $catcher=self::CAUGHT_BY_OTHER)
Log an exception to the exception log (if enabled).
static getLocalServerInstance( $fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)