Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

Setup.php

Go to the documentation of this file.
00001 <?php 00002 # The main wiki script and things like database 00003 # conversion and maintenance scripts all share a 00004 # common setup of including lots of classes and 00005 # setting up a few globals. 00006 # 00007 00008 global $wgProfiling, $wgProfileSampleRate, $wgIP, $wgUseSquid; 00009 00010 if( !isset( $wgProfiling ) ) 00011 $wgProfiling = false; 00012 00013 if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) { 00014 require_once( 'Profiling.php' ); 00015 } else { 00016 function wfProfileIn( $fn = '' ) {} 00017 function wfProfileOut( $fn = '' ) {} 00018 function wfGetProfilingOutput( $s, $e ) {} 00019 function wfProfileClose() {} 00020 } 00021 00022 /* collect the originating ips */ 00023 if( $wgUseSquid && isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { 00024 # If the web server is behind a reverse proxy, we need to find 00025 # out where our requests are really coming from. 00026 $hopips = array_map( 'trim', explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) ); 00027 00028 while(in_array(trim(end($hopips)), $wgSquidServers)){ 00029 array_pop($hopips); 00030 } 00031 $wgIP = trim(end($hopips)); 00032 } else { 00033 $wgIP = getenv('REMOTE_ADDR'); 00034 } 00035 00036 00037 $fname = 'Setup.php'; 00038 wfProfileIn( $fname ); 00039 global $wgUseDynamicDates; 00040 wfProfileIn( $fname.'-includes' ); 00041 00042 require_once( 'GlobalFunctions.php' ); 00043 require_once( 'Namespace.php' ); 00044 require_once( 'RecentChange.php' ); 00045 require_once( 'User.php' ); 00046 require_once( 'Skin.php' ); 00047 require_once( 'OutputPage.php' ); 00048 require_once( 'LinkCache.php' ); 00049 require_once( 'Title.php' ); 00050 require_once( 'Article.php' ); 00051 require_once( 'MagicWord.php' ); 00052 require_once( 'memcached-client.php' ); 00053 require_once( 'Block.php' ); 00054 require_once( 'SearchEngine.php' ); 00055 require_once( 'DifferenceEngine.php' ); 00056 require_once( 'MessageCache.php' ); 00057 require_once( 'BlockCache.php' ); 00058 require_once( 'Parser.php' ); 00059 require_once( 'ParserCache.php' ); 00060 require_once( 'WebRequest.php' ); 00061 require_once( 'LoadBalancer.php' ); 00062 00063 $wgRequest = new WebRequest(); 00064 00065 00066 00067 wfProfileOut( $fname.'-includes' ); 00068 wfProfileIn( $fname.'-memcached' ); 00069 global $wgUser, $wgLang, $wgOut, $wgTitle; 00070 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache; 00071 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile; 00072 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages; 00073 global $wgMsgCacheExpiry, $wgDBname, $wgCommandLineMode; 00074 global $wgBlockCache, $wgParserCache, $wgParser, $wgDBConnections; 00075 global $wgLoadBalancer, $wgDBservers, $wgDBloads, $wgDBuser, $wgDBpassword; 00076 00077 # Useful debug output 00078 if ( $wgCommandLineMode ) { 00079 # wfDebug( '"' . implode( '" "', $argv ) . '"' ); 00080 } elseif ( function_exists( 'getallheaders' ) ) { 00081 wfDebug( "\nStart request\n" ); 00082 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" ); 00083 $headers = getallheaders(); 00084 foreach ($headers as $name => $value) { 00085 wfDebug( "$name: $value\n" ); 00086 } 00087 wfDebug( "\n" ); 00088 } else { 00089 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" ); 00090 } 00091 00092 # Set up Memcached 00093 # 00094 class MemCachedClientforWiki extends memcached { 00095 function _debugprint( $text ) { 00096 wfDebug( "memcached: $text\n" ); 00097 } 00098 } 00099 00100 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2. 00101 # It acts as a memcached server with no RAM, that is, all objects are 00102 # cleared the moment they are set. All set operations succeed and all 00103 # get operations return null. 00104 00105 class FakeMemCachedClient { 00106 function add ($key, $val, $exp = 0) { return true; } 00107 function decr ($key, $amt=1) { return null; } 00108 function delete ($key, $time = 0) { return false; } 00109 function disconnect_all () { } 00110 function enable_compress ($enable) { } 00111 function forget_dead_hosts () { } 00112 function get ($key) { return null; } 00113 function get_multi ($keys) { return array_pad(array(), count($keys), null); } 00114 function incr ($key, $amt=1) { return null; } 00115 function replace ($key, $value, $exp=0) { return false; } 00116 function run_command ($sock, $cmd) { return null; } 00117 function set ($key, $value, $exp=0){ return true; } 00118 function set_compress_threshold ($thresh){ } 00119 function set_debug ($dbg) { } 00120 function set_servers ($list) { } 00121 } 00122 00123 if( $wgUseMemCached ) { 00124 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) ); 00125 $wgMemc->set_servers( $wgMemCachedServers ); 00126 $wgMemc->set_debug( $wgMemCachedDebug ); 00127 00128 # Test it to see if it's working 00129 # This is necessary because otherwise wfMsg would be extremely inefficient 00130 if ( !$wgMemc->set( 'test', '', 0 ) ) { 00131 wfDebug( "Memcached failed setup test - connection error?\n" ); 00132 $wgUseMemCached = false; 00133 $wgMemc = new FakeMemCachedClient(); 00134 } 00135 $messageMemc = &$wgMemc; 00136 } else { 00137 $wgMemc = new FakeMemCachedClient(); 00138 00139 # Give the message cache a separate cache in the DB. 00140 # This is a speedup over separately querying every message used 00141 require_once( 'ObjectCache.php' ); 00142 $messageMemc = new MediaWikiBagOStuff('objectcache'); 00143 } 00144 00145 wfProfileOut( $fname.'-memcached' ); 00146 wfProfileIn( $fname.'-database' ); 00147 00148 if ( !$wgDBservers ) { 00149 $wgDBservers = array( $wgDBserver ); 00150 $wgDBloads = array( 1 ); 00151 } 00152 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, $wgDBloads, $wgDBuser, $wgDBpassword, $wgDBname ); 00153 $wgLoadBalancer->force(0); 00154 00155 wfProfileOut( $fname.'-database' ); 00156 wfProfileIn( $fname.'-language' ); 00157 require_once( 'languages/Language.php' ); 00158 00159 $wgMessageCache = new MessageCache; 00160 00161 $wgLangClass = 'Language' . ucfirst( $wgLanguageCode ); 00162 if( ! class_exists( $wgLangClass ) || ($wgLanguageCode == 'en' && !$wgUseLatin1) ) { 00163 # Default to English/UTF-8 00164 require_once( 'languages/LanguageUtf8.php' ); 00165 $wgLangClass = 'LanguageUtf8'; 00166 } 00167 00168 $wgLang = new $wgLangClass(); 00169 if ( !is_object($wgLang) ) { 00170 print "No language class ($wgLang)\N"; 00171 } 00172 00173 if( $wgUseLatin1 && $wgLanguageCode != 'en' ) { 00174 # For non-UTF-8 non-English. 00175 require_once( 'languages/LanguageLatin1.php' ); 00176 $xxx = new LanguageLatin1( $wgLang ); 00177 unset( $wgLang ); 00178 $wgLang = $xxx; 00179 } 00180 wfProfileOut( $fname.'-language' ); 00181 wfProfileIn( $fname.'-MessageCache' ); 00182 00183 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname ); 00184 00185 wfProfileOut( $fname.'-MessageCache' ); 00186 wfProfileIn( $fname.'-OutputPage' ); 00187 00188 $wgOut = new OutputPage(); 00189 wfDebug( "\n\n" ); 00190 00191 wfProfileOut( $fname.'-OutputPage' ); 00192 wfProfileIn( $fname.'-DateFormatter' ); 00193 00194 if ( $wgUseDynamicDates ) { 00195 require_once( 'DateFormatter.php' ); 00196 global $wgDateFormatter; 00197 $wgDateFormatter = new DateFormatter; 00198 } 00199 00200 wfProfileOut( $fname.'-DateFormatter' ); 00201 wfProfileIn( $fname.'-SetupSession' ); 00202 00203 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) || isset( $_COOKIE[$wgDBname.'Password'] ) ) ) { 00204 User::SetupSession(); 00205 } 00206 00207 wfProfileOut( $fname.'-SetupSession' ); 00208 wfProfileIn( $fname.'-BlockCache' ); 00209 00210 $wgBlockCache = new BlockCache( true ); 00211 00212 wfProfileOut( $fname.'-BlockCache' ); 00213 wfProfileIn( $fname.'-User' ); 00214 00215 if( $wgCommandLineMode ) { 00216 # Used for some maintenance scripts; user session cookies can screw things up 00217 # when the database is in an in-between state. 00218 $wgUser = new User(); 00219 } else { 00220 $wgUser = User::loadFromSession(); 00221 } 00222 00223 wfProfileOut( $fname.'-User' ); 00224 wfProfileIn( $fname.'-misc' ); 00225 00226 $wgDeferredUpdateList = array(); 00227 $wgLinkCache = new LinkCache(); 00228 $wgMagicWords = array(); 00229 $wgMwRedir =& MagicWord::get( MAG_REDIRECT ); 00230 $wgParserCache = new ParserCache(); 00231 $wgParser = new Parser(); 00232 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) ); 00233 $wgDBConnections = array(); 00234 00235 # Placeholders in case of DB error 00236 $wgTitle = Title::newFromText( wfMsg( 'badtitle' ) ); 00237 $wgArticle = new Article($wgTitle); 00238 00239 wfProfileOut( $fname.'-misc' ); 00240 wfProfileIn( $fname.'-extensions' ); 00241 00242 # Extension setup functions 00243 # Entries should be added to this variable during the inclusion 00244 # of the extension file. This allows the extension to perform 00245 # any necessary initialisation in the fully initialised environment 00246 foreach ( $wgExtensionFunctions as $func ) { 00247 $func(); 00248 } 00249 00250 wfProfileOut( $fname.'-extensions' ); 00251 wfProfileOut( $fname ); 00252 00253 00254 ?>

Generated on Tue Jun 29 23:40:06 2004 for Mediawiki by doxygen 1.3.7