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