Merge "Add ss_active_users in SiteStats::isSane"
[mediawiki.git] / includes / Setup.php
blobd8c9180685546c260fa69817998322abf0ba62c8
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 ) {
48 $wgScript = "$wgScriptPath/index$wgScriptExtension";
50 if ( $wgLoadScript === false ) {
51 $wgLoadScript = "$wgScriptPath/load$wgScriptExtension";
54 if ( $wgArticlePath === false ) {
55 if ( $wgUsePathInfo ) {
56 $wgArticlePath = "$wgScript/$1";
57 } else {
58 $wgArticlePath = "$wgScript?title=$1";
62 if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
63 # 'view' is assumed the default action path everywhere in the code
64 # but is rarely filled in $wgActionPaths
65 $wgActionPaths['view'] = $wgArticlePath;
68 if ( $wgStylePath === false ) {
69 $wgStylePath = "$wgScriptPath/skins";
71 if ( $wgLocalStylePath === false ) {
72 $wgLocalStylePath = "$wgScriptPath/skins";
74 if ( $wgStyleDirectory === false ) {
75 $wgStyleDirectory = "$IP/skins";
77 if ( $wgExtensionAssetsPath === false ) {
78 $wgExtensionAssetsPath = "$wgScriptPath/extensions";
81 if ( $wgLogo === false ) {
82 $wgLogo = "$wgStylePath/common/images/wiki.png";
85 if ( $wgUploadPath === false ) {
86 $wgUploadPath = "$wgScriptPath/images";
88 if ( $wgUploadDirectory === false ) {
89 $wgUploadDirectory = "$IP/images";
91 if ( $wgReadOnlyFile === false ) {
92 $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
94 if ( $wgFileCacheDirectory === false ) {
95 $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
97 if ( $wgDeletedDirectory === false ) {
98 $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
101 if ( isset( $wgFileStore['deleted']['directory'] ) ) {
102 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
105 if ( isset( $wgFooterIcons['copyright'] ) &&
106 isset( $wgFooterIcons['copyright']['copyright'] ) &&
107 $wgFooterIcons['copyright']['copyright'] === array() )
109 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
110 $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
111 } elseif ( $wgRightsIcon || $wgRightsText ) {
112 $wgFooterIcons['copyright']['copyright'] = array(
113 'url' => $wgRightsUrl,
114 'src' => $wgRightsIcon,
115 'alt' => $wgRightsText,
117 } else {
118 unset( $wgFooterIcons['copyright']['copyright'] );
122 if ( isset( $wgFooterIcons['poweredby'] ) &&
123 isset( $wgFooterIcons['poweredby']['mediawiki'] ) &&
124 $wgFooterIcons['poweredby']['mediawiki']['src'] === null )
126 $wgFooterIcons['poweredby']['mediawiki']['src'] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
130 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
131 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
133 * Note that this is the definition of editinterface and it can be granted to
134 * all users if desired.
136 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
139 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
140 * and "File_talk". The old names "Image" and "Image_talk" are
141 * retained as aliases for backwards compatibility.
143 $wgNamespaceAliases['Image'] = NS_FILE;
144 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
147 * Initialise $wgLockManagers to include basic FS version
149 $wgLockManagers[] = array(
150 'name' => 'fsLockManager',
151 'class' => 'FSLockManager',
152 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
154 $wgLockManagers[] = array(
155 'name' => 'nullLockManager',
156 'class' => 'NullLockManager',
160 * Initialise $wgLocalFileRepo from backwards-compatible settings
162 if ( !$wgLocalFileRepo ) {
163 if ( isset( $wgFileStore['deleted']['hash'] ) ) {
164 $deletedHashLevel = $wgFileStore['deleted']['hash'];
165 } else {
166 $deletedHashLevel = $wgHashedUploadDirectory ? 3 : 0;
168 $wgLocalFileRepo = array(
169 'class' => 'LocalRepo',
170 'name' => 'local',
171 'directory' => $wgUploadDirectory,
172 'scriptDirUrl' => $wgScriptPath,
173 'scriptExtension' => $wgScriptExtension,
174 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
175 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
176 'thumbScriptUrl' => $wgThumbnailScriptPath,
177 'transformVia404' => !$wgGenerateThumbnailOnParse,
178 'deletedDir' => $wgDeletedDirectory,
179 'deletedHashLevels' => $deletedHashLevel
183 * Initialise shared repo from backwards-compatible settings
185 if ( $wgUseSharedUploads ) {
186 if ( $wgSharedUploadDBname ) {
187 $wgForeignFileRepos[] = array(
188 'class' => 'ForeignDBRepo',
189 'name' => 'shared',
190 'directory' => $wgSharedUploadDirectory,
191 'url' => $wgSharedUploadPath,
192 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
193 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
194 'transformVia404' => !$wgGenerateThumbnailOnParse,
195 'dbType' => $wgDBtype,
196 'dbServer' => $wgDBserver,
197 'dbUser' => $wgDBuser,
198 'dbPassword' => $wgDBpassword,
199 'dbName' => $wgSharedUploadDBname,
200 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
201 'tablePrefix' => $wgSharedUploadDBprefix,
202 'hasSharedCache' => $wgCacheSharedUploads,
203 'descBaseUrl' => $wgRepositoryBaseUrl,
204 'fetchDescription' => $wgFetchCommonsDescriptions,
206 } else {
207 $wgForeignFileRepos[] = array(
208 'class' => 'FileRepo',
209 'name' => 'shared',
210 'directory' => $wgSharedUploadDirectory,
211 'url' => $wgSharedUploadPath,
212 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
213 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
214 'transformVia404' => !$wgGenerateThumbnailOnParse,
215 'descBaseUrl' => $wgRepositoryBaseUrl,
216 'fetchDescription' => $wgFetchCommonsDescriptions,
220 if ( $wgUseInstantCommons ) {
221 $wgForeignFileRepos[] = array(
222 'class' => 'ForeignAPIRepo',
223 'name' => 'wikimediacommons',
224 'apibase' => WebRequest::detectProtocol() === 'https' ?
225 'https://commons.wikimedia.org/w/api.php' :
226 'http://commons.wikimedia.org/w/api.php',
227 'hashLevels' => 2,
228 'fetchDescription' => true,
229 'descriptionCacheExpiry' => 43200,
230 'apiThumbCacheExpiry' => 86400,
234 * Add on default file backend config for file repos.
235 * FileBackendGroup will handle initializing the backends.
237 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
238 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
240 foreach ( $wgForeignFileRepos as &$repo ) {
241 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
242 $repo['directory'] = $wgUploadDirectory; // b/c
244 if ( !isset( $repo['backend'] ) ) {
245 $repo['backend'] = $repo['name'] . '-backend';
248 unset( $repo ); // no global pollution; destroy reference
250 if ( is_null( $wgEnableAutoRotation ) ) {
251 // Only enable auto-rotation when the bitmap handler can rotate
252 $wgEnableAutoRotation = BitmapHandler::canRotate();
255 if ( $wgRCFilterByAge ) {
256 # # Trim down $wgRCLinkDays so that it only lists links which are valid
257 # # as determined by $wgRCMaxAge.
258 # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
259 sort( $wgRCLinkDays );
260 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
261 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
262 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
263 break;
268 if ( $wgSkipSkin ) {
269 $wgSkipSkins[] = $wgSkipSkin;
272 # Set default shared prefix
273 if ( $wgSharedPrefix === false ) {
274 $wgSharedPrefix = $wgDBprefix;
277 if ( !$wgCookiePrefix ) {
278 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
279 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
280 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
281 $wgCookiePrefix = $wgSharedDB;
282 } elseif ( $wgDBprefix ) {
283 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
284 } else {
285 $wgCookiePrefix = $wgDBname;
288 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
290 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
292 if ( $wgMetaNamespace === false ) {
293 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
297 * Definitions of the NS_ constants are in Defines.php
298 * @private
300 $wgCanonicalNamespaceNames = array(
301 NS_MEDIA => 'Media',
302 NS_SPECIAL => 'Special',
303 NS_TALK => 'Talk',
304 NS_USER => 'User',
305 NS_USER_TALK => 'User_talk',
306 NS_PROJECT => 'Project',
307 NS_PROJECT_TALK => 'Project_talk',
308 NS_FILE => 'File',
309 NS_FILE_TALK => 'File_talk',
310 NS_MEDIAWIKI => 'MediaWiki',
311 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
312 NS_TEMPLATE => 'Template',
313 NS_TEMPLATE_TALK => 'Template_talk',
314 NS_HELP => 'Help',
315 NS_HELP_TALK => 'Help_talk',
316 NS_CATEGORY => 'Category',
317 NS_CATEGORY_TALK => 'Category_talk',
320 /// @todo UGLY UGLY
321 if ( is_array( $wgExtraNamespaces ) ) {
322 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
325 # These are now the same, always
326 # To determine the user language, use $wgLang->getCode()
327 $wgContLanguageCode = $wgLanguageCode;
329 # Easy to forget to falsify $wgShowIPinHeader for static caches.
330 # If file cache or squid cache is on, just disable this (DWIMD).
331 # Do the same for $wgDebugToolbar.
332 if ( $wgUseFileCache || $wgUseSquid ) {
333 $wgShowIPinHeader = false;
334 $wgDebugToolbar = false;
337 # Doesn't make sense to have if disabled.
338 if ( !$wgEnotifMinorEdits ) {
339 $wgHiddenPrefs[] = 'enotifminoredits';
342 # $wgDisabledActions is deprecated as of 1.18
343 foreach ( $wgDisabledActions as $action ) {
344 $wgActions[$action] = false;
347 # We always output HTML5 since 1.22, overriding these is no longer supported
348 # we set them here for extensions that depend on its value.
349 $wgHtml5 = true;
350 $wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
351 $wgJsMimeType = 'text/javascript';
353 if ( !$wgHtml5Version && $wgAllowRdfaAttributes ) {
354 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
355 if ( $wgMimeType == 'application/xhtml+xml' ) {
356 $wgHtml5Version = 'XHTML+RDFa 1.0';
357 } else {
358 $wgHtml5Version = 'HTML+RDFa 1.0';
362 # Blacklisted file extensions shouldn't appear on the "allowed" list
363 $wgFileExtensions = array_values( array_diff ( $wgFileExtensions, $wgFileBlacklist ) );
365 if ( $wgArticleCountMethod === null ) {
366 $wgArticleCountMethod = $wgUseCommaCount ? 'comma' : 'link';
369 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
370 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
373 if ( $wgAjaxUploadDestCheck ) {
374 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
377 if ( $wgNewUserLog ) {
378 # Add a new log type
379 $wgLogTypes[] = 'newusers';
380 $wgLogNames['newusers'] = 'newuserlogpage';
381 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
382 $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
383 $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
384 $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
385 $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
386 $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
389 if ( $wgCookieSecure === 'detect' ) {
390 $wgCookieSecure = ( WebRequest::detectProtocol() === 'https' );
393 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
394 // all the memory from logging SQL queries on maintenance scripts
395 global $wgCommandLineMode;
396 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
397 MWDebug::init();
400 if ( !class_exists( 'AutoLoader' ) ) {
401 require_once "$IP/includes/AutoLoader.php";
404 wfProfileIn( $fname . '-exception' );
405 MWExceptionHandler::installHandler();
406 wfProfileOut( $fname . '-exception' );
408 wfProfileIn( $fname . '-includes' );
409 require_once "$IP/includes/normal/UtfNormalUtil.php";
410 require_once "$IP/includes/GlobalFunctions.php";
411 require_once "$IP/includes/ProxyTools.php";
412 require_once "$IP/includes/normal/UtfNormalDefines.php";
413 wfProfileOut( $fname . '-includes' );
415 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
416 $wgSecureLogin = false;
417 wfWarn( 'Secure login was enabled on a server that only supports HTTP or HTTPS. Disabling secure login.' );
420 # Now that GlobalFunctions is loaded, set defaults that depend
421 # on it.
422 if ( $wgTmpDirectory === false ) {
423 $wgTmpDirectory = wfTempDir();
426 if ( $wgCanonicalServer === false ) {
427 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
430 // Initialize $wgHTCPMulticastRouting from backwards-compatible settings
431 if ( !$wgHTCPMulticastRouting && $wgHTCPMulticastAddress ) {
432 $wgHTCPMulticastRouting = array(
433 '' => array(
434 'host' => $wgHTCPMulticastAddress,
435 'port' => $wgHTCPPort,
440 wfProfileIn( $fname . '-misc1' );
442 # Raise the memory limit if it's too low
443 wfMemoryLimit();
446 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
447 * that happens whenever you use a date function without the timezone being
448 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
450 if ( is_null( $wgLocaltimezone ) ) {
451 wfSuppressWarnings();
452 $wgLocaltimezone = date_default_timezone_get();
453 wfRestoreWarnings();
456 date_default_timezone_set( $wgLocaltimezone );
457 if ( is_null( $wgLocalTZoffset ) ) {
458 $wgLocalTZoffset = date( 'Z' ) / 60;
461 # Useful debug output
462 if ( $wgCommandLineMode ) {
463 $wgRequest = new FauxRequest( array() );
465 wfDebug( "\n\nStart command line script $self\n" );
466 } else {
467 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
468 $wgRequest = new WebRequest;
470 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
472 if ( $wgDebugPrintHttpHeaders ) {
473 $debug .= "HTTP HEADERS:\n";
475 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
476 $debug .= "$name: $value\n";
479 wfDebug( $debug );
482 wfProfileOut( $fname . '-misc1' );
483 wfProfileIn( $fname . '-memcached' );
485 $wgMemc = wfGetMainCache();
486 $messageMemc = wfGetMessageCacheStorage();
487 $parserMemc = wfGetParserCacheStorage();
488 $wgLangConvMemc = wfGetLangConverterCacheStorage();
490 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
491 get_class( $messageMemc ) . '[message] ' .
492 get_class( $parserMemc ) . "[parser]\n" );
494 wfProfileOut( $fname . '-memcached' );
496 # # Most of the config is out, some might want to run hooks here.
497 wfRunHooks( 'SetupAfterCache' );
499 wfProfileIn( $fname . '-session' );
501 # If session.auto_start is there, we can't touch session name
502 if ( !wfIniGetBool( 'session.auto_start' ) ) {
503 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
506 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
507 if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
508 wfSetupSession();
509 $wgSessionStarted = true;
510 } else {
511 $wgSessionStarted = false;
515 wfProfileOut( $fname . '-session' );
516 wfProfileIn( $fname . '-globals' );
518 $wgContLang = Language::factory( $wgLanguageCode );
519 $wgContLang->initEncoding();
520 $wgContLang->initContLang();
522 // Now that variant lists may be available...
523 $wgRequest->interpolateTitle();
524 $wgUser = RequestContext::getMain()->getUser(); # BackCompat
527 * @var $wgLang Language
529 $wgLang = new StubUserLang;
532 * @var OutputPage
534 $wgOut = RequestContext::getMain()->getOutput(); # BackCompat
537 * @var $wgParser Parser
539 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
541 if ( !is_object( $wgAuth ) ) {
542 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
543 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
546 # Placeholders in case of DB error
547 $wgTitle = null;
549 $wgDeferredUpdateList = array();
551 wfProfileOut( $fname . '-globals' );
552 wfProfileIn( $fname . '-extensions' );
554 # Extension setup functions for extensions other than skins
555 # Entries should be added to this variable during the inclusion
556 # of the extension file. This allows the extension to perform
557 # any necessary initialisation in the fully initialised environment
558 foreach ( $wgExtensionFunctions as $func ) {
559 # Allow closures in PHP 5.3+
560 if ( is_object( $func ) && $func instanceof Closure ) {
561 $profName = $fname . '-extensions-closure';
562 } elseif ( is_array( $func ) ) {
563 if ( is_object( $func[0] ) ) {
564 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
565 } else {
566 $profName = $fname . '-extensions-' . implode( '::', $func );
568 } else {
569 $profName = $fname . '-extensions-' . strval( $func );
572 wfProfileIn( $profName );
573 call_user_func( $func );
574 wfProfileOut( $profName );
577 wfDebug( "Fully initialised\n" );
578 $wgFullyInitialised = true;
580 wfProfileOut( $fname . '-extensions' );
581 wfProfileOut( $fname );