Debian Codegraph @

includes/SetupDynamicConfig.php

raw symbols SCIP
1 <?php
2 /**
3 * This is included by Setup.php to adjust the values of globals before services are initialized.
4 * It's split into a separate file so it can be tested.
5 */
6
7 use MediaWiki\Language\LanguageCode;
8 use MediaWiki\MainConfigSchema;
9 use MediaWiki\Title\NamespaceInfo;
10 use Wikimedia\AtEase\AtEase;
11
12 // For backwards compatibility, the value of wgLogos is copied to wgLogo.
13 // This is because some extensions/skins may be using $config->get('Logo')
14 // to access the value.
15 if ( $wgLogos !== false && isset( $wgLogos['1x'] ) ) {
16 $wgLogo = $wgLogos['1x'];
17 }
18
19 // Back-compat
20 if ( isset( $wgFileBlacklist ) ) {
21 $wgProhibitedFileExtensions = array_merge( $wgProhibitedFileExtensions, $wgFileBlacklist );
22 } else {
23 $wgFileBlacklist = $wgProhibitedFileExtensions;
24 }
25 if ( isset( $wgMimeTypeBlacklist ) ) {
26 $wgMimeTypeExclusions = array_merge( $wgMimeTypeExclusions, $wgMimeTypeBlacklist );
27 } else {
28 $wgMimeTypeBlacklist = $wgMimeTypeExclusions;
29 }
30 if ( isset( $wgEnableUserEmailBlacklist ) ) {
31 $wgEnableUserEmailMuteList = $wgEnableUserEmailBlacklist;
32 } else {
33 $wgEnableUserEmailBlacklist = $wgEnableUserEmailMuteList;
34 }
35 if ( isset( $wgShortPagesNamespaceBlacklist ) ) {
36 $wgShortPagesNamespaceExclusions = $wgShortPagesNamespaceBlacklist;
37 } else {
38 $wgShortPagesNamespaceBlacklist = $wgShortPagesNamespaceExclusions;
39 }
40
41 // Rate limits should have the same name as the corresponding permission
42 if ( isset( $wgRateLimits['emailuser'] ) ) {
43 // If the deprecated field is set, use it.
44 // Note that we can't know whether the new field has been set explicitly, since it has a default value.
45 $wgSettings->warning(
46 'RateLimit: The "emailuser" limit is deprecated, use "sendemail" instead.'
47 );
48 $wgRateLimits['sendemail'] = $wgRateLimits['emailuser'];
49 }
50
51 // Rate limits should have the same name as the corresponding permission
52 if ( isset( $wgRateLimits['changetag'] ) ) {
53 // If the deprecated field is set, use it.
54 // Note that we can't know whether the new field has been set explicitly, since it has a default value.
55 $wgSettings->warning(
56 'RateLimit: The "changetag" limit is deprecated, use "changetags" instead.'
57 );
58 $wgRateLimits['changetags'] = $wgRateLimits['changetag'];
59 }
60
61 // Prohibited file extensions shouldn't appear on the "allowed" list
62 // @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal False positive
63 $wgFileExtensions = array_values( array_diff( $wgFileExtensions, $wgProhibitedFileExtensions ) );
64
65 // Fix path to icon images after they were moved in 1.24
66 if ( $wgRightsIcon ) {
67 $wgRightsIcon = str_replace(
68 "{$wgStylePath}/common/images/",
69 "{$wgResourceBasePath}/resources/assets/licenses/",
70 $wgRightsIcon
71 );
72 }
73
74 if ( isset( $wgFooterIcons['copyright']['copyright'] )
75 && $wgFooterIcons['copyright']['copyright'] === []
76 ) {
77 if ( $wgRightsIcon || $wgRightsText ) {
78 $wgFooterIcons['copyright']['copyright'] = [
79 'url' => $wgRightsUrl,
80 'src' => $wgRightsIcon,
81 'alt' => $wgRightsText,
82 ];
83 }
84 }
85
86 if ( isset( $wgFooterIcons['poweredby'] )
87 && isset( $wgFooterIcons['poweredby']['mediawiki'] )
88 && is_array( $wgFooterIcons['poweredby']['mediawiki'] )
89 && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
90 ) {
91 $wgFooterIcons['poweredby']['mediawiki']['src'] =
92 "$wgResourceBasePath/resources/assets/poweredby_mediawiki.svg";
93 }
94
95 // Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
96 // sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
97 //
98 // Note that this is the definition of editinterface and it can be granted to
99 // all users if desired.
100 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
101
102 // Initialise $wgLockManagers to include basic FS version
103 $wgLockManagers[] = [
104 'name' => 'fsLockManager',
105 'class' => FSLockManager::class,
106 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
107 ];
108 $wgLockManagers[] = [
109 'name' => 'nullLockManager',
110 'class' => NullLockManager::class,
111 ];
112
113 // Default parameters for the "<gallery>" tag.
114 // See \MediaWiki\MainConfigSchema::GalleryOptions
115 $wgGalleryOptions += [
116 'imagesPerRow' => 0,
117 'imageWidth' => 120,
118 'imageHeight' => 120,
119 'captionLength' => true,
120 'showBytes' => true,
121 'showDimensions' => true,
122 'mode' => 'traditional',
123 ];
124
125 if ( isset( $wgLocalFileRepo['name'] ) && !isset( $wgLocalFileRepo['backend'] ) ) {
126 // Create a default FileBackend name.
127 // FileBackendGroup will register a default, if absent from $wgFileBackends.
128 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
129 }
130
131 /**
132 * Shortcuts for $wgForeignFileRepos
133 */
134 if ( $wgUseSharedUploads ) {
135 if ( $wgSharedUploadDBname ) {
136 $wgForeignFileRepos[] = [
137 'class' => ForeignDBRepo::class,
138 'name' => 'shared',
139 'directory' => $wgSharedUploadDirectory,
140 'url' => $wgSharedUploadPath,
141 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
142 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
143 'transformVia404' => !$wgGenerateThumbnailOnParse,
144 'dbType' => $wgDBtype,
145 'dbServer' => $wgDBserver,
146 'dbUser' => $wgDBuser,
147 'dbPassword' => $wgDBpassword,
148 'dbName' => $wgSharedUploadDBname,
149 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
150 'tablePrefix' => $wgSharedUploadDBprefix,
151 'hasSharedCache' => $wgCacheSharedUploads,
152 'descBaseUrl' => $wgRepositoryBaseUrl,
153 'fetchDescription' => $wgFetchCommonsDescriptions,
154 ];
155 } else {
156 $wgForeignFileRepos[] = [
157 'class' => FileRepo::class,
158 'name' => 'shared',
159 'directory' => $wgSharedUploadDirectory,
160 'url' => $wgSharedUploadPath,
161 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
162 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
163 'transformVia404' => !$wgGenerateThumbnailOnParse,
164 'descBaseUrl' => $wgRepositoryBaseUrl,
165 'fetchDescription' => $wgFetchCommonsDescriptions,
166 ];
167 }
168 }
169 if ( $wgUseInstantCommons ) {
170 $wgForeignFileRepos[] = [
171 'class' => ForeignAPIRepo::class,
172 'name' => 'wikimediacommons',
173 'apibase' => 'https://commons.wikimedia.org/w/api.php',
174 'url' => 'https://upload.wikimedia.org/wikipedia/commons',
175 'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
176 'hashLevels' => 2,
177 'transformVia404' => true,
178 'fetchDescription' => true,
179 'descriptionCacheExpiry' => 43200,
180 'apiThumbCacheExpiry' => 0,
181 ];
182 }
183 foreach ( $wgForeignFileRepos as &$repo ) {
184 if ( !isset( $repo['directory'] ) && $repo['class'] === ForeignAPIRepo::class ) {
185 $repo['directory'] = $wgUploadDirectory; // b/c
186 }
187 if ( !isset( $repo['backend'] ) ) {
188 $repo['backend'] = $repo['name'] . '-backend';
189 }
190 }
191 unset( $repo ); // no global pollution; destroy reference
192
193 $rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 );
194 // Ensure that default user options are not invalid, since that breaks Special:Preferences
195 $wgDefaultUserOptions['rcdays'] = min(
196 $wgDefaultUserOptions['rcdays'],
197 ceil( $rcMaxAgeDays )
198 );
199 $wgDefaultUserOptions['watchlistdays'] = min(
200 $wgDefaultUserOptions['watchlistdays'],
201 ceil( $rcMaxAgeDays )
202 );
203 unset( $rcMaxAgeDays );
204
205 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
206
207 if ( !$wgEnableEmail ) {
208 // Disable all other email settings automatically if $wgEnableEmail
209 // is set to false. - T65678
210 $wgAllowHTMLEmail = false;
211 $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
212 $wgEnableUserEmail = false;
213 $wgEnotifFromEditor = false;
214 $wgEnotifImpersonal = false;
215 $wgEnotifMaxRecips = 0;
216 $wgEnotifMinorEdits = false;
217 $wgEnotifRevealEditorAddress = false;
218 $wgEnotifUseRealName = false;
219 $wgEnotifUserTalk = false;
220 $wgEnotifWatchlist = false;
221 unset( $wgGroupPermissions['user']['sendemail'] );
222 $wgUserEmailUseReplyTo = false;
223 $wgUsersNotifiedOnAllChanges = [];
224 }
225
226 if ( !$wgLocaltimezone ) {
227 // NOTE: The automatic dynamic default only kicks in if $wgLocaltimezone is null,
228 // but the installer writes $wgLocaltimezone into LocalSettings, and may
229 // produce (or may have produced historically) an empty string for some
230 // reason. To be compatible with existing LocalSettings.php files, we need
231 // to gracefully handle the case of $wgLocaltimezone being the empty string.
232 // See T305093#8063451.
233 $wgLocaltimezone = MainConfigSchema::getDefaultLocaltimezone();
234 $wgSettings->warning(
235 'The Localtimezone setting must a valid timezone string or null. '
236 . 'It must not be an empty string or false.'
237 );
238 }
239
240 // The part after the System| is ignored, but rest of MW fills it out as the local offset.
241 $wgDefaultUserOptions['timecorrection'] = "System|$wgLocalTZoffset";
242
243 /**
244 * Definitions of the NS_ constants are in Defines.php
245 * @internal
246 */
247 $wgCanonicalNamespaceNames = NamespaceInfo::CANONICAL_NAMES;
248
249 // Hard-deprecate setting $wgDummyLanguageCodes in LocalSettings.php
250 if ( count( $wgDummyLanguageCodes ) !== 0 ) {
251 $wgSettings->warning(
252 'Do not add to DummyLanguageCodes directly, ' .
253 'add to ExtraLanguageCodes instead.'
254 );
255 }
256 // Merge in the legacy language codes, incorporating overrides from the config
257 $wgDummyLanguageCodes += [
258 // Internal language codes of the private-use area which get mapped to
259 // themselves.
260 'qqq' => 'qqq', // Used for message documentation
261 'qqx' => 'qqx', // Used for viewing message keys
262 ] + $wgExtraLanguageCodes + LanguageCode::getDeprecatedCodeMapping();
263 // Merge in (inverted) BCP 47 mappings
264 foreach ( LanguageCode::getNonstandardLanguageCodeMapping() as $code => $bcp47 ) {
265 $bcp47 = strtolower( $bcp47 ); // force case-insensitivity
266 if ( !isset( $wgDummyLanguageCodes[$bcp47] ) ) {
267 $wgDummyLanguageCodes[$bcp47] = $wgDummyLanguageCodes[$code] ?? $code;
268 }
269 }
270 unset( $code ); // no global pollution; destroy reference
271 unset( $bcp47 ); // no global pollution; destroy reference
272 if ( $wgUseXssLanguage ) {
273 $wgDummyLanguageCodes['x-xss'] = 'x-xss'; // Used for testing
274 }
275
276 // Temporary backwards-compatibility reading of old replica lag settings as of MediaWiki 1.36,
277 // to support sysadmins who fail to update their settings immediately:
278
279 if ( isset( $wgSlaveLagWarning ) ) {
280 // If the old value is set to something other than the default, use it.
281 if ( $wgDatabaseReplicaLagWarning === 10 && $wgSlaveLagWarning !== 10 ) {
282 $wgDatabaseReplicaLagWarning = $wgSlaveLagWarning;
283 $wgSettings->warning( 'SlaveLagWarning is no longer supported, ' .
284 'use DatabaseReplicaLagWarning instead!' );
285 }
286 } else {
287 // Backwards-compatibility for extensions that read this value.
288 $wgSlaveLagWarning = $wgDatabaseReplicaLagWarning;
289 }
290
291 if ( isset( $wgSlaveLagCritical ) ) {
292 // If the old value is set to something other than the default, use it.
293 if ( $wgDatabaseReplicaLagCritical === 30 && $wgSlaveLagCritical !== 30 ) {
294 $wgDatabaseReplicaLagCritical = $wgSlaveLagCritical;
295 $wgSettings->warning( 'SlaveLagCritical is no longer supported, ' .
296 'use DatabaseReplicaLagCritical instead!' );
297 }
298 } else {
299 // Backwards-compatibility for extensions that read this value.
300 $wgSlaveLagCritical = $wgDatabaseReplicaLagCritical;
301 }
302
303 if ( $wgInvalidateCacheOnLocalSettingsChange && defined( 'MW_CONFIG_FILE' ) ) {
304 AtEase::suppressWarnings();
305 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', filemtime( MW_CONFIG_FILE ) ) );
306 AtEase::restoreWarnings();
307 }
308
309 if ( $wgNewUserLog ) {
310 // Add new user log type
311 $wgLogTypes[] = 'newusers';
312 $wgLogNames['newusers'] = 'newuserlogpage';
313 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
314 $wgLogActionsHandlers['newusers/newusers'] = NewUsersLogFormatter::class;
315 $wgLogActionsHandlers['newusers/create'] = NewUsersLogFormatter::class;
316 $wgLogActionsHandlers['newusers/create2'] = NewUsersLogFormatter::class;
317 $wgLogActionsHandlers['newusers/byemail'] = NewUsersLogFormatter::class;
318 $wgLogActionsHandlers['newusers/autocreate'] = NewUsersLogFormatter::class;
319 }
320
321 if ( $wgPageCreationLog ) {
322 // Add page creation log type
323 $wgLogTypes[] = 'create';
324 $wgLogActionsHandlers['create/create'] = LogFormatter::class;
325 }
326
327 if ( $wgPageLanguageUseDB ) {
328 $wgLogTypes[] = 'pagelang';
329 $wgLogActionsHandlers['pagelang/pagelang'] = [
330 'class' => PageLangLogFormatter::class,
331 'services' => [
332 'LanguageNameUtils',
333 ]
334 ];
335 }
336
337 if ( $wgPHPSessionHandling !== 'enable' &&
338 $wgPHPSessionHandling !== 'warn' &&
339 $wgPHPSessionHandling !== 'disable'
340 ) {
341 $wgPHPSessionHandling = 'warn';
342 }
343 if ( defined( 'MW_NO_SESSION' ) ) {
344 // If the entry point wants no session, force 'disable' here unless they
345 // specifically set it to the (undocumented) 'warn'.
346 $wgPHPSessionHandling = MW_NO_SESSION === 'warn' ? 'warn' : 'disable';
347 }
348
349 // Backwards compatibility with old bot passwords storage configs
350 if ( !$wgVirtualDomainsMapping ) {
351 $wgVirtualDomainsMapping = [];
352 }
353 if ( $wgBotPasswordsCluster ) {
354 $wgVirtualDomainsMapping['virtual-botpasswords']['cluster'] = $wgBotPasswordsCluster;
355 }
356
357 if ( $wgBotPasswordsDatabase ) {
358 $wgVirtualDomainsMapping['virtual-botpasswords']['db'] = $wgBotPasswordsDatabase;
359 }