57 $mainPage = Title::newFromText(
$context->msg(
'mainpage' )->inContentLanguage()->text() );
59 $mainPage = Title::newFromText(
'Main Page' );
67 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
68 $namespaceIds = $contLang->getNamespaceIds();
69 $caseSensitiveNamespaces = [];
70 foreach ( MWNamespace::getCanonicalNamespaces() as $index => $name ) {
71 $namespaceIds[$contLang->lc( $name )] = $index;
72 if ( !MWNamespace::isCapitalized( $index ) ) {
73 $caseSensitiveNamespaces[] = $index;
77 $illegalFileChars = $conf->get(
'IllegalFileChars' );
78 $oldCommentSchema = $conf->get(
'CommentTableSchemaMigrationStage' ) ===
MIGRATION_OLD;
82 'wgLoadScript' =>
wfScript(
'load' ),
85 'stylepath' => $conf->get(
'StylePath' ),
87 'wgArticlePath' => $conf->get(
'ArticlePath' ),
88 'wgScriptPath' => $conf->get(
'ScriptPath' ),
90 'wgSearchType' => $conf->get(
'SearchType' ),
91 'wgVariantArticlePath' => $conf->get(
'VariantArticlePath' ),
94 'wgActionPaths' => (
object)$conf->get(
'ActionPaths' ),
95 'wgServer' => $conf->get(
'Server' ),
96 'wgServerName' => $conf->get(
'ServerName' ),
97 'wgUserLanguage' =>
$context->getLanguage(),
98 'wgContentLanguage' => $contLang->getCode(),
99 'wgTranslateNumerals' => $conf->get(
'TranslateNumerals' ),
100 'wgVersion' => $conf->get(
'Version' ),
101 'wgEnableAPI' =>
true,
102 'wgEnableWriteAPI' =>
true,
103 'wgMainPageTitle' => $mainPage->getPrefixedText(),
104 'wgFormattedNamespaces' => $contLang->getFormattedNamespaces(),
105 'wgNamespaceIds' => $namespaceIds,
106 'wgContentNamespaces' => MWNamespace::getContentNamespaces(),
107 'wgSiteName' => $conf->get(
'Sitename' ),
108 'wgDBname' => $conf->get(
'DBname' ),
109 'wgExtraSignatureNamespaces' => $conf->get(
'ExtraSignatureNamespaces' ),
110 'wgAvailableSkins' => Skin::getSkinNames(),
111 'wgExtensionAssetsPath' => $conf->get(
'ExtensionAssetsPath' ),
113 'wgCookiePrefix' => $conf->get(
'CookiePrefix' ),
114 'wgCookieDomain' => $conf->get(
'CookieDomain' ),
115 'wgCookiePath' => $conf->get(
'CookiePath' ),
116 'wgCookieExpiration' => $conf->get(
'CookieExpiration' ),
117 'wgResourceLoaderMaxQueryLength' => $conf->get(
'ResourceLoaderMaxQueryLength' ),
118 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces,
119 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass( Title::legalChars() ),
120 'wgIllegalFileChars' => Title::convertByteClassToUnicodeClass( $illegalFileChars ),
121 'wgResourceLoaderStorageVersion' => $conf->get(
'ResourceLoaderStorageVersion' ),
122 'wgResourceLoaderStorageEnabled' => $conf->get(
'ResourceLoaderStorageEnabled' ),
123 'wgForeignUploadTargets' => $conf->get(
'ForeignUploadTargets' ),
124 'wgEnableUploads' => $conf->get(
'EnableUploads' ),
125 'wgCommentByteLimit' => $oldCommentSchema ? 255 :
null,
126 'wgCommentCodePointLimit' => $oldCommentSchema ? null : CommentStore::COMMENT_CHARACTER_LIMIT,
129 Hooks::run(
'ResourceLoaderGetConfigVars', [ &
$vars ] );
142 static $dependencyCache = [];
146 if ( !isset( $dependencyCache[$moduleName] ) ) {
147 if ( !isset( $registryData[$moduleName] ) ) {
149 $dependencyCache[$moduleName] = [];
151 $data = $registryData[$moduleName];
152 $dependencyCache[$moduleName] = $data[
'dependencies'];
154 foreach ( $data[
'dependencies'] as $dependency ) {
156 $dependencyCache[$moduleName] = array_merge(
157 $dependencyCache[$moduleName],
158 self::getImplicitDependencies( $registryData, $dependency )
164 return $dependencyCache[$moduleName];
186 foreach ( $registryData as $name => &$data ) {
187 $dependencies = $data[
'dependencies'];
188 foreach ( $data[
'dependencies'] as $dependency ) {
190 $dependencies = array_diff( $dependencies, $implicitDependencies );
193 $data[
'dependencies'] = array_values( $dependencies );
207 $target =
$context->getRequest()->getRawVal(
'target',
'desktop' );
208 $safemode =
$context->getRequest()->getRawVal(
'safemode' ) ===
'1';
211 $byPassTargetFilter = $this->
getConfig()->get(
'EnableJavaScriptTest' ) && $target ===
'test';
222 }
catch ( Exception
$e ) {
226 'Preloading module info from startup failed: {exception}',
227 [
'exception' =>
$e ]
232 foreach ( $moduleNames as $name ) {
234 $moduleTargets = $module->getTargets();
236 ( !$byPassTargetFilter && !in_array( $target, $moduleTargets ) )
242 if ( $module->isRaw() ) {
258 }
catch ( Exception
$e ) {
262 'Calculating version for "{module}" failed: {exception}',
269 $states[
$name] =
'error';
274 "Module '{module}' produced an invalid version hash: '{version}'.",
285 $skipFunction = $module->getSkipFunction();
290 $registryData[
$name] = [
292 'dependencies' => $module->getDependencies(
$context ),
293 'group' => $module->getGroup(),
294 'source' => $module->getSource(),
295 'skip' => $skipFunction,
306 foreach ( $registryData as $name => $data ) {
311 $data[
'dependencies'],
314 $data[
'source'] ===
'local' ? null : $data[
'source'],
376 $baseModules = [
'jquery',
'mediawiki.base' ];
378 $baseModules[] =
'mediawiki.legacy.wikibits';
390 if (
$context->getOnly() !==
'scripts' ) {
391 return '/* Requires only=script */';
394 $startupCode = file_get_contents(
"$IP/resources/src/startup/startup.js" );
398 $mwLoaderCode = file_get_contents(
"$IP/resources/src/startup/mediawiki.js" ) .
399 file_get_contents(
"$IP/resources/src/startup/mediawiki.requestIdleCallback.js" );
401 $mwLoaderCode .= file_get_contents(
"$IP/resources/src/startup/mediawiki.log.js" );
403 if ( $this->
getConfig()->
get(
'ResourceLoaderEnableJSProfiler' ) ) {
404 $mwLoaderCode .= file_get_contents(
"$IP/resources/src/startup/profiler.js" );
412 '$CODE.profileExecuteStart();' =>
'mw.loader.profiler.onExecuteStart( module );',
413 '$CODE.profileExecuteEnd();' =>
'mw.loader.profiler.onExecuteEnd( module );',
414 '$CODE.profileScriptStart();' =>
'mw.loader.profiler.onScriptStart( module );',
415 '$CODE.profileScriptEnd();' =>
'mw.loader.profiler.onScriptEnd( module );',
417 if ( $this->
getConfig()->
get(
'ResourceLoaderEnableJSProfiler' ) ) {
419 $mwLoaderPairs += $profilerStubs;
422 $mwLoaderPairs += array_fill_keys( array_keys( $profilerStubs ),
'' );
424 $mwLoaderCode = strtr( $mwLoaderCode, $mwLoaderPairs );
429 $this->
getConfig()->
get(
'LegacyJavaScriptGlobals' )
436 '$CODE.defineLoader();' => $mwLoaderCode,
438 $startupCode = strtr( $startupCode, $pairs );
$wgIncludeLegacyJavaScript
Whether to ensure the mediawiki.legacy library is loaded before other modules.
wfUrlProtocols( $includeProtocolRelative=true)
Returns a regular expression of url protocols.
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Object passed around to modules which contains information about the state of a specific loader reque...
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
const ORIGIN_CORE_INDIVIDUAL
Module for ResourceLoader initialization.
getScript(ResourceLoaderContext $context)
enableModuleContentVersion()
static getImplicitDependencies(array $registryData, $moduleName)
Recursively get all explicit and implicit dependencies for to the given module.
static getStartupModules()
Internal modules used by ResourceLoader that cannot be depended on.
getConfigSettings( $context)
static compileUnresolvedDependencies(array &$registryData)
Optimize the dependency tree in $this->modules.
getBaseModules()
Base modules implicitly available to all modules.
getModuleRegistrations(ResourceLoaderContext $context)
Get registration code for all modules.
static getLegacyModules()
static makeLoaderStateScript( $states, $state=null)
Returns a JS call to mw.loader.state, which sets the state of one ore more modules to a given value.
static inDebugMode()
Determine whether debug mode was requested Order of priority is 1) request param, 2) cookie,...
static makeLoaderSourcesScript( $sources, $loadUrl=null)
Returns JS code which calls mw.loader.addSource() with the given parameters.
static makeLoaderRegisterScript(array $modules)
Returns JS code which calls mw.loader.register with the given parameter.
static encodeJsonForScript( $data)
Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.
static filter( $filter, $data, array $options=[])
Run JavaScript or CSS data through a filter, caching the filtered result for future calls.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
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
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 such as when responding to a resource loader request or generating HTML output & $resourceLoader
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
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))