00001 <?php
00010 if( !defined( 'MEDIAWIKI' ) ) {
00011 exit( 1 );
00012 }
00013
00014 # The main wiki script and things like database
00015 # conversion and maintenance scripts all share a
00016 # common setup of including lots of classes and
00017 # setting up a few globals.
00018 #
00019
00020 $fname = 'Setup.php';
00021 wfProfileIn( $fname );
00022
00023
00024 if ( !isset( $wgVersion ) ) {
00025 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
00026 die( 1 );
00027 }
00028
00029
00030 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
00031 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
00032
00033 if( $wgArticlePath === false ) {
00034 if( $wgUsePathInfo ) {
00035 $wgArticlePath = "$wgScript/$1";
00036 } else {
00037 $wgArticlePath = "$wgScript?title=$1";
00038 }
00039 }
00040
00041 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
00042 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
00043 if( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
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 'deletedDir' => $wgFileStore['deleted']['directory'],
00091 'deletedHashLevels' => $wgFileStore['deleted']['hash']
00092 );
00093 }
00097 if ( $wgUseSharedUploads ) {
00098 if ( $wgSharedUploadDBname ) {
00099 $wgForeignFileRepos[] = array(
00100 'class' => 'ForeignDBRepo',
00101 'name' => 'shared',
00102 'directory' => $wgSharedUploadDirectory,
00103 'url' => $wgSharedUploadPath,
00104 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
00105 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
00106 'transformVia404' => !$wgGenerateThumbnailOnParse,
00107 'dbType' => $wgDBtype,
00108 'dbServer' => $wgDBserver,
00109 'dbUser' => $wgDBuser,
00110 'dbPassword' => $wgDBpassword,
00111 'dbName' => $wgSharedUploadDBname,
00112 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
00113 'tablePrefix' => $wgSharedUploadDBprefix,
00114 'hasSharedCache' => $wgCacheSharedUploads,
00115 'descBaseUrl' => $wgRepositoryBaseUrl,
00116 'fetchDescription' => $wgFetchCommonsDescriptions,
00117 );
00118 } else {
00119 $wgForeignFileRepos[] = array(
00120 'class' => 'FSRepo',
00121 'name' => 'shared',
00122 'directory' => $wgSharedUploadDirectory,
00123 'url' => $wgSharedUploadPath,
00124 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
00125 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
00126 'transformVia404' => !$wgGenerateThumbnailOnParse,
00127 'descBaseUrl' => $wgRepositoryBaseUrl,
00128 'fetchDescription' => $wgFetchCommonsDescriptions,
00129 );
00130 }
00131 }
00132 if( $wgUseInstantCommons ) {
00133 $wgForeignFileRepos[] = array(
00134 'class' => 'ForeignAPIRepo',
00135 'name' => 'wikimediacommons',
00136 'apibase' => 'http://commons.wikimedia.org/w/api.php',
00137 'hashLevels' => 2,
00138 'fetchDescription' => true,
00139 'descriptionCacheExpiry' => 43200,
00140 'apiThumbCacheExpiry' => 86400,
00141 );
00142 }
00143
00144 if ( !class_exists( 'AutoLoader' ) ) {
00145 require_once( "$IP/includes/AutoLoader.php" );
00146 }
00147
00148 wfProfileIn( $fname.'-exception' );
00149 require_once( "$IP/includes/Exception.php" );
00150 wfInstallExceptionHandler();
00151 wfProfileOut( $fname.'-exception' );
00152
00153 wfProfileIn( $fname.'-includes' );
00154 require_once( "$IP/includes/GlobalFunctions.php" );
00155 require_once( "$IP/includes/Hooks.php" );
00156 require_once( "$IP/includes/Namespace.php" );
00157 require_once( "$IP/includes/ProxyTools.php" );
00158 require_once( "$IP/includes/ObjectCache.php" );
00159 require_once( "$IP/includes/ImageFunctions.php" );
00160 require_once( "$IP/includes/StubObject.php" );
00161 wfProfileOut( $fname.'-includes' );
00162 wfProfileIn( $fname.'-misc1' );
00163
00164 # Raise the memory limit if it's too low
00165 wfMemoryLimit();
00166
00172 wfSuppressWarnings();
00173 date_default_timezone_set( date_default_timezone_get() );
00174 wfRestoreWarnings();
00175
00176 $wgIP = false; # Load on demand
00177 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
00178 $wgRequest = new WebRequest;
00179
00180 # Useful debug output
00181 if ( $wgCommandLineMode ) {
00182 wfDebug( "\n\nStart command line script $self\n" );
00183 } else {
00184 wfDebug( "Start request\n\n" );
00185 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
00186
00187 if ( $wgDebugPrintHttpHeaders ) {
00188 $headerOut = "HTTP HEADERS:\n";
00189
00190 if ( function_exists( 'getallheaders' ) ) {
00191 $headers = getallheaders();
00192 foreach ( $headers as $name => $value ) {
00193 $headerOut .= "$name: $value\n";
00194 }
00195 } else {
00196 $headers = $_SERVER;
00197 foreach ( $headers as $name => $value ) {
00198 if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue;
00199 $name = substr( $name, 5 );
00200 $headerOut .= "$name: $value\n";
00201 }
00202 }
00203 wfDebug( "$headerOut\n" );
00204 }
00205 }
00206
00207 if( $wgRCFilterByAge ) {
00208 ## Trim down $wgRCLinkDays so that it only lists links which are valid
00209 ## as determined by $wgRCMaxAge.
00210 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
00211 sort($wgRCLinkDays);
00212 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
00213 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
00214 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
00215 break;
00216 }
00217 }
00218 }
00219
00220 if ( $wgSkipSkin ) {
00221 $wgSkipSkins[] = $wgSkipSkin;
00222 }
00223
00224 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
00225
00226 if($wgMetaNamespace === FALSE) {
00227 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
00228 }
00229
00230 # These are now the same, always
00231 # To determine the user language, use $wgLang->getCode()
00232 $wgContLanguageCode = $wgLanguageCode;
00233
00234 # Easy to forget to falsify $wgShowIPinHeader for static caches.
00235 # If file cache or squid cache is on, just disable this (DWIMD).
00236 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
00237
00238 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
00239 # in favor of $wgHiddenPrefs, handle b/c here
00240 if( !$wgAllowRealName ) {
00241 $wgHiddenPrefs[] = 'realname';
00242 }
00243
00244 if( !$wgAllowUserSkin ) {
00245 $wgHiddenPrefs[] = 'skin';
00246 }
00247
00248 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
00249 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
00250 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
00251 else $wgHtml5Version = 'HTML+RDFa 1.0';
00252 }
00253
00254
00255 wfProfileOut( $fname.'-misc1' );
00256 wfProfileIn( $fname.'-memcached' );
00257
00258 $wgMemc =& wfGetMainCache();
00259 $messageMemc =& wfGetMessageCacheStorage();
00260 $parserMemc =& wfGetParserCacheStorage();
00261
00262 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
00263 get_class( $messageMemc ) . '[message] ' .
00264 get_class( $parserMemc ) . "[parser]\n" );
00265
00266 wfProfileOut( $fname.'-memcached' );
00267
00268 ## Most of the config is out, some might want to run hooks here.
00269 wfRunHooks( 'SetupAfterCache' );
00270
00271 wfProfileIn( $fname.'-SetupSession' );
00272
00273 # Set default shared prefix
00274 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
00275
00276 if( !$wgCookiePrefix ) {
00277 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
00278 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
00279 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
00280 $wgCookiePrefix = $wgSharedDB;
00281 } elseif ( $wgDBprefix ) {
00282 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
00283 } else {
00284 $wgCookiePrefix = $wgDBname;
00285 }
00286 }
00287 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
00288
00289 # If session.auto_start is there, we can't touch session name
00290 #
00291 if( !wfIniGetBool( 'session.auto_start' ) )
00292 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
00293
00294 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
00295 wfIncrStats( 'request_with_session' );
00296 wfSetupSession();
00297 $wgSessionStarted = true;
00298 } else {
00299 wfIncrStats( 'request_without_session' );
00300 $wgSessionStarted = false;
00301 }
00302
00303 wfProfileOut( $fname.'-SetupSession' );
00304 wfProfileIn( $fname.'-globals' );
00305
00306 $wgContLang = new StubContLang;
00307
00308
00309 $wgRequest->interpolateTitle();
00310
00311 $wgUser = new StubUser;
00312 $wgLang = new StubUserLang;
00313 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
00314 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
00315
00316 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
00317 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
00318
00319 wfProfileOut( $fname.'-globals' );
00320 wfProfileIn( $fname.'-User' );
00321
00322 # Skin setup functions
00323 # Entries can be added to this variable during the inclusion
00324 # of the extension file. Skins can then perform any necessary initialisation.
00325 #
00326 foreach ( $wgSkinExtensionFunctions as $func ) {
00327 call_user_func( $func );
00328 }
00329
00330 if( !is_object( $wgAuth ) ) {
00331 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
00332 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
00333 }
00334
00335 wfProfileOut( $fname.'-User' );
00336
00337 wfProfileIn( $fname.'-misc2' );
00338
00339 $wgDeferredUpdateList = array();
00340 $wgPostCommitUpdateList = array();
00341
00342 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
00343 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
00344
00345 # Placeholders in case of DB error
00346 $wgTitle = null;
00347 $wgArticle = null;
00348
00349 wfProfileOut( $fname.'-misc2' );
00350 wfProfileIn( $fname.'-extensions' );
00351
00352 # Extension setup functions for extensions other than skins
00353 # Entries should be added to this variable during the inclusion
00354 # of the extension file. This allows the extension to perform
00355 # any necessary initialisation in the fully initialised environment
00356 foreach ( $wgExtensionFunctions as $func ) {
00357 # Allow closures in PHP 5.3+
00358 if ( is_object( $func ) && $func instanceof Closure ) {
00359 $profName = $fname.'-extensions-closure';
00360 } elseif( is_array( $func ) ) {
00361 if ( is_object( $func[0] ) )
00362 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
00363 else
00364 $profName = $fname.'-extensions-'.implode( '::', $func );
00365 } else {
00366 $profName = $fname.'-extensions-'.strval( $func );
00367 }
00368
00369 wfProfileIn( $profName );
00370 call_user_func( $func );
00371 wfProfileOut( $profName );
00372 }
00373
00374
00375 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
00376 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
00377 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
00378 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
00379
00380 if( !empty($wgNewUserLog) ) {
00381 # Add a new log type
00382 $wgLogTypes[] = 'newusers';
00383 $wgLogNames['newusers'] = 'newuserlogpage';
00384 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
00385 $wgLogActions['newusers/newusers'] = 'newuserlogentry';
00386 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
00387 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
00388 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
00389 }
00390
00391 wfDebug( "Fully initialised\n" );
00392 $wgFullyInitialised = true;
00393 wfProfileOut( $fname.'-extensions' );
00394 wfProfileOut( $fname );