Squid integration changes
[lhc/web/wiklou.git] / includes / Setup.php
1 <?
2 # The main wiki script and things like database
3 # conversion and maintenance scripts all share a
4 # common setup of including lots of classes and
5 # setting up a few globals.
6 #
7
8 if( !isset( $wgProfiling ) )
9 $wgProfiling = false;
10
11 if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
12 include_once( "Profiling.php" );
13 } else {
14 function wfProfileIn( $fn ) {}
15 function wfProfileOut( $fn = "" ) {}
16 function wfGetProfilingOutput( $s, $e ) {}
17 function wfProfileClose() {}
18 }
19
20
21
22 /* collect the originating ips */
23 if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
24 $wgIP = trim(preg_replace("/^(.*, )?([^,]+)$/", "$2",
25 $_SERVER['HTTP_X_FORWARDED_FOR']));
26 } else {
27 $wgIP = getenv("REMOTE_ADDR");
28 }
29
30 $fname = "Setup.php";
31 wfProfileIn( $fname );
32 global $wgUseDynamicDates;
33 wfProfileIn( "$fname-includes" );
34
35 include_once( "GlobalFunctions.php" );
36 include_once( "Namespace.php" );
37 include_once( "RecentChange.php" );
38 include_once( "Skin.php" );
39 include_once( "OutputPage.php" );
40 include_once( "User.php" );
41 include_once( "LinkCache.php" );
42 include_once( "Title.php" );
43 include_once( "Article.php" );
44 include_once( "MagicWord.php" );
45 include_once( "memcached-client.php" );
46 include_once( "Block.php" );
47 include_once( "SearchEngine.php" );
48 include_once( "DifferenceEngine.php" );
49 include_once( "MessageCache.php" );
50
51 wfProfileOut( "$fname-includes" );
52 wfProfileIn( "$fname-memcached" );
53 global $wgUser, $wgLang, $wgOut, $wgTitle;
54 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
55 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
56 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
57 global $wgMsgCacheExpiry, $wgDBname, $wgCommandLineMode;
58
59 class MemCachedClientforWiki extends memcached {
60 function _debugprint( $text ) {
61 wfDebug( "memcached: $text\n" );
62 }
63 }
64
65 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
66 # It acts as a memcached server with no RAM, that is, all objects are
67 # cleared the moment they are set. All set operations succeed and all
68 # get operations return null.
69
70 class FakeMemCachedClient {
71 function add ($key, $val, $exp = 0) { return true; }
72 function decr ($key, $amt=1) { return null; }
73 function delete ($key, $time = 0) { return false; }
74 function disconnect_all () { }
75 function enable_compress ($enable) { }
76 function forget_dead_hosts () { }
77 function get ($key) { return null; }
78 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
79 function incr ($key, $amt=1) { return null; }
80 function replace ($key, $value, $exp=0) { return false; }
81 function run_command ($sock, $cmd) { return null; }
82 function set ($key, $value, $exp=0){ return true; }
83 function set_compress_threshold ($thresh){ }
84 function set_debug ($dbg) { }
85 function set_servers ($list) { }
86 }
87
88 if( $wgUseMemCached ) {
89 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
90 $wgMemc->set_servers( $wgMemCachedServers );
91 $wgMemc->set_debug( $wgMemCachedDebug );
92
93 # Test it to see if it's working
94 # This is necessary because otherwise wfMsg would be extremely inefficient
95 if ( !$wgMemc->set( "test", "", 0 ) ) {
96 wfDebug( "Memcached failed setup test - connection error?\n" );
97 $wgUseMemCached = false;
98 $wgMemc = new FakeMemCachedClient();
99 }
100 } else {
101 $wgMemc = new FakeMemCachedClient();
102 }
103
104 wfProfileOut( "$fname-memcached" );
105 wfProfileIn( "$fname-misc" );
106
107 include_once( "Language.php" );
108
109 $wgMessageCache = new MessageCache;
110
111 $wgOut = new OutputPage();
112 wfDebug( "\n\n" );
113
114 $wgLangClass = "Language" . ucfirst( $wgLanguageCode );
115 if( ! class_exists( $wgLangClass ) ) {
116 include_once( "LanguageUtf8.php" );
117 $wgLangClass = "LanguageUtf8";
118 }
119
120 $wgLang = new $wgLangClass();
121 if ( !is_object($wgLang) ) {
122 print "No language class ($wgLang)\N";
123 }
124 $wgMessageCache->initialise( $wgUseMemCached, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
125
126 if ( $wgUseDynamicDates ) {
127 include_once( "DateFormatter.php" );
128 global $wgDateFormatter;
129 $wgDateFormatter = new DateFormatter;
130 }
131
132 if( !$wgCommandLineMode && isset( $_COOKIE[ini_get("session.name")] ) ) {
133 User::SetupSession();
134 }
135
136 $wgUser = User::loadFromSession();
137 $wgDeferredUpdateList = array();
138 $wgLinkCache = new LinkCache();
139 $wgMagicWords = array();
140 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
141
142 wfProfileOut( "$fname-misc" );
143 wfProfileOut( $fname );
144
145 ?>