Removed most exit() calls from the MediaWiki core, by replacing them with either...
[lhc/web/wiklou.git] / includes / Setup.php
index e098396..acdca9c 100644 (file)
@@ -18,50 +18,50 @@ if( defined( 'MEDIAWIKI' ) ) {
 
 // Check to see if we are at the file scope
 if ( !isset( $wgVersion ) ) {
-       die( "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n" );
+       echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
+       die( 1 );
 }
 
 if( !isset( $wgProfiling ) )
        $wgProfiling = false;
 
-if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
-        require_once( 'Profiling.php' );
+if ( function_exists( 'wfProfileIn' ) ) {
+       /* nada, everything should be done already */
+} elseif ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
+       require_once( 'Profiling.php' );
+       $wgProfiling = true;
+       if ($wgProfilerType == "") {
+               $wgProfiler = new Profiler();
+       } else {
+               $prclass="Profiler{$wgProfilerType}";
+               require_once( $prclass.".php" );
+               $wgProfiler = new $prclass();
+       }
 } else {
-        function wfProfileIn( $fn = '' ) {
-                global $hackwhere, $wgDBname;
-                $hackwhere[] = $fn;
-                if (function_exists("setproctitle"))
-                        setproctitle($fn . " [$wgDBname]");
-        }
-        function wfProfileOut( $fn = '' ) {
-                global $hackwhere, $wgDBname;
-                if (count($hackwhere))
-                        array_pop($hackwhere);
-                if (function_exists("setproctitle") && count($hackwhere))
-                        setproctitle($hackwhere[count($hackwhere)-1] . " [$wgDBname]");
-        }
-        function wfGetProfilingOutput( $s, $e ) {}
-        function wfProfileClose() {}
+       require_once( 'ProfilerStub.php' );
 }
 
 $fname = 'Setup.php';
 wfProfileIn( $fname );
+
+wfProfileIn( $fname.'-exception' );
+require_once( 'Exception.php' );
+wfInstallExceptionHandler();
+wfProfileOut( $fname.'-exception' );
+
 wfProfileIn( $fname.'-includes' );
 
+require_once( 'AutoLoader.php' );
 require_once( 'GlobalFunctions.php' );
 require_once( 'Hooks.php' );
 require_once( 'Namespace.php' );
-require_once( 'RecentChange.php' ); 
 require_once( 'User.php' );
 require_once( 'Skin.php' );
 require_once( 'OutputPage.php' );
-require_once( 'LinkCache.php' );
 require_once( 'Title.php' );
-require_once( 'Article.php' );
 require_once( 'MagicWord.php' );
 require_once( 'Block.php' );
 require_once( 'MessageCache.php' );
-require_once( 'BlockCache.php' );
 require_once( 'Parser.php' );
 require_once( 'ParserCache.php' );
 require_once( 'WebRequest.php' );
@@ -69,7 +69,6 @@ require_once( 'LoadBalancer.php' );
 require_once( 'HistoryBlob.php' );
 require_once( 'ProxyTools.php' );
 require_once( 'ObjectCache.php' );
-require_once( 'WikiError.php' );
 require_once( 'SpecialPage.php' );
 
 if ( $wgUseDynamicDates ) {
@@ -79,8 +78,14 @@ if ( $wgUseDynamicDates ) {
 wfProfileOut( $fname.'-includes' );
 wfProfileIn( $fname.'-misc1' );
 
-$wgIP = wfGetIP();
+$wgIP = false; # Load on demand
 $wgRequest = new WebRequest();
+if ( function_exists( 'posix_uname' ) ) {
+       $wguname = posix_uname();
+       $wgNodeName = $wguname['nodename'];
+} else {
+       $wgNodeName = '';
+}
 
 # Useful debug output
 if ( $wgCommandLineMode ) {
@@ -101,6 +106,8 @@ if ( $wgSkipSkin ) {
        $wgSkipSkins[] = $wgSkipSkin;
 }
 
+$wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
+
 wfProfileOut( $fname.'-misc1' );
 wfProfileIn( $fname.'-memcached' );
 
@@ -108,23 +115,33 @@ $wgMemc =& wfGetMainCache();
 $messageMemc =& wfGetMessageCacheStorage();
 $parserMemc =& wfGetParserCacheStorage();
 
-wfDebug( 'Main cache: ' . get_class( $wgMemc ) . 
-       "\nMessage cache: " . get_class( $messageMemc ) . 
+wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
+       "\nMessage cache: " . get_class( $messageMemc ) .
           "\nParser cache: " . get_class( $parserMemc ) . "\n" );
 
 wfProfileOut( $fname.'-memcached' );
 wfProfileIn( $fname.'-SetupSession' );
 
 if ( $wgDBprefix ) {
-       session_name( $wgDBname . '_' . $wgDBprefix . '_session' );
+       $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
+} elseif ( $wgSharedDB ) {
+       $wgCookiePrefix = $wgSharedDB;
 } else {
-       session_name( $wgDBname . '_session' );
+       $wgCookiePrefix = $wgDBname;
+}
+
+# If session.auto_start is there, we can't touch session name
+#
+if (!ini_get('session.auto_start')) {
+       session_name( $wgCookiePrefix . '_session' );
 }
 
-if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
+if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
+       wfIncrStats( 'request_with_session' );
        User::SetupSession();
        $wgSessionStarted = true;
 } else {
+       wfIncrStats( 'request_without_session' );
        $wgSessionStarted = false;
 }
 
@@ -132,7 +149,7 @@ wfProfileOut( $fname.'-SetupSession' );
 wfProfileIn( $fname.'-database' );
 
 if ( !$wgDBservers ) {
-       $wgDBservers = array(array( 
+       $wgDBservers = array(array(
                'host' => $wgDBserver,
                'user' => $wgDBuser,
                'password' => $wgDBpassword,
@@ -150,35 +167,7 @@ wfProfileIn( $fname.'-language1' );
 
 require_once( "$IP/languages/Language.php" );
 
-wfProfileOut( $fname.'-language1' );
-wfProfileIn( $fname.'-User' );
-
-# Skin setup functions
-# Entries can be added to this variable during the inclusion 
-# of the extension file. Skins can then perform any necessary initialisation.
-foreach ( $wgSkinExtensionFunctions as $func ) {
-       $func();
-}
-
-if( !is_object( $wgAuth ) ) {
-       require_once( 'AuthPlugin.php' );
-       $wgAuth = new AuthPlugin();
-}
-
-if( $wgCommandLineMode ) {
-       # Used for some maintenance scripts; user session cookies can screw things up
-       # when the database is in an in-between state.
-       $wgUser = new User();
-       # Prevent loading User settings from the DB.
-       $wgUser->setLoaded( true );
-} else {
-       $wgUser = User::loadFromSession();
-}
-
-wfProfileOut( $fname.'-User' );
-wfProfileIn( $fname.'-language2' );
-
-function setupLangObj(&$langclass) {
+function setupLangObj($langclass) {
        global $IP;
 
        if( ! class_exists( $langclass ) ) {
@@ -210,15 +199,45 @@ $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageC
 $wgContLang = setupLangObj( $wgContLangClass );
 $wgContLang->initEncoding();
 
-// set default user option from content language
-if( !$wgUser->mDataLoaded ) {
-       $wgUser->loadDefaultFromLanguage();
+wfProfileOut( $fname.'-language1' );
+wfProfileIn( $fname.'-User' );
+
+# Skin setup functions
+# Entries can be added to this variable during the inclusion
+# of the extension file. Skins can then perform any necessary initialisation.
+# 
+foreach ( $wgSkinExtensionFunctions as $func ) {
+       call_user_func( $func );
+}
+
+if( !is_object( $wgAuth ) ) {
+       require_once( 'AuthPlugin.php' );
+       $wgAuth = new AuthPlugin();
 }
 
+if( $wgCommandLineMode ) {
+       # Used for some maintenance scripts; user session cookies can screw things up
+       # when the database is in an in-between state.
+       $wgUser = new User();
+       # Prevent loading User settings from the DB.
+       $wgUser->setLoaded( true );
+} else {
+       $wgUser = null;
+       wfRunHooks('AutoAuthenticate',array(&$wgUser));
+       if ($wgUser === null) {
+               $wgUser = User::loadFromSession();
+       }
+}
+
+wfProfileOut( $fname.'-User' );
+wfProfileIn( $fname.'-language2' );
+
 // wgLanguageCode now specifically means the UI language
-$wgLanguageCode = $wgUser->getOption('language');
+$wgLanguageCode = $wgRequest->getText('uselang', '');
+if ($wgLanguageCode == '')
+       $wgLanguageCode = $wgUser->getOption('language');
 # Validate $wgLanguageCode, which will soon be sent to an eval()
-if( empty( $wgLanguageCode ) || preg_match( '/^[^a-z-]*$/', $wgLanguageCode ) ) {
+if( empty( $wgLanguageCode ) || !preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
        $wgLanguageCode = $wgContLanguageCode;
 }
 
@@ -228,13 +247,15 @@ if( $wgLangClass == $wgContLangClass ) {
        $wgLang = &$wgContLang;
 } else {
        wfSuppressWarnings();
+       // Preload base classes to work around APC/PHP5 bug
+       include_once("$IP/languages/$wgLangClass.deps.php");
        include_once("$IP/languages/$wgLangClass.php");
        wfRestoreWarnings();
 
        $wgLang = setupLangObj( $wgLangClass );
 }
 
-wfProfileOut( $fname.'-language' );
+wfProfileOut( $fname.'-language2' );
 wfProfileIn( $fname.'-MessageCache' );
 
 $wgMessageCache = new MessageCache;
@@ -249,14 +270,14 @@ wfProfileOut( $fname.'-MessageCache' );
 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
 #
-# To disable it, the easiest thing could be to uncomment the 
+# To disable it, the easiest thing could be to uncomment the
 # following; they should effectively disable the UI switch functionality
 #
 # $wgLangClass = $wgContLangClass;
 # $wgLanguageCode = $wgContLanguageCode;
 # $wgLang = $wgContLang;
 #
-# TODO: Need to change reference to $wgLang to $wgContLang at proper 
+# TODO: Need to change reference to $wgLang to $wgContLang at proper
 #       places, including namespaces, dates in signatures, magic words,
 #       and links
 #
@@ -269,20 +290,13 @@ wfProfileIn( $fname.'-OutputPage' );
 $wgOut = new OutputPage();
 
 wfProfileOut( $fname.'-OutputPage' );
-wfProfileIn( $fname.'-BlockCache' );
-
-$wgBlockCache = new BlockCache( true );
-
-wfProfileOut( $fname.'-BlockCache' );
 wfProfileIn( $fname.'-misc2' );
 
 $wgDeferredUpdateList = array();
 $wgPostCommitUpdateList = array();
 
-$wgLinkCache = new LinkCache();
 $wgMagicWords = array();
 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
-$wgParserCache = new ParserCache( $messageMemc );
 
 if ( $wgUseXMLparser ) {
        require_once( 'ParserXML.php' );
@@ -302,13 +316,20 @@ wfProfileOut( $fname.'-misc2' );
 wfProfileIn( $fname.'-extensions' );
 
 # Extension setup functions for extensions other than skins
-# Entries should be added to this variable during the inclusion 
-# of the extension file. This allows the extension to perform 
+# Entries should be added to this variable during the inclusion
+# of the extension file. This allows the extension to perform
 # any necessary initialisation in the fully initialised environment
 foreach ( $wgExtensionFunctions as $func ) {
-       $func();
+       call_user_func( $func );
 }
 
+// For compatibility
+wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
+wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
+wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
+wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
+
+
 wfDebug( "\n" );
 $wgFullyInitialised = true;
 wfProfileOut( $fname.'-extensions' );