Merge "installer: Read styles from Vector's skin.json"
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that are needed to make %MediaWiki work.
4 *
5 * This file is included by WebStart.php and doMaintenance.php so that both
6 * web and maintenance scripts share a final set up phase to include necessary
7 * files and create global object variables.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @file
25 */
26
27 /**
28 * This file is not a valid entry point, perform no further processing unless
29 * MEDIAWIKI is defined
30 */
31 if ( !defined( 'MEDIAWIKI' ) ) {
32 exit( 1 );
33 }
34
35 $fname = 'Setup.php';
36 $ps_setup = Profiler::instance()->scopedProfileIn( $fname );
37
38 // If any extensions are still queued, force load them
39 ExtensionRegistry::getInstance()->loadFromQueue();
40
41 // Check to see if we are at the file scope
42 if ( !isset( $wgVersion ) ) {
43 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
44 die( 1 );
45 }
46
47 // Set various default paths sensibly...
48 $ps_default = Profiler::instance()->scopedProfileIn( $fname . '-defaults' );
49
50 if ( $wgScript === false ) {
51 $wgScript = "$wgScriptPath/index$wgScriptExtension";
52 }
53 if ( $wgLoadScript === false ) {
54 $wgLoadScript = "$wgScriptPath/load$wgScriptExtension";
55 }
56
57 if ( $wgArticlePath === false ) {
58 if ( $wgUsePathInfo ) {
59 $wgArticlePath = "$wgScript/$1";
60 } else {
61 $wgArticlePath = "$wgScript?title=$1";
62 }
63 }
64
65 if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
66 // 'view' is assumed the default action path everywhere in the code
67 // but is rarely filled in $wgActionPaths
68 $wgActionPaths['view'] = $wgArticlePath;
69 }
70
71 if ( $wgStylePath === false ) {
72 $wgStylePath = "$wgScriptPath/skins";
73 }
74 if ( $wgLocalStylePath === false ) {
75 $wgLocalStylePath = "$wgScriptPath/skins";
76 }
77 if ( $wgStyleDirectory === false ) {
78 $wgStyleDirectory = "$IP/skins";
79 }
80 if ( $wgExtensionAssetsPath === false ) {
81 $wgExtensionAssetsPath = "$wgScriptPath/extensions";
82 }
83 if ( $wgResourceBasePath === null ) {
84 $wgResourceBasePath = $wgScriptPath;
85 }
86
87 if ( $wgLogo === false ) {
88 $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
89 }
90
91 if ( $wgUploadPath === false ) {
92 $wgUploadPath = "$wgScriptPath/images";
93 }
94 if ( $wgUploadDirectory === false ) {
95 $wgUploadDirectory = "$IP/images";
96 }
97 if ( $wgReadOnlyFile === false ) {
98 $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
99 }
100 if ( $wgFileCacheDirectory === false ) {
101 $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
102 }
103 if ( $wgDeletedDirectory === false ) {
104 $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
105 }
106
107 if ( $wgGitInfoCacheDirectory === false && $wgCacheDirectory !== false ) {
108 $wgGitInfoCacheDirectory = "{$wgCacheDirectory}/gitinfo";
109 }
110
111 // Fix path to icon images after they were moved in 1.24
112 if ( $wgRightsIcon ) {
113 $wgRightsIcon = str_replace(
114 "{$wgStylePath}/common/images/",
115 "{$wgResourceBasePath}/resources/assets/licenses/",
116 $wgRightsIcon
117 );
118 }
119
120 if ( isset( $wgFooterIcons['copyright'] )
121 && isset( $wgFooterIcons['copyright']['copyright'] )
122 && $wgFooterIcons['copyright']['copyright'] === array()
123 ) {
124 if ( $wgCopyrightIcon ) {
125 $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
126 } elseif ( $wgRightsIcon || $wgRightsText ) {
127 $wgFooterIcons['copyright']['copyright'] = array(
128 'url' => $wgRightsUrl,
129 'src' => $wgRightsIcon,
130 'alt' => $wgRightsText,
131 );
132 } else {
133 unset( $wgFooterIcons['copyright']['copyright'] );
134 }
135 }
136
137 if ( isset( $wgFooterIcons['poweredby'] )
138 && isset( $wgFooterIcons['poweredby']['mediawiki'] )
139 && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
140 ) {
141 $wgFooterIcons['poweredby']['mediawiki']['src'] =
142 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png";
143 $wgFooterIcons['poweredby']['mediawiki']['srcset'] =
144 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png 1.5x, " .
145 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png 2x";
146 }
147
148 /**
149 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
150 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
151 *
152 * Note that this is the definition of editinterface and it can be granted to
153 * all users if desired.
154 */
155 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
156
157 /**
158 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
159 * and "File_talk". The old names "Image" and "Image_talk" are
160 * retained as aliases for backwards compatibility.
161 */
162 $wgNamespaceAliases['Image'] = NS_FILE;
163 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
164
165 /**
166 * Initialise $wgLockManagers to include basic FS version
167 */
168 $wgLockManagers[] = array(
169 'name' => 'fsLockManager',
170 'class' => 'FSLockManager',
171 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
172 );
173 $wgLockManagers[] = array(
174 'name' => 'nullLockManager',
175 'class' => 'NullLockManager',
176 );
177
178 /**
179 * Initialise $wgLocalFileRepo from backwards-compatible settings
180 */
181 if ( !$wgLocalFileRepo ) {
182 $wgLocalFileRepo = array(
183 'class' => 'LocalRepo',
184 'name' => 'local',
185 'directory' => $wgUploadDirectory,
186 'scriptDirUrl' => $wgScriptPath,
187 'scriptExtension' => $wgScriptExtension,
188 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
189 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
190 'thumbScriptUrl' => $wgThumbnailScriptPath,
191 'transformVia404' => !$wgGenerateThumbnailOnParse,
192 'deletedDir' => $wgDeletedDirectory,
193 'deletedHashLevels' => $wgHashedUploadDirectory ? 3 : 0
194 );
195 }
196 /**
197 * Initialise shared repo from backwards-compatible settings
198 */
199 if ( $wgUseSharedUploads ) {
200 if ( $wgSharedUploadDBname ) {
201 $wgForeignFileRepos[] = array(
202 'class' => 'ForeignDBRepo',
203 'name' => 'shared',
204 'directory' => $wgSharedUploadDirectory,
205 'url' => $wgSharedUploadPath,
206 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
207 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
208 'transformVia404' => !$wgGenerateThumbnailOnParse,
209 'dbType' => $wgDBtype,
210 'dbServer' => $wgDBserver,
211 'dbUser' => $wgDBuser,
212 'dbPassword' => $wgDBpassword,
213 'dbName' => $wgSharedUploadDBname,
214 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
215 'tablePrefix' => $wgSharedUploadDBprefix,
216 'hasSharedCache' => $wgCacheSharedUploads,
217 'descBaseUrl' => $wgRepositoryBaseUrl,
218 'fetchDescription' => $wgFetchCommonsDescriptions,
219 );
220 } else {
221 $wgForeignFileRepos[] = array(
222 'class' => 'FileRepo',
223 'name' => 'shared',
224 'directory' => $wgSharedUploadDirectory,
225 'url' => $wgSharedUploadPath,
226 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
227 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
228 'transformVia404' => !$wgGenerateThumbnailOnParse,
229 'descBaseUrl' => $wgRepositoryBaseUrl,
230 'fetchDescription' => $wgFetchCommonsDescriptions,
231 );
232 }
233 }
234 if ( $wgUseInstantCommons ) {
235 $wgForeignFileRepos[] = array(
236 'class' => 'ForeignAPIRepo',
237 'name' => 'wikimediacommons',
238 'apibase' => WebRequest::detectProtocol() === 'https' ?
239 'https://commons.wikimedia.org/w/api.php' :
240 'http://commons.wikimedia.org/w/api.php',
241 'hashLevels' => 2,
242 'fetchDescription' => true,
243 'descriptionCacheExpiry' => 43200,
244 'apiThumbCacheExpiry' => 86400,
245 );
246 }
247 /*
248 * Add on default file backend config for file repos.
249 * FileBackendGroup will handle initializing the backends.
250 */
251 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
252 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
253 }
254 foreach ( $wgForeignFileRepos as &$repo ) {
255 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
256 $repo['directory'] = $wgUploadDirectory; // b/c
257 }
258 if ( !isset( $repo['backend'] ) ) {
259 $repo['backend'] = $repo['name'] . '-backend';
260 }
261 }
262 unset( $repo ); // no global pollution; destroy reference
263
264 if ( $wgRCFilterByAge ) {
265 // Trim down $wgRCLinkDays so that it only lists links which are valid
266 // as determined by $wgRCMaxAge.
267 // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
268 sort( $wgRCLinkDays );
269
270 // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
271 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
272 // @codingStandardsIgnoreEnd
273 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
274 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
275 break;
276 }
277 }
278 }
279
280 if ( $wgSkipSkin ) {
281 $wgSkipSkins[] = $wgSkipSkin;
282 }
283
284 // Register skins
285 // Use a closure to avoid leaking into global state
286 call_user_func( function () use ( $wgValidSkinNames ) {
287 $factory = SkinFactory::getDefaultInstance();
288 foreach ( $wgValidSkinNames as $name => $skin ) {
289 $factory->register( $name, $skin, function () use ( $name, $skin ) {
290 $class = "Skin$skin";
291 return new $class( $name );
292 } );
293 }
294 // Register a hidden "fallback" skin
295 $factory->register( 'fallback', 'Fallback', function () {
296 return new SkinFallback;
297 } );
298 // Register a hidden skin for api output
299 $factory->register( 'apioutput', 'ApiOutput', function () {
300 return new SkinApi;
301 } );
302 } );
303 $wgSkipSkins[] = 'fallback';
304 $wgSkipSkins[] = 'apioutput';
305
306 if ( $wgLocalInterwiki ) {
307 array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
308 }
309
310 // Set default shared prefix
311 if ( $wgSharedPrefix === false ) {
312 $wgSharedPrefix = $wgDBprefix;
313 }
314
315 // Set default shared schema
316 if ( $wgSharedSchema === false ) {
317 $wgSharedSchema = $wgDBmwschema;
318 }
319
320 if ( !$wgCookiePrefix ) {
321 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
322 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
323 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
324 $wgCookiePrefix = $wgSharedDB;
325 } elseif ( $wgDBprefix ) {
326 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
327 } else {
328 $wgCookiePrefix = $wgDBname;
329 }
330 }
331 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
332
333 if ( $wgEnableEmail ) {
334 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
335 } else {
336 // Disable all other email settings automatically if $wgEnableEmail
337 // is set to false. - bug 63678
338 $wgAllowHTMLEmail = false;
339 $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
340 $wgEnableUserEmail = false;
341 $wgEnotifFromEditor = false;
342 $wgEnotifImpersonal = false;
343 $wgEnotifMaxRecips = 0;
344 $wgEnotifMinorEdits = false;
345 $wgEnotifRevealEditorAddress = false;
346 $wgEnotifUseJobQ = false;
347 $wgEnotifUseRealName = false;
348 $wgEnotifUserTalk = false;
349 $wgEnotifWatchlist = false;
350 unset( $wgGroupPermissions['user']['sendemail'] );
351 $wgUseEnotif = false;
352 $wgUserEmailUseReplyTo = false;
353 $wgUsersNotifiedOnAllChanges = array();
354 }
355
356 // Doesn't make sense to have if disabled.
357 if ( !$wgEnotifMinorEdits ) {
358 $wgHiddenPrefs[] = 'enotifminoredits';
359 }
360
361 if ( $wgMetaNamespace === false ) {
362 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
363 }
364
365 // Default value is 2000 or the suhosin limit if it is between 1 and 2000
366 if ( $wgResourceLoaderMaxQueryLength === false ) {
367 $suhosinMaxValueLength = (int) ini_get( 'suhosin.get.max_value_length' );
368 if ( $suhosinMaxValueLength > 0 && $suhosinMaxValueLength < 2000 ) {
369 $wgResourceLoaderMaxQueryLength = $suhosinMaxValueLength;
370 } else {
371 $wgResourceLoaderMaxQueryLength = 2000;
372 }
373 unset($suhosinMaxValueLength);
374 }
375
376 /**
377 * Definitions of the NS_ constants are in Defines.php
378 * @private
379 */
380 $wgCanonicalNamespaceNames = array(
381 NS_MEDIA => 'Media',
382 NS_SPECIAL => 'Special',
383 NS_TALK => 'Talk',
384 NS_USER => 'User',
385 NS_USER_TALK => 'User_talk',
386 NS_PROJECT => 'Project',
387 NS_PROJECT_TALK => 'Project_talk',
388 NS_FILE => 'File',
389 NS_FILE_TALK => 'File_talk',
390 NS_MEDIAWIKI => 'MediaWiki',
391 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
392 NS_TEMPLATE => 'Template',
393 NS_TEMPLATE_TALK => 'Template_talk',
394 NS_HELP => 'Help',
395 NS_HELP_TALK => 'Help_talk',
396 NS_CATEGORY => 'Category',
397 NS_CATEGORY_TALK => 'Category_talk',
398 );
399
400 /// @todo UGLY UGLY
401 if ( is_array( $wgExtraNamespaces ) ) {
402 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
403 }
404
405 // These are now the same, always
406 // To determine the user language, use $wgLang->getCode()
407 $wgContLanguageCode = $wgLanguageCode;
408
409 // Easy to forget to falsify $wgShowIPinHeader for static caches.
410 // If file cache or squid cache is on, just disable this (DWIMD).
411 // Do the same for $wgDebugToolbar.
412 if ( $wgUseFileCache || $wgUseSquid ) {
413 $wgShowIPinHeader = false;
414 $wgDebugToolbar = false;
415 }
416
417 // We always output HTML5 since 1.22, overriding these is no longer supported
418 // we set them here for extensions that depend on its value.
419 $wgHtml5 = true;
420 $wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
421 $wgJsMimeType = 'text/javascript';
422
423 if ( !$wgHtml5Version && $wgAllowRdfaAttributes ) {
424 // see http://www.w3.org/TR/rdfa-in-html/#document-conformance
425 if ( $wgMimeType == 'application/xhtml+xml' ) {
426 $wgHtml5Version = 'XHTML+RDFa 1.0';
427 } else {
428 $wgHtml5Version = 'HTML+RDFa 1.0';
429 }
430 }
431
432 // Blacklisted file extensions shouldn't appear on the "allowed" list
433 $wgFileExtensions = array_values( array_diff ( $wgFileExtensions, $wgFileBlacklist ) );
434
435 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
436 // @codingStandardsIgnoreStart Generic.PHP.NoSilencedErrors.Discouraged - No GlobalFunction here yet.
437 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
438 // @codingStandardsIgnoreEnd
439 }
440
441 if ( $wgNewUserLog ) {
442 // Add a new log type
443 $wgLogTypes[] = 'newusers';
444 $wgLogNames['newusers'] = 'newuserlogpage';
445 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
446 $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
447 $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
448 $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
449 $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
450 $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
451 }
452
453 if ( $wgPageLanguageUseDB ) {
454 $wgLogTypes[] = 'pagelang';
455 $wgLogActionsHandlers['pagelang/pagelang'] = 'PageLangLogFormatter';
456 }
457
458 if ( $wgCookieSecure === 'detect' ) {
459 $wgCookieSecure = ( WebRequest::detectProtocol() === 'https' );
460 }
461
462 // Back compatibility for $wgRateLimitLog deprecated with 1.23
463 if ( $wgRateLimitLog && !array_key_exists( 'ratelimit', $wgDebugLogGroups ) ) {
464 $wgDebugLogGroups['ratelimit'] = $wgRateLimitLog;
465 }
466
467 if ( $wgProfileOnly ) {
468 $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
469 $wgDebugLogFile = '';
470 }
471
472 Profiler::instance()->scopedProfileOut( $ps_default );
473
474 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
475 // all the memory from logging SQL queries on maintenance scripts
476 global $wgCommandLineMode;
477 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
478 MWDebug::init();
479 }
480
481 if ( !class_exists( 'AutoLoader' ) ) {
482 require_once "$IP/includes/AutoLoader.php";
483 }
484
485 MWExceptionHandler::installHandler();
486
487 require_once "$IP/includes/libs/normal/UtfNormalUtil.php";
488
489 $ps_default2 = Profiler::instance()->scopedProfileIn( $fname . '-defaults2' );
490
491 if ( defined( 'MW_ENTRY_PHP5' ) ) {
492 wfWarn( 'The ".php5" entry point files are deprecated. Use ".php" instead.' );
493 }
494
495 if ( $wgCanonicalServer === false ) {
496 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
497 }
498
499 // Set server name
500 $serverParts = wfParseUrl( $wgCanonicalServer );
501 if ( $wgServerName !== false ) {
502 wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
503 . 'not customized. Overwriting $wgServerName.' );
504 }
505 $wgServerName = $serverParts['host'];
506 unset( $serverParts );
507
508 // Set defaults for configuration variables
509 // that are derived from the server name by default
510 if ( $wgEmergencyContact === false ) {
511 $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
512 }
513
514 if ( $wgPasswordSender === false ) {
515 $wgPasswordSender = 'apache@' . $wgServerName;
516 }
517
518 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
519 $wgSecureLogin = false;
520 wfWarn( 'Secure login was enabled on a server that only supports '
521 . 'HTTP or HTTPS. Disabling secure login.' );
522 }
523
524 // Now that GlobalFunctions is loaded, set defaults that depend on it.
525 if ( $wgTmpDirectory === false ) {
526 $wgTmpDirectory = wfTempDir();
527 }
528
529 // We don't use counters anymore. Left here for extensions still
530 // expecting this to exist. Should be removed sometime 1.26 or later.
531 $wgDisableCounters = true;
532
533 if ( $wgMainWANCache === false ) {
534 // Setup a WAN cache from $wgMainCacheType with no relayer.
535 // Sites using multiple datacenters can configure a relayer.
536 $wgMainWANCache = 'mediawiki-main-default';
537 $wgWANObjectCaches[$wgMainWANCache] = array(
538 'class' => 'WANObjectCache',
539 'cacheId' => $wgMainCacheType,
540 'pool' => 'mediawiki-main-default',
541 'relayerConfig' => array( 'class' => 'EventRelayerNull' )
542 );
543 }
544
545 Profiler::instance()->scopedProfileOut( $ps_default2 );
546
547 $ps_misc = Profiler::instance()->scopedProfileIn( $fname . '-misc1' );
548
549 // Raise the memory limit if it's too low
550 wfMemoryLimit();
551
552 /**
553 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
554 * that happens whenever you use a date function without the timezone being
555 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
556 */
557 if ( is_null( $wgLocaltimezone ) ) {
558 wfSuppressWarnings();
559 $wgLocaltimezone = date_default_timezone_get();
560 wfRestoreWarnings();
561 }
562
563 date_default_timezone_set( $wgLocaltimezone );
564 if ( is_null( $wgLocalTZoffset ) ) {
565 $wgLocalTZoffset = date( 'Z' ) / 60;
566 }
567
568 if ( !$wgDBerrorLogTZ ) {
569 $wgDBerrorLogTZ = $wgLocaltimezone;
570 }
571
572 // Useful debug output
573 if ( $wgCommandLineMode ) {
574 $wgRequest = new FauxRequest( array() );
575
576 wfDebug( "\n\nStart command line script $self\n" );
577 } else {
578 // Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
579 $wgRequest = new WebRequest;
580
581 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
582
583 if ( $wgDebugPrintHttpHeaders ) {
584 $debug .= "HTTP HEADERS:\n";
585
586 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
587 $debug .= "$name: $value\n";
588 }
589 }
590 wfDebug( $debug );
591 }
592
593 Profiler::instance()->scopedProfileOut( $ps_misc );
594 $ps_memcached = Profiler::instance()->scopedProfileIn( $fname . '-memcached' );
595
596 $wgMemc = wfGetMainCache();
597 $messageMemc = wfGetMessageCacheStorage();
598 $parserMemc = wfGetParserCacheStorage();
599
600 wfDebugLog( 'caches', 'main: ' . get_class( $wgMemc ) .
601 ', message: ' . get_class( $messageMemc ) .
602 ', parser: ' . get_class( $parserMemc ) );
603
604 Profiler::instance()->scopedProfileOut( $ps_memcached );
605
606 // Most of the config is out, some might want to run hooks here.
607 Hooks::run( 'SetupAfterCache' );
608
609 $ps_session = Profiler::instance()->scopedProfileIn( $fname . '-session' );
610
611 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
612 // If session.auto_start is there, we can't touch session name
613 if ( !wfIniGetBool( 'session.auto_start' ) ) {
614 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
615 }
616
617 if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
618 wfSetupSession();
619 }
620 }
621
622 Profiler::instance()->scopedProfileOut( $ps_session );
623 $ps_globals = Profiler::instance()->scopedProfileIn( $fname . '-globals' );
624
625 /**
626 * @var Language $wgContLang
627 */
628 $wgContLang = Language::factory( $wgLanguageCode );
629 $wgContLang->initEncoding();
630 $wgContLang->initContLang();
631
632 // Now that variant lists may be available...
633 $wgRequest->interpolateTitle();
634
635 /**
636 * @var User $wgUser
637 */
638 $wgUser = RequestContext::getMain()->getUser(); // BackCompat
639
640 /**
641 * @var Language $wgLang
642 */
643 $wgLang = new StubUserLang;
644
645 /**
646 * @var OutputPage $wgOut
647 */
648 $wgOut = RequestContext::getMain()->getOutput(); // BackCompat
649
650 /**
651 * @var Parser $wgParser
652 */
653 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
654
655 if ( !is_object( $wgAuth ) ) {
656 $wgAuth = new AuthPlugin;
657 Hooks::run( 'AuthPluginSetup', array( &$wgAuth ) );
658 }
659
660 /**
661 * @var Title $wgTitle
662 */
663 $wgTitle = null;
664
665 /**
666 * @deprecated since 1.24 Use DeferredUpdates::addUpdate instead
667 * @var array
668 */
669 $wgDeferredUpdateList = array();
670
671 Profiler::instance()->scopedProfileOut( $ps_globals );
672 $ps_extensions = Profiler::instance()->scopedProfileIn( $fname . '-extensions' );
673
674 // Extension setup functions for extensions other than skins
675 // Entries should be added to this variable during the inclusion
676 // of the extension file. This allows the extension to perform
677 // any necessary initialisation in the fully initialised environment
678 foreach ( $wgExtensionFunctions as $func ) {
679 // Allow closures in PHP 5.3+
680 if ( is_object( $func ) && $func instanceof Closure ) {
681 $profName = $fname . '-extensions-closure';
682 } elseif ( is_array( $func ) ) {
683 if ( is_object( $func[0] ) ) {
684 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
685 } else {
686 $profName = $fname . '-extensions-' . implode( '::', $func );
687 }
688 } else {
689 $profName = $fname . '-extensions-' . strval( $func );
690 }
691
692 $ps_ext_func = Profiler::instance()->scopedProfileIn( $profName );
693 call_user_func( $func );
694 Profiler::instance()->scopedProfileOut( $ps_ext_func );
695 }
696
697 wfDebug( "Fully initialised\n" );
698 $wgFullyInitialised = true;
699
700 Profiler::instance()->scopedProfileOut( $ps_extensions );
701 Profiler::instance()->scopedProfileOut( $ps_setup );
702