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