MediaWiki  REL1_22
Setup.php
Go to the documentation of this file.
00001 <?php
00027 if ( !defined( 'MEDIAWIKI' ) ) {
00028     exit( 1 );
00029 }
00030 
00031 # The main wiki script and things like database
00032 # conversion and maintenance scripts all share a
00033 # common setup of including lots of classes and
00034 # setting up a few globals.
00035 #
00036 
00037 $fname = 'Setup.php';
00038 wfProfileIn( $fname );
00039 
00040 // Check to see if we are at the file scope
00041 if ( !isset( $wgVersion ) ) {
00042     echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
00043     die( 1 );
00044 }
00045 
00046 // Set various default paths sensibly...
00047 if ( $wgScript === false ) {
00048     $wgScript = "$wgScriptPath/index$wgScriptExtension";
00049 }
00050 if ( $wgLoadScript === false ) {
00051     $wgLoadScript = "$wgScriptPath/load$wgScriptExtension";
00052 }
00053 
00054 if ( $wgArticlePath === false ) {
00055     if ( $wgUsePathInfo ) {
00056         $wgArticlePath = "$wgScript/$1";
00057     } else {
00058         $wgArticlePath = "$wgScript?title=$1";
00059     }
00060 }
00061 
00062 if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
00063     # 'view' is assumed the default action path everywhere in the code
00064     # but is rarely filled in $wgActionPaths
00065     $wgActionPaths['view'] = $wgArticlePath;
00066 }
00067 
00068 if ( $wgStylePath === false ) {
00069     $wgStylePath = "$wgScriptPath/skins";
00070 }
00071 if ( $wgLocalStylePath === false ) {
00072     $wgLocalStylePath = "$wgScriptPath/skins";
00073 }
00074 if ( $wgStyleDirectory === false ) {
00075     $wgStyleDirectory = "$IP/skins";
00076 }
00077 if ( $wgExtensionAssetsPath === false ) {
00078     $wgExtensionAssetsPath = "$wgScriptPath/extensions";
00079 }
00080 
00081 if ( $wgLogo === false ) {
00082     $wgLogo = "$wgStylePath/common/images/wiki.png";
00083 }
00084 
00085 if ( $wgUploadPath === false ) {
00086     $wgUploadPath = "$wgScriptPath/images";
00087 }
00088 if ( $wgUploadDirectory === false ) {
00089     $wgUploadDirectory = "$IP/images";
00090 }
00091 if ( $wgReadOnlyFile === false ) {
00092     $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
00093 }
00094 if ( $wgFileCacheDirectory === false ) {
00095     $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
00096 }
00097 if ( $wgDeletedDirectory === false ) {
00098     $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
00099 }
00100 
00101 if ( isset( $wgFileStore['deleted']['directory'] ) ) {
00102     $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
00103 }
00104 
00105 if ( isset( $wgFooterIcons['copyright'] ) &&
00106     isset( $wgFooterIcons['copyright']['copyright'] ) &&
00107     $wgFooterIcons['copyright']['copyright'] === array() )
00108 {
00109     if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
00110         $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
00111     } elseif ( $wgRightsIcon || $wgRightsText ) {
00112         $wgFooterIcons['copyright']['copyright'] = array(
00113             'url' => $wgRightsUrl,
00114             'src' => $wgRightsIcon,
00115             'alt' => $wgRightsText,
00116         );
00117     } else {
00118         unset( $wgFooterIcons['copyright']['copyright'] );
00119     }
00120 }
00121 
00122 if ( isset( $wgFooterIcons['poweredby'] ) &&
00123     isset( $wgFooterIcons['poweredby']['mediawiki'] ) &&
00124     $wgFooterIcons['poweredby']['mediawiki']['src'] === null )
00125 {
00126     $wgFooterIcons['poweredby']['mediawiki']['src'] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
00127 }
00128 
00136 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
00137 
00143 $wgNamespaceAliases['Image'] = NS_FILE;
00144 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
00145 
00149 $wgLockManagers[] = array(
00150     'name' => 'fsLockManager',
00151     'class' => 'FSLockManager',
00152     'lockDirectory' => "{$wgUploadDirectory}/lockdir",
00153 );
00154 $wgLockManagers[] = array(
00155     'name' => 'nullLockManager',
00156     'class' => 'NullLockManager',
00157 );
00158 
00162 if ( !$wgLocalFileRepo ) {
00163     if ( isset( $wgFileStore['deleted']['hash'] ) ) {
00164         $deletedHashLevel = $wgFileStore['deleted']['hash'];
00165     } else {
00166         $deletedHashLevel = $wgHashedUploadDirectory ? 3 : 0;
00167     }
00168     $wgLocalFileRepo = array(
00169         'class' => 'LocalRepo',
00170         'name' => 'local',
00171         'directory' => $wgUploadDirectory,
00172         'scriptDirUrl' => $wgScriptPath,
00173         'scriptExtension' => $wgScriptExtension,
00174         'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
00175         'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
00176         'thumbScriptUrl' => $wgThumbnailScriptPath,
00177         'transformVia404' => !$wgGenerateThumbnailOnParse,
00178         'deletedDir' => $wgDeletedDirectory,
00179         'deletedHashLevels' => $deletedHashLevel
00180     );
00181 }
00185 if ( $wgUseSharedUploads ) {
00186     if ( $wgSharedUploadDBname ) {
00187         $wgForeignFileRepos[] = array(
00188             'class' => 'ForeignDBRepo',
00189             'name' => 'shared',
00190             'directory' => $wgSharedUploadDirectory,
00191             'url' => $wgSharedUploadPath,
00192             'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
00193             'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
00194             'transformVia404' => !$wgGenerateThumbnailOnParse,
00195             'dbType' => $wgDBtype,
00196             'dbServer' => $wgDBserver,
00197             'dbUser' => $wgDBuser,
00198             'dbPassword' => $wgDBpassword,
00199             'dbName' => $wgSharedUploadDBname,
00200             'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
00201             'tablePrefix' => $wgSharedUploadDBprefix,
00202             'hasSharedCache' => $wgCacheSharedUploads,
00203             'descBaseUrl' => $wgRepositoryBaseUrl,
00204             'fetchDescription' => $wgFetchCommonsDescriptions,
00205         );
00206     } else {
00207         $wgForeignFileRepos[] = array(
00208             'class' => 'FileRepo',
00209             'name' => 'shared',
00210             'directory' => $wgSharedUploadDirectory,
00211             'url' => $wgSharedUploadPath,
00212             'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
00213             'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
00214             'transformVia404' => !$wgGenerateThumbnailOnParse,
00215             'descBaseUrl' => $wgRepositoryBaseUrl,
00216             'fetchDescription' => $wgFetchCommonsDescriptions,
00217         );
00218     }
00219 }
00220 if ( $wgUseInstantCommons ) {
00221     $wgForeignFileRepos[] = array(
00222         'class' => 'ForeignAPIRepo',
00223         'name' => 'wikimediacommons',
00224         'apibase' => WebRequest::detectProtocol() === 'https' ?
00225             'https://commons.wikimedia.org/w/api.php' :
00226             'http://commons.wikimedia.org/w/api.php',
00227         'hashLevels' => 2,
00228         'fetchDescription' => true,
00229         'descriptionCacheExpiry' => 43200,
00230         'apiThumbCacheExpiry' => 86400,
00231     );
00232 }
00233 /*
00234  * Add on default file backend config for file repos.
00235  * FileBackendGroup will handle initializing the backends.
00236  */
00237 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
00238     $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
00239 }
00240 foreach ( $wgForeignFileRepos as &$repo ) {
00241     if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
00242         $repo['directory'] = $wgUploadDirectory; // b/c
00243     }
00244     if ( !isset( $repo['backend'] ) ) {
00245         $repo['backend'] = $repo['name'] . '-backend';
00246     }
00247 }
00248 unset( $repo ); // no global pollution; destroy reference
00249 
00250 if ( is_null( $wgEnableAutoRotation ) ) {
00251     // Only enable auto-rotation when the bitmap handler can rotate
00252     $wgEnableAutoRotation = BitmapHandler::canRotate();
00253 }
00254 
00255 if ( $wgRCFilterByAge ) {
00256     # # Trim down $wgRCLinkDays so that it only lists links which are valid
00257     # # as determined by $wgRCMaxAge.
00258     # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
00259     sort( $wgRCLinkDays );
00260     for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
00261         if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
00262             $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
00263             break;
00264         }
00265     }
00266 }
00267 
00268 if ( $wgSkipSkin ) {
00269     $wgSkipSkins[] = $wgSkipSkin;
00270 }
00271 
00272 # Set default shared prefix
00273 if ( $wgSharedPrefix === false ) {
00274     $wgSharedPrefix = $wgDBprefix;
00275 }
00276 
00277 if ( !$wgCookiePrefix ) {
00278     if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
00279         $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
00280     } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
00281         $wgCookiePrefix = $wgSharedDB;
00282     } elseif ( $wgDBprefix ) {
00283         $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
00284     } else {
00285         $wgCookiePrefix = $wgDBname;
00286     }
00287 }
00288 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
00289 
00290 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
00291 
00292 if ( $wgMetaNamespace === false ) {
00293     $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
00294 }
00295 
00296 
00297 // Default value is either the suhosin limit or -1 for unlimited
00298 if ( $wgResourceLoaderMaxQueryLength === false ) {
00299     $maxValueLength = ini_get( 'suhosin.get.max_value_length' );
00300     $wgResourceLoaderMaxQueryLength = $maxValueLength > 0 ? $maxValueLength : -1;
00301 }
00302 
00307 $wgCanonicalNamespaceNames = array(
00308     NS_MEDIA            => 'Media',
00309     NS_SPECIAL          => 'Special',
00310     NS_TALK             => 'Talk',
00311     NS_USER             => 'User',
00312     NS_USER_TALK        => 'User_talk',
00313     NS_PROJECT          => 'Project',
00314     NS_PROJECT_TALK     => 'Project_talk',
00315     NS_FILE             => 'File',
00316     NS_FILE_TALK        => 'File_talk',
00317     NS_MEDIAWIKI        => 'MediaWiki',
00318     NS_MEDIAWIKI_TALK   => 'MediaWiki_talk',
00319     NS_TEMPLATE         => 'Template',
00320     NS_TEMPLATE_TALK    => 'Template_talk',
00321     NS_HELP             => 'Help',
00322     NS_HELP_TALK        => 'Help_talk',
00323     NS_CATEGORY         => 'Category',
00324     NS_CATEGORY_TALK    => 'Category_talk',
00325 );
00326 
00328 if ( is_array( $wgExtraNamespaces ) ) {
00329     $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
00330 }
00331 
00332 # These are now the same, always
00333 # To determine the user language, use $wgLang->getCode()
00334 $wgContLanguageCode = $wgLanguageCode;
00335 
00336 # Easy to forget to falsify $wgShowIPinHeader for static caches.
00337 # If file cache or squid cache is on, just disable this (DWIMD).
00338 # Do the same for $wgDebugToolbar.
00339 if ( $wgUseFileCache || $wgUseSquid ) {
00340     $wgShowIPinHeader = false;
00341     $wgDebugToolbar = false;
00342 }
00343 
00344 # Doesn't make sense to have if disabled.
00345 if ( !$wgEnotifMinorEdits ) {
00346     $wgHiddenPrefs[] = 'enotifminoredits';
00347 }
00348 
00349 # $wgDisabledActions is deprecated as of 1.18
00350 foreach ( $wgDisabledActions as $action ) {
00351     $wgActions[$action] = false;
00352 }
00353 
00354 # We always output HTML5 since 1.22, overriding these is no longer supported
00355 # we set them here for extensions that depend on its value.
00356 $wgHtml5 = true;
00357 $wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
00358 $wgJsMimeType = 'text/javascript';
00359 
00360 if ( !$wgHtml5Version && $wgAllowRdfaAttributes ) {
00361     # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
00362     if ( $wgMimeType == 'application/xhtml+xml' ) {
00363         $wgHtml5Version = 'XHTML+RDFa 1.0';
00364     } else {
00365         $wgHtml5Version = 'HTML+RDFa 1.0';
00366     }
00367 }
00368 
00369 # Blacklisted file extensions shouldn't appear on the "allowed" list
00370 $wgFileExtensions = array_values( array_diff ( $wgFileExtensions, $wgFileBlacklist ) );
00371 
00372 if ( $wgArticleCountMethod === null ) {
00373     $wgArticleCountMethod = $wgUseCommaCount ? 'comma' : 'link';
00374 }
00375 
00376 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
00377     $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
00378 }
00379 
00380 if ( $wgNewUserLog ) {
00381     # Add a new log type
00382     $wgLogTypes[] = 'newusers';
00383     $wgLogNames['newusers'] = 'newuserlogpage';
00384     $wgLogHeaders['newusers'] = 'newuserlogpagetext';
00385     $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
00386     $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
00387     $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
00388     $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
00389     $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
00390 }
00391 
00392 if ( $wgCookieSecure === 'detect' ) {
00393     $wgCookieSecure = ( WebRequest::detectProtocol() === 'https' );
00394 }
00395 
00396 if ( $wgRC2UDPAddress ) {
00397     $wgRCFeeds['default'] = array(
00398         'formatter' => 'IRCColourfulRCFeedFormatter',
00399         'uri' => "udp://$wgRC2UDPAddress:$wgRC2UDPPort/$wgRC2UDPPrefix",
00400         'add_interwiki_prefix' => &$wgRC2UDPInterwikiPrefix,
00401         'omit_bots' => &$wgRC2UDPOmitBots,
00402     );
00403 }
00404 
00405 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
00406 // all the memory from logging SQL queries on maintenance scripts
00407 global $wgCommandLineMode;
00408 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
00409     MWDebug::init();
00410 }
00411 
00412 if ( !class_exists( 'AutoLoader' ) ) {
00413     require_once "$IP/includes/AutoLoader.php";
00414 }
00415 
00416 wfProfileIn( $fname . '-exception' );
00417 MWExceptionHandler::installHandler();
00418 wfProfileOut( $fname . '-exception' );
00419 
00420 wfProfileIn( $fname . '-includes' );
00421 require_once "$IP/includes/normal/UtfNormalUtil.php";
00422 require_once "$IP/includes/GlobalFunctions.php";
00423 require_once "$IP/includes/ProxyTools.php";
00424 require_once "$IP/includes/normal/UtfNormalDefines.php";
00425 wfProfileOut( $fname . '-includes' );
00426 
00427 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
00428     $wgSecureLogin = false;
00429     wfWarn( 'Secure login was enabled on a server that only supports HTTP or HTTPS. Disabling secure login.' );
00430 }
00431 
00432 # Now that GlobalFunctions is loaded, set defaults that depend
00433 # on it.
00434 if ( $wgTmpDirectory === false ) {
00435     $wgTmpDirectory = wfTempDir();
00436 }
00437 
00438 if ( $wgCanonicalServer === false ) {
00439     $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
00440 }
00441 
00442 // $wgHTCPMulticastRouting got renamed to $wgHTCPRouting in MediaWiki 1.22
00443 // ensure back compatibility.
00444 if ( !$wgHTCPRouting && $wgHTCPMulticastRouting ) {
00445     $wgHTCPRouting = $wgHTCPMulticastRouting;
00446 }
00447 
00448 // Initialize $wgHTCPRouting from backwards-compatible settings that
00449 // comes from pre 1.20 version.
00450 if ( !$wgHTCPRouting && $wgHTCPMulticastAddress ) {
00451     $wgHTCPRouting = array(
00452         '' => array(
00453             'host' => $wgHTCPMulticastAddress,
00454             'port' => $wgHTCPPort,
00455         )
00456     );
00457 }
00458 
00459 wfProfileIn( $fname . '-misc1' );
00460 
00461 # Raise the memory limit if it's too low
00462 wfMemoryLimit();
00463 
00469 if ( is_null( $wgLocaltimezone ) ) {
00470     wfSuppressWarnings();
00471     $wgLocaltimezone = date_default_timezone_get();
00472     wfRestoreWarnings();
00473 }
00474 
00475 date_default_timezone_set( $wgLocaltimezone );
00476 if ( is_null( $wgLocalTZoffset ) ) {
00477     $wgLocalTZoffset = date( 'Z' ) / 60;
00478 }
00479 
00480 # Useful debug output
00481 if ( $wgCommandLineMode ) {
00482     $wgRequest = new FauxRequest( array() );
00483 
00484     wfDebug( "\n\nStart command line script $self\n" );
00485 } else {
00486     # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
00487     $wgRequest = new WebRequest;
00488 
00489     $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
00490 
00491     if ( $wgDebugPrintHttpHeaders ) {
00492         $debug .= "HTTP HEADERS:\n";
00493 
00494         foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
00495             $debug .= "$name: $value\n";
00496         }
00497     }
00498     wfDebug( $debug );
00499 }
00500 
00501 wfProfileOut( $fname . '-misc1' );
00502 wfProfileIn( $fname . '-memcached' );
00503 
00504 $wgMemc = wfGetMainCache();
00505 $messageMemc = wfGetMessageCacheStorage();
00506 $parserMemc = wfGetParserCacheStorage();
00507 $wgLangConvMemc = wfGetLangConverterCacheStorage();
00508 
00509 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
00510     get_class( $messageMemc ) . '[message] ' .
00511     get_class( $parserMemc ) . "[parser]\n" );
00512 
00513 wfProfileOut( $fname . '-memcached' );
00514 
00515 # # Most of the config is out, some might want to run hooks here.
00516 wfRunHooks( 'SetupAfterCache' );
00517 
00518 wfProfileIn( $fname . '-session' );
00519 
00520 # If session.auto_start is there, we can't touch session name
00521 if ( !wfIniGetBool( 'session.auto_start' ) ) {
00522     session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
00523 }
00524 
00525 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
00526     if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
00527         wfSetupSession();
00528         $wgSessionStarted = true;
00529     } else {
00530         $wgSessionStarted = false;
00531     }
00532 }
00533 
00534 wfProfileOut( $fname . '-session' );
00535 wfProfileIn( $fname . '-globals' );
00536 
00537 $wgContLang = Language::factory( $wgLanguageCode );
00538 $wgContLang->initEncoding();
00539 $wgContLang->initContLang();
00540 
00541 // Now that variant lists may be available...
00542 $wgRequest->interpolateTitle();
00543 $wgUser = RequestContext::getMain()->getUser(); # BackCompat
00544 
00548 $wgLang = new StubUserLang;
00549 
00553 $wgOut = RequestContext::getMain()->getOutput(); # BackCompat
00554 
00558 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
00559 
00560 if ( !is_object( $wgAuth ) ) {
00561     $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
00562     wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
00563 }
00564 
00565 # Placeholders in case of DB error
00566 $wgTitle = null;
00567 
00568 $wgDeferredUpdateList = array();
00569 
00570 wfProfileOut( $fname . '-globals' );
00571 wfProfileIn( $fname . '-extensions' );
00572 
00573 # Extension setup functions for extensions other than skins
00574 # Entries should be added to this variable during the inclusion
00575 # of the extension file. This allows the extension to perform
00576 # any necessary initialisation in the fully initialised environment
00577 foreach ( $wgExtensionFunctions as $func ) {
00578     # Allow closures in PHP 5.3+
00579     if ( is_object( $func ) && $func instanceof Closure ) {
00580         $profName = $fname . '-extensions-closure';
00581     } elseif ( is_array( $func ) ) {
00582         if ( is_object( $func[0] ) ) {
00583             $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
00584         } else {
00585             $profName = $fname . '-extensions-' . implode( '::', $func );
00586         }
00587     } else {
00588         $profName = $fname . '-extensions-' . strval( $func );
00589     }
00590 
00591     wfProfileIn( $profName );
00592     call_user_func( $func );
00593     wfProfileOut( $profName );
00594 }
00595 
00596 wfDebug( "Fully initialised\n" );
00597 $wgFullyInitialised = true;
00598 
00599 wfProfileOut( $fname . '-extensions' );
00600 wfProfileOut( $fname );