Silenced this, $token["pos"] was undefined when parsing '''hi'''''hi'' which created...
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
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 global $wgProfiling, $wgProfileSampleRate, $wgIP, $wgUseSquid;
9
10 if( !isset( $wgProfiling ) )
11 $wgProfiling = false;
12
13 if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
14 require_once( "Profiling.php" );
15 } else {
16 function wfProfileIn( $fn ) {}
17 function wfProfileOut( $fn = "" ) {}
18 function wfGetProfilingOutput( $s, $e ) {}
19 function wfProfileClose() {}
20 }
21
22 /* collect the originating ips */
23 if( $wgUseSquid && isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
24 # If the web server is behind a reverse proxy, we need to find
25 # out where our requests are really coming from.
26 $hopips = array_map( "trim", explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
27
28 while(in_array(trim(end($hopips)), $wgSquidServers)){
29 array_pop($hopips);
30 }
31 $wgIP = trim(end($hopips));
32 } else {
33 $wgIP = getenv("REMOTE_ADDR");
34 }
35
36
37 $fname = "Setup.php";
38 wfProfileIn( $fname );
39 global $wgUseDynamicDates;
40 wfProfileIn( "$fname-includes" );
41
42 require_once( "GlobalFunctions.php" );
43 require_once( "Namespace.php" );
44 require_once( "RecentChange.php" );
45 require_once( "Skin.php" );
46 require_once( "OutputPage.php" );
47 require_once( "User.php" );
48 require_once( "LinkCache.php" );
49 require_once( "Title.php" );
50 require_once( "Article.php" );
51 require_once( "MagicWord.php" );
52 require_once( "memcached-client.php" );
53 require_once( "Block.php" );
54 require_once( "SearchEngine.php" );
55 require_once( "DifferenceEngine.php" );
56 require_once( "MessageCache.php" );
57 require_once( "BlockCache.php" );
58 require_once( "Parser.php" );
59 require_once( "ParserCache.php" );
60 require_once( "WebRequest.php" );
61 $wgRequest = new WebRequest();
62
63
64
65 wfProfileOut( "$fname-includes" );
66 wfProfileIn( "$fname-memcached" );
67 global $wgUser, $wgLang, $wgOut, $wgTitle;
68 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
69 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
70 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
71 global $wgMsgCacheExpiry, $wgDBname, $wgCommandLineMode;
72 global $wgBlockCache, $wgParserCache, $wgParser;
73
74 # Useful debug output
75 if ( $wgCommandLineMode ) {
76 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
77 } elseif ( function_exists( "getallheaders" ) ) {
78 wfDebug( "\nStart request\n" );
79 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
80 $headers = getallheaders();
81 foreach ($headers as $name => $value) {
82 wfDebug( "$name: $value\n" );
83 }
84 wfDebug( "\n" );
85 } else {
86 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
87 }
88
89 # Set up Memcached
90 #
91 class MemCachedClientforWiki extends memcached {
92 function _debugprint( $text ) {
93 wfDebug( "memcached: $text\n" );
94 }
95 }
96
97 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
98 # It acts as a memcached server with no RAM, that is, all objects are
99 # cleared the moment they are set. All set operations succeed and all
100 # get operations return null.
101
102 class FakeMemCachedClient {
103 function add ($key, $val, $exp = 0) { return true; }
104 function decr ($key, $amt=1) { return null; }
105 function delete ($key, $time = 0) { return false; }
106 function disconnect_all () { }
107 function enable_compress ($enable) { }
108 function forget_dead_hosts () { }
109 function get ($key) { return null; }
110 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
111 function incr ($key, $amt=1) { return null; }
112 function replace ($key, $value, $exp=0) { return false; }
113 function run_command ($sock, $cmd) { return null; }
114 function set ($key, $value, $exp=0){ return true; }
115 function set_compress_threshold ($thresh){ }
116 function set_debug ($dbg) { }
117 function set_servers ($list) { }
118 }
119
120 if( $wgUseMemCached ) {
121 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
122 $wgMemc->set_servers( $wgMemCachedServers );
123 $wgMemc->set_debug( $wgMemCachedDebug );
124
125 # Test it to see if it's working
126 # This is necessary because otherwise wfMsg would be extremely inefficient
127 if ( !$wgMemc->set( "test", "", 0 ) ) {
128 wfDebug( "Memcached failed setup test - connection error?\n" );
129 $wgUseMemCached = false;
130 $wgMemc = new FakeMemCachedClient();
131 }
132 $messageMemc = &$wgMemc;
133 } else {
134 $wgMemc = new FakeMemCachedClient();
135
136 # Give the message cache a separate cache in the DB.
137 # This is a speedup over separately querying every message used
138 require_once( "ObjectCache.php" );
139 $messageMemc = new MediaWikiBagOStuff("objectcache");
140 }
141
142 wfProfileOut( "$fname-memcached" );
143 wfProfileIn( "$fname-misc" );
144
145 require_once( "languages/Language.php" );
146
147 $wgMessageCache = new MessageCache;
148
149 $wgLangClass = "Language" . ucfirst( $wgLanguageCode );
150 if( ! class_exists( $wgLangClass ) || ($wgLanguageCode == "en" && strcasecmp( $wgInputEncoding, "utf-8" ) == 0 ) ) {
151 require_once( "languages/LanguageUtf8.php" );
152 $wgLangClass = "LanguageUtf8";
153 }
154
155 $wgLang = new $wgLangClass();
156 if ( !is_object($wgLang) ) {
157 print "No language class ($wgLang)\N";
158 }
159 $wgMessageCache->initialise( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
160
161 $wgOut = new OutputPage();
162 wfDebug( "\n\n" );
163
164 if ( $wgUseDynamicDates ) {
165 require_once( "DateFormatter.php" );
166 global $wgDateFormatter;
167 $wgDateFormatter = new DateFormatter;
168 }
169
170 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get("session.name")] ) || isset( $_COOKIE["{$wgDBname}Password"] ) ) ) {
171 User::SetupSession();
172 }
173
174 $wgBlockCache = new BlockCache( true );
175 if( $wgCommandLineMode ) {
176 # Used for some maintenance scripts; user session cookies can screw things up
177 # when the database is in an in-between state.
178 $wgUser = new User();
179 } else {
180 $wgUser = User::loadFromSession();
181 }
182 $wgDeferredUpdateList = array();
183 $wgLinkCache = new LinkCache();
184 $wgMagicWords = array();
185 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
186 $wgParserCache = new ParserCache();
187 $wgParser = new Parser();
188 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
189
190 wfProfileOut( "$fname-misc" );
191 wfProfileOut( $fname );
192
193
194 ?>