Fixed spacing in db/debug/diff/externalstore/objectcache folder
[mediawiki.git] / includes / Setup.php
bloba5979ea5e6303d374443d7b747b74813aff5b6ee
1 <?php
2 /**
3 * Include most things that's need to customize the site.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
23 /**
24 * This file is not a valid entry point, perform no further processing unless
25 * MEDIAWIKI is defined
27 if ( !defined( 'MEDIAWIKI' ) ) {
28 exit( 1 );
31 # The main wiki script and things like database
32 # conversion and maintenance scripts all share a
33 # common setup of including lots of classes and
34 # setting up a few globals.
37 $fname = 'Setup.php';
38 wfProfileIn( $fname );
40 // Check to see if we are at the file scope
41 if ( !isset( $wgVersion ) ) {
42 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
43 die( 1 );
46 // Set various default paths sensibly...
47 if ( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
48 if ( $wgLoadScript === false ) $wgLoadScript = "$wgScriptPath/load$wgScriptExtension";
50 if ( $wgArticlePath === false ) {
51 if ( $wgUsePathInfo ) {
52 $wgArticlePath = "$wgScript/$1";
53 } else {
54 $wgArticlePath = "$wgScript?title=$1";
58 if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
59 # 'view' is assumed the default action path everywhere in the code
60 # but is rarely filled in $wgActionPaths
61 $wgActionPaths['view'] = $wgArticlePath;
64 if ( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
65 if ( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins";
66 if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins";
67 if ( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
69 if ( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
71 if ( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
72 if ( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
73 if ( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
74 if ( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
75 if ( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
77 if ( isset( $wgFileStore['deleted']['directory'] ) ) {
78 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
81 if ( isset( $wgFooterIcons['copyright'] ) &&
82 isset( $wgFooterIcons['copyright']['copyright'] ) &&
83 $wgFooterIcons['copyright']['copyright'] === array() )
85 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
86 $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
87 } elseif ( $wgRightsIcon || $wgRightsText ) {
88 $wgFooterIcons['copyright']['copyright'] = array(
89 'url' => $wgRightsUrl,
90 'src' => $wgRightsIcon,
91 'alt' => $wgRightsText,
93 } else {
94 unset( $wgFooterIcons['copyright']['copyright'] );
98 if ( isset( $wgFooterIcons['poweredby'] ) &&
99 isset( $wgFooterIcons['poweredby']['mediawiki'] ) &&
100 $wgFooterIcons['poweredby']['mediawiki']['src'] === null )
102 $wgFooterIcons['poweredby']['mediawiki']['src'] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
106 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
107 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
109 * Note that this is the definition of editinterface and it can be granted to
110 * all users if desired.
112 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
115 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
116 * and "File_talk". The old names "Image" and "Image_talk" are
117 * retained as aliases for backwards compatibility.
119 $wgNamespaceAliases['Image'] = NS_FILE;
120 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
123 * Initialise $wgLockManagers to include basic FS version
125 $wgLockManagers[] = array(
126 'name' => 'fsLockManager',
127 'class' => 'FSLockManager',
128 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
130 $wgLockManagers[] = array(
131 'name' => 'nullLockManager',
132 'class' => 'NullLockManager',
136 * Initialise $wgLocalFileRepo from backwards-compatible settings
138 if ( !$wgLocalFileRepo ) {
139 if ( isset( $wgFileStore['deleted']['hash'] ) ) {
140 $deletedHashLevel = $wgFileStore['deleted']['hash'];
141 } else {
142 $deletedHashLevel = $wgHashedUploadDirectory ? 3 : 0;
144 $wgLocalFileRepo = array(
145 'class' => 'LocalRepo',
146 'name' => 'local',
147 'directory' => $wgUploadDirectory,
148 'scriptDirUrl' => $wgScriptPath,
149 'scriptExtension' => $wgScriptExtension,
150 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
151 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
152 'thumbScriptUrl' => $wgThumbnailScriptPath,
153 'transformVia404' => !$wgGenerateThumbnailOnParse,
154 'deletedDir' => $wgDeletedDirectory,
155 'deletedHashLevels' => $deletedHashLevel
159 * Initialise shared repo from backwards-compatible settings
161 if ( $wgUseSharedUploads ) {
162 if ( $wgSharedUploadDBname ) {
163 $wgForeignFileRepos[] = array(
164 'class' => 'ForeignDBRepo',
165 'name' => 'shared',
166 'directory' => $wgSharedUploadDirectory,
167 'url' => $wgSharedUploadPath,
168 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
169 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
170 'transformVia404' => !$wgGenerateThumbnailOnParse,
171 'dbType' => $wgDBtype,
172 'dbServer' => $wgDBserver,
173 'dbUser' => $wgDBuser,
174 'dbPassword' => $wgDBpassword,
175 'dbName' => $wgSharedUploadDBname,
176 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
177 'tablePrefix' => $wgSharedUploadDBprefix,
178 'hasSharedCache' => $wgCacheSharedUploads,
179 'descBaseUrl' => $wgRepositoryBaseUrl,
180 'fetchDescription' => $wgFetchCommonsDescriptions,
182 } else {
183 $wgForeignFileRepos[] = array(
184 'class' => 'FileRepo',
185 'name' => 'shared',
186 'directory' => $wgSharedUploadDirectory,
187 'url' => $wgSharedUploadPath,
188 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
189 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
190 'transformVia404' => !$wgGenerateThumbnailOnParse,
191 'descBaseUrl' => $wgRepositoryBaseUrl,
192 'fetchDescription' => $wgFetchCommonsDescriptions,
196 if ( $wgUseInstantCommons ) {
197 $wgForeignFileRepos[] = array(
198 'class' => 'ForeignAPIRepo',
199 'name' => 'wikimediacommons',
200 'apibase' => WebRequest::detectProtocol() === 'https' ?
201 'https://commons.wikimedia.org/w/api.php' :
202 'http://commons.wikimedia.org/w/api.php',
203 'hashLevels' => 2,
204 'fetchDescription' => true,
205 'descriptionCacheExpiry' => 43200,
206 'apiThumbCacheExpiry' => 86400,
210 * Add on default file backend config for file repos.
211 * FileBackendGroup will handle initializing the backends.
213 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
214 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
216 foreach ( $wgForeignFileRepos as &$repo ) {
217 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
218 $repo['directory'] = $wgUploadDirectory; // b/c
220 if ( !isset( $repo['backend'] ) ) {
221 $repo['backend'] = $repo['name'] . '-backend';
224 unset( $repo ); // no global pollution; destroy reference
226 if ( is_null( $wgEnableAutoRotation ) ) {
227 // Only enable auto-rotation when the bitmap handler can rotate
228 $wgEnableAutoRotation = BitmapHandler::canRotate();
231 if ( $wgRCFilterByAge ) {
232 # # Trim down $wgRCLinkDays so that it only lists links which are valid
233 # # as determined by $wgRCMaxAge.
234 # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
235 sort( $wgRCLinkDays );
236 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
237 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
238 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
239 break;
244 if ( $wgSkipSkin ) {
245 $wgSkipSkins[] = $wgSkipSkin;
248 # Set default shared prefix
249 if ( $wgSharedPrefix === false ) {
250 $wgSharedPrefix = $wgDBprefix;
253 if ( !$wgCookiePrefix ) {
254 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
255 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
256 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
257 $wgCookiePrefix = $wgSharedDB;
258 } elseif ( $wgDBprefix ) {
259 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
260 } else {
261 $wgCookiePrefix = $wgDBname;
264 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
266 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
268 if ( $wgMetaNamespace === false ) {
269 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
273 * Definitions of the NS_ constants are in Defines.php
274 * @private
276 $wgCanonicalNamespaceNames = array(
277 NS_MEDIA => 'Media',
278 NS_SPECIAL => 'Special',
279 NS_TALK => 'Talk',
280 NS_USER => 'User',
281 NS_USER_TALK => 'User_talk',
282 NS_PROJECT => 'Project',
283 NS_PROJECT_TALK => 'Project_talk',
284 NS_FILE => 'File',
285 NS_FILE_TALK => 'File_talk',
286 NS_MEDIAWIKI => 'MediaWiki',
287 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
288 NS_TEMPLATE => 'Template',
289 NS_TEMPLATE_TALK => 'Template_talk',
290 NS_HELP => 'Help',
291 NS_HELP_TALK => 'Help_talk',
292 NS_CATEGORY => 'Category',
293 NS_CATEGORY_TALK => 'Category_talk',
296 /// @todo UGLY UGLY
297 if( is_array( $wgExtraNamespaces ) ) {
298 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
301 # These are now the same, always
302 # To determine the user language, use $wgLang->getCode()
303 $wgContLanguageCode = $wgLanguageCode;
305 # Easy to forget to falsify $wgShowIPinHeader for static caches.
306 # If file cache or squid cache is on, just disable this (DWIMD).
307 # Do the same for $wgDebugToolbar.
308 if ( $wgUseFileCache || $wgUseSquid ) {
309 $wgShowIPinHeader = false;
310 $wgDebugToolbar = false;
313 # Doesn't make sense to have if disabled.
314 if ( !$wgEnotifMinorEdits ) {
315 $wgHiddenPrefs[] = 'enotifminoredits';
318 # $wgDisabledActions is deprecated as of 1.18
319 foreach( $wgDisabledActions as $action ) {
320 $wgActions[$action] = false;
323 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
324 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
325 if ( $wgMimeType == 'application/xhtml+xml' ) {
326 $wgHtml5Version = 'XHTML+RDFa 1.0';
327 } else {
328 $wgHtml5Version = 'HTML+RDFa 1.0';
332 # Blacklisted file extensions shouldn't appear on the "allowed" list
333 $wgFileExtensions = array_values( array_diff ( $wgFileExtensions, $wgFileBlacklist ) );
335 if ( $wgArticleCountMethod === null ) {
336 $wgArticleCountMethod = $wgUseCommaCount ? 'comma' : 'link';
339 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
340 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
343 if ( $wgAjaxUploadDestCheck ) {
344 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
347 if ( $wgNewUserLog ) {
348 # Add a new log type
349 $wgLogTypes[] = 'newusers';
350 $wgLogNames['newusers'] = 'newuserlogpage';
351 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
352 $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
353 $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
354 $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
355 $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
356 $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
359 if ( $wgCookieSecure === 'detect' ) {
360 $wgCookieSecure = ( WebRequest::detectProtocol() === 'https' );
363 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
364 // all the memory from logging SQL queries on maintenance scripts
365 global $wgCommandLineMode;
366 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
367 MWDebug::init();
370 if ( !defined( 'MW_COMPILED' ) ) {
371 if ( !MWInit::classExists( 'AutoLoader' ) ) {
372 require_once( "$IP/includes/AutoLoader.php" );
375 wfProfileIn( $fname . '-exception' );
376 MWExceptionHandler::installHandler();
377 wfProfileOut( $fname . '-exception' );
379 wfProfileIn( $fname . '-includes' );
380 require_once( "$IP/includes/normal/UtfNormalUtil.php" );
381 require_once( "$IP/includes/GlobalFunctions.php" );
382 require_once( "$IP/includes/ProxyTools.php" );
383 require_once( "$IP/includes/normal/UtfNormalDefines.php" );
384 wfProfileOut( $fname . '-includes' );
387 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
388 $wgSecureLogin = false;
389 wfWarn( 'Secure login was enabled on a server that only supports HTTP or HTTPS. Disabling secure login.' );
392 # Now that GlobalFunctions is loaded, set defaults that depend
393 # on it.
394 if ( $wgTmpDirectory === false ) {
395 $wgTmpDirectory = wfTempDir();
398 if ( $wgCanonicalServer === false ) {
399 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
402 // Initialize $wgHTCPMulticastRouting from backwards-compatible settings
403 if ( !$wgHTCPMulticastRouting && $wgHTCPMulticastAddress ) {
404 $wgHTCPMulticastRouting = array(
405 '' => array(
406 'host' => $wgHTCPMulticastAddress,
407 'port' => $wgHTCPPort,
412 wfProfileIn( $fname . '-misc1' );
414 # Raise the memory limit if it's too low
415 wfMemoryLimit();
418 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
419 * that happens whenever you use a date function without the timezone being
420 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
422 if ( is_null( $wgLocaltimezone ) ) {
423 wfSuppressWarnings();
424 $wgLocaltimezone = date_default_timezone_get();
425 wfRestoreWarnings();
428 date_default_timezone_set( $wgLocaltimezone );
429 if( is_null( $wgLocalTZoffset ) ) {
430 $wgLocalTZoffset = date( 'Z' ) / 60;
433 # Useful debug output
434 if ( $wgCommandLineMode ) {
435 $wgRequest = new FauxRequest( array() );
437 wfDebug( "\n\nStart command line script $self\n" );
438 } else {
439 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
440 $wgRequest = new WebRequest;
442 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
444 if ( $wgDebugPrintHttpHeaders ) {
445 $debug .= "HTTP HEADERS:\n";
447 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
448 $debug .= "$name: $value\n";
451 wfDebug( $debug );
454 wfProfileOut( $fname . '-misc1' );
455 wfProfileIn( $fname . '-memcached' );
457 $wgMemc = wfGetMainCache();
458 $messageMemc = wfGetMessageCacheStorage();
459 $parserMemc = wfGetParserCacheStorage();
460 $wgLangConvMemc = wfGetLangConverterCacheStorage();
462 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
463 get_class( $messageMemc ) . '[message] ' .
464 get_class( $parserMemc ) . "[parser]\n" );
466 wfProfileOut( $fname . '-memcached' );
468 # # Most of the config is out, some might want to run hooks here.
469 wfRunHooks( 'SetupAfterCache' );
471 wfProfileIn( $fname . '-session' );
473 # If session.auto_start is there, we can't touch session name
474 if ( !wfIniGetBool( 'session.auto_start' ) ) {
475 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
478 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
479 if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
480 wfSetupSession();
481 $wgSessionStarted = true;
482 } else {
483 $wgSessionStarted = false;
487 wfProfileOut( $fname . '-session' );
488 wfProfileIn( $fname . '-globals' );
490 $wgContLang = Language::factory( $wgLanguageCode );
491 $wgContLang->initEncoding();
492 $wgContLang->initContLang();
494 // Now that variant lists may be available...
495 $wgRequest->interpolateTitle();
496 $wgUser = RequestContext::getMain()->getUser(); # BackCompat
499 * @var $wgLang Language
501 $wgLang = new StubUserLang;
504 * @var OutputPage
506 $wgOut = RequestContext::getMain()->getOutput(); # BackCompat
509 * @var $wgParser Parser
511 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
513 if ( !is_object( $wgAuth ) ) {
514 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
515 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
518 # Placeholders in case of DB error
519 $wgTitle = null;
521 $wgDeferredUpdateList = array();
523 wfProfileOut( $fname . '-globals' );
524 wfProfileIn( $fname . '-extensions' );
526 # Extension setup functions for extensions other than skins
527 # Entries should be added to this variable during the inclusion
528 # of the extension file. This allows the extension to perform
529 # any necessary initialisation in the fully initialised environment
530 foreach ( $wgExtensionFunctions as $func ) {
531 # Allow closures in PHP 5.3+
532 if ( is_object( $func ) && $func instanceof Closure ) {
533 $profName = $fname . '-extensions-closure';
534 } elseif ( is_array( $func ) ) {
535 if ( is_object( $func[0] ) )
536 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
537 else
538 $profName = $fname . '-extensions-' . implode( '::', $func );
539 } else {
540 $profName = $fname . '-extensions-' . strval( $func );
543 wfProfileIn( $profName );
544 call_user_func( $func );
545 wfProfileOut( $profName );
548 wfDebug( "Fully initialised\n" );
549 $wgFullyInitialised = true;
551 wfProfileOut( $fname . '-extensions' );
552 wfProfileOut( $fname );