00001 <?php
00010 if( !defined( 'MEDIAWIKI' ) ) {
00011 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
00012 exit( 1 );
00013 }
00014
00015 # The main wiki script and things like database
00016 # conversion and maintenance scripts all share a
00017 # common setup of including lots of classes and
00018 # setting up a few globals.
00019 #
00020
00021 $fname = 'Setup.php';
00022 wfProfileIn( $fname );
00023
00024
00025 if ( !isset( $wgVersion ) ) {
00026 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
00027 die( 1 );
00028 }
00029
00030
00031 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
00032 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
00033
00034 if( $wgArticlePath === false ) {
00035 if( $wgUsePathInfo ) {
00036 $wgArticlePath = "$wgScript/$1";
00037 } else {
00038 $wgArticlePath = "$wgScript?title=$1";
00039 }
00040 }
00041
00042 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
00043 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
00044
00045 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
00046
00047 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
00048 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
00049
00050 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
00051 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
00052 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
00053
00054 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
00055 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
00056
00057 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
00058 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
00059 }
00060
00068 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
00069
00075 $wgNamespaceAliases['Image'] = NS_FILE;
00076 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
00077
00081 if ( !$wgLocalFileRepo ) {
00082 $wgLocalFileRepo = array(
00083 'class' => 'LocalRepo',
00084 'name' => 'local',
00085 'directory' => $wgUploadDirectory,
00086 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
00087 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
00088 'thumbScriptUrl' => $wgThumbnailScriptPath,
00089 'transformVia404' => !$wgGenerateThumbnailOnParse,
00090 'initialCapital' => $wgCapitalLinks,
00091 'deletedDir' => $wgFileStore['deleted']['directory'],
00092 'deletedHashLevels' => $wgFileStore['deleted']['hash']
00093 );
00094 }
00098 if ( $wgUseSharedUploads ) {
00099 if ( $wgSharedUploadDBname ) {
00100 $wgForeignFileRepos[] = array(
00101 'class' => 'ForeignDBRepo',
00102 'name' => 'shared',
00103 'directory' => $wgSharedUploadDirectory,
00104 'url' => $wgSharedUploadPath,
00105 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
00106 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
00107 'transformVia404' => !$wgGenerateThumbnailOnParse,
00108 'dbType' => $wgDBtype,
00109 'dbServer' => $wgDBserver,
00110 'dbUser' => $wgDBuser,
00111 'dbPassword' => $wgDBpassword,
00112 'dbName' => $wgSharedUploadDBname,
00113 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
00114 'tablePrefix' => $wgSharedUploadDBprefix,
00115 'hasSharedCache' => $wgCacheSharedUploads,
00116 'descBaseUrl' => $wgRepositoryBaseUrl,
00117 'fetchDescription' => $wgFetchCommonsDescriptions,
00118 );
00119 } else {
00120 $wgForeignFileRepos[] = array(
00121 'class' => 'FSRepo',
00122 'name' => 'shared',
00123 'directory' => $wgSharedUploadDirectory,
00124 'url' => $wgSharedUploadPath,
00125 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
00126 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
00127 'transformVia404' => !$wgGenerateThumbnailOnParse,
00128 'descBaseUrl' => $wgRepositoryBaseUrl,
00129 'fetchDescription' => $wgFetchCommonsDescriptions,
00130 );
00131 }
00132 }
00133 if ( !class_exists( 'AutoLoader' ) ) {
00134 require_once( "$IP/includes/AutoLoader.php" );
00135 }
00136
00137 wfProfileIn( $fname.'-exception' );
00138 require_once( "$IP/includes/Exception.php" );
00139 wfInstallExceptionHandler();
00140 wfProfileOut( $fname.'-exception' );
00141
00142 wfProfileIn( $fname.'-includes' );
00143 require_once( "$IP/includes/GlobalFunctions.php" );
00144 require_once( "$IP/includes/Hooks.php" );
00145 require_once( "$IP/includes/Namespace.php" );
00146 require_once( "$IP/includes/ProxyTools.php" );
00147 require_once( "$IP/includes/ObjectCache.php" );
00148 require_once( "$IP/includes/ImageFunctions.php" );
00149 require_once( "$IP/includes/StubObject.php" );
00150 wfProfileOut( $fname.'-includes' );
00151 wfProfileIn( $fname.'-misc1' );
00152
00153
00154 $wgIP = false; # Load on demand
00155 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
00156 $wgRequest = new WebRequest;
00157
00158 # Useful debug output
00159 if ( $wgCommandLineMode ) {
00160 wfDebug( "\n\nStart command line script $self\n" );
00161 } elseif ( function_exists( 'getallheaders' ) ) {
00162 wfDebug( "\n\nStart request\n" );
00163 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
00164 $headers = getallheaders();
00165 foreach ($headers as $name => $value) {
00166 wfDebug( "$name: $value\n" );
00167 }
00168 wfDebug( "\n" );
00169 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
00170 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
00171 }
00172
00173 if( $wgRCFilterByAge ) {
00174 ## Trim down $wgRCLinkDays so that it only lists links which are valid
00175 ## as determined by $wgRCMaxAge.
00176 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
00177 sort($wgRCLinkDays);
00178 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
00179 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
00180 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
00181 break;
00182 }
00183 }
00184 }
00185
00186 if ( $wgSkipSkin ) {
00187 $wgSkipSkins[] = $wgSkipSkin;
00188 }
00189
00190 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
00191
00192 if($wgMetaNamespace === FALSE) {
00193 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
00194 }
00195
00196 # These are now the same, always
00197 # To determine the user language, use $wgLang->getCode()
00198 $wgContLanguageCode = $wgLanguageCode;
00199
00200 # Easy to forget to falsify $wgShowIPinHeader for static caches.
00201 # If file cache or squid cache is on, just disable this (DWIMD).
00202 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
00203
00204 wfProfileOut( $fname.'-misc1' );
00205 wfProfileIn( $fname.'-memcached' );
00206
00207 $wgMemc =& wfGetMainCache();
00208 $messageMemc =& wfGetMessageCacheStorage();
00209 $parserMemc =& wfGetParserCacheStorage();
00210
00211 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
00212 "\nMessage cache: " . get_class( $messageMemc ) .
00213 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
00214
00215 wfProfileOut( $fname.'-memcached' );
00216
00217 ## Most of the config is out, some might want to run hooks here.
00218 wfRunHooks( 'SetupAfterCache' );
00219
00220 wfProfileIn( $fname.'-SetupSession' );
00221
00222 # Set default shared prefix
00223 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
00224
00225 if( !$wgCookiePrefix ) {
00226 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
00227 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
00228 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
00229 $wgCookiePrefix = $wgSharedDB;
00230 } elseif ( $wgDBprefix ) {
00231 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
00232 } else {
00233 $wgCookiePrefix = $wgDBname;
00234 }
00235 }
00236 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
00237
00238 # If session.auto_start is there, we can't touch session name
00239 #
00240 if( !wfIniGetBool( 'session.auto_start' ) )
00241 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
00242
00243 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
00244 wfIncrStats( 'request_with_session' );
00245 wfSetupSession();
00246 $wgSessionStarted = true;
00247 } else {
00248 wfIncrStats( 'request_without_session' );
00249 $wgSessionStarted = false;
00250 }
00251
00252 wfProfileOut( $fname.'-SetupSession' );
00253 wfProfileIn( $fname.'-globals' );
00254
00255 $wgContLang = new StubContLang;
00256
00257
00258 $wgRequest->interpolateTitle();
00259
00260 $wgUser = new StubUser;
00261 $wgLang = new StubUserLang;
00262 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
00263 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
00264
00265 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
00266 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
00267
00268 wfProfileOut( $fname.'-globals' );
00269 wfProfileIn( $fname.'-User' );
00270
00271 # Skin setup functions
00272 # Entries can be added to this variable during the inclusion
00273 # of the extension file. Skins can then perform any necessary initialisation.
00274 #
00275 foreach ( $wgSkinExtensionFunctions as $func ) {
00276 call_user_func( $func );
00277 }
00278
00279 if( !is_object( $wgAuth ) ) {
00280 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
00281 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
00282 }
00283
00284 wfProfileOut( $fname.'-User' );
00285
00286 wfProfileIn( $fname.'-misc2' );
00287
00288 $wgDeferredUpdateList = array();
00289 $wgPostCommitUpdateList = array();
00290
00291 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
00292 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
00293 if( $wgAjaxLicensePreview )
00294 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
00295
00296 # Placeholders in case of DB error
00297 $wgTitle = null;
00298 $wgArticle = null;
00299
00300 wfProfileOut( $fname.'-misc2' );
00301 wfProfileIn( $fname.'-extensions' );
00302
00303 # Extension setup functions for extensions other than skins
00304 # Entries should be added to this variable during the inclusion
00305 # of the extension file. This allows the extension to perform
00306 # any necessary initialisation in the fully initialised environment
00307 foreach ( $wgExtensionFunctions as $func ) {
00308 $profName = $fname.'-extensions-'.strval( $func );
00309 wfProfileIn( $profName );
00310 call_user_func( $func );
00311 wfProfileOut( $profName );
00312 }
00313
00314
00315 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
00316 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
00317 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
00318 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
00319
00320 if( !empty($wgNewUserLog) ) {
00321 # Add a new log type
00322 $wgLogTypes[] = 'newusers';
00323 $wgLogNames['newusers'] = 'newuserlogpage';
00324 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
00325 $wgLogActions['newusers/newusers'] = 'newuserlogentry';
00326 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
00327 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
00328 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
00329 }
00330
00331 wfDebug( "Fully initialised\n" );
00332 $wgFullyInitialised = true;
00333 wfProfileOut( $fname.'-extensions' );
00334 wfProfileOut( $fname );