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