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