Fix bug 56, which causes sections to be dropped or duplicated
[lhc/web/wiklou.git] / includes / Setup.php
index 22f8585..c04f287 100644 (file)
@@ -1,7 +1,14 @@
 <?php
+/**
+ * Include most things that's need to customize the site
+ * @package MediaWiki
+ */
 
-# This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
-if( defined( "MEDIAWIKI" ) ) {
+/**
+ * This file is not a valid entry point, perform no further processing unless
+ * MEDIAWIKI is defined
+ */
+if( defined( 'MEDIAWIKI' ) ) {
 
 # The main wiki script and things like database
 # conversion and maintenance scripts all share a
@@ -111,6 +118,11 @@ if( $wgUseMemCached ) {
        # Set up Memcached
        #
        require_once( 'memcached-client.php' );
+       
+       /**
+        *
+        * @package MediaWiki
+        */
        class MemCachedClientforWiki extends memcached {
                function _debugprint( $text ) {
                        wfDebug( "memcached: $text\n" );
@@ -121,8 +133,18 @@ if( $wgUseMemCached ) {
        $wgMemc->set_servers( $wgMemCachedServers );
        $wgMemc->set_debug( $wgMemCachedDebug );
 
+       $messageMemc = &$wgMemc;
+} elseif ( $wgUseTurckShm ) {
+       # Turck shared memory
+       #
+       require_once( 'ObjectCache.php' );
+       $wgMemc = new TurckBagOStuff;
        $messageMemc = &$wgMemc;
 } else {
+       /**
+        * No shared memory
+        * @package MediaWiki
+        */
        class FakeMemCachedClient {
                function add ($key, $val, $exp = 0) { return true; }
                function decr ($key, $amt=1) { return null; }
@@ -176,12 +198,44 @@ $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers );
 $wgLoadBalancer->loadMasterPos();
 
 wfProfileOut( $fname.'-database' );
+wfProfileIn( $fname.'-User' );
+
+# Extension setup functions
+# 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 ( $wgSkinExtensionFunctions as $func ) {
+       $func();
+}
+
+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();
+} else {
+       $wgUser = User::loadFromSession();
+}
+
+// FIXME : we don't know what the user entered (see SpecialPreferences.php [AV])
+if( count( $wgUserLanguages ) &&
+       !empty( $wgUser->mOptions['language'] ) &&
+       in_array( $wgUser->mOptions['language'], $wgUserLanguages ) ) {
+       // Change language of the site
+       $wgUserLanguageCode = $wgUser->mOptions['language'];
+       // we will load messages from file instead of from database
+       $wgUseDatabaseMessages = false;
+       # FIXME: THIS WILL BREAK NAMESPACES, VARIABLES,
+       # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
+       # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
+}
+
+wfProfileOut( $fname.'-User' );
 wfProfileIn( $fname.'-language' );
 require_once( 'languages/Language.php' );
 
-$wgMessageCache = new MessageCache; 
+$wgMessageCache = new MessageCache;
 
-$wgLangClass = 'Language' . ucfirst( $wgLanguageCode );
+$wgLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
 if( ! class_exists( $wgLangClass ) || ($wgLanguageCode == 'en' && !$wgUseLatin1) ) {
        # Default to English/UTF-8
        require_once( 'languages/LanguageUtf8.php' );
@@ -200,6 +254,24 @@ if( $wgUseLatin1 && $wgLanguageCode != 'en' ) {
        unset( $wgLang );
        $wgLang = $xxx;
 }
+
+// now that we have a language object, set per language user defaults options
+// if we didn't grabbed them from database.
+if(!$wgUser->mDataLoaded) { $wgUser->loadDefaultFromLanguage(); }
+// and change the messages array used
+
+if(isset($wgUserLanguageCode)) {
+       /** Need to load the language datas */
+       require_once( 'languages/Language'.str_replace('-', '_', ucfirst( $wgUserLanguageCode )).'.php');
+       $sitemsgarray = 'wgAllMessages'.ucfirst($wgLanguageCode);
+       $usermsgarray = 'wgAllMessages'.str_replace('-', '_', ucfirst( $wgUserLanguageCode ));
+       $$sitemsgarray = &$$usermsgarray;
+       // rebuild the language object messages
+       $wgLang->Language();
+}
+
+
+
 wfProfileOut( $fname.'-language' );
 wfProfileIn( $fname.'-MessageCache' );
 
@@ -226,17 +298,6 @@ wfProfileIn( $fname.'-BlockCache' );
 $wgBlockCache = new BlockCache( true );
 
 wfProfileOut( $fname.'-BlockCache' );
-wfProfileIn( $fname.'-User' );
-
-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();
-} else {
-       $wgUser = User::loadFromSession();
-}
-
-wfProfileOut( $fname.'-User' );
 wfProfileIn( $fname.'-misc2' );
 
 $wgDeferredUpdateList = array();