Oops, left debug output in
[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 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 $wgIP = getenv("REMOTE_ADDR");
24 if( $wgUseSquid && isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
25 # If the web server is behind a reverse proxy, we need to find
26 # out where our requests are really coming from.
27 $wgIP = trim( preg_replace( "/^(.*, )?([^,]+)$/", "$2",
28 $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
29 }
30
31 $fname = "Setup.php";
32 wfProfileIn( $fname );
33 global $wgUseDynamicDates;
34 wfProfileIn( "$fname-includes" );
35
36 include_once( "GlobalFunctions.php" );
37 include_once( "Namespace.php" );
38 include_once( "RecentChange.php" );
39 include_once( "Skin.php" );
40 include_once( "OutputPage.php" );
41 include_once( "User.php" );
42 include_once( "LinkCache.php" );
43 include_once( "Title.php" );
44 include_once( "Article.php" );
45 include_once( "MagicWord.php" );
46 include_once( "memcached-client.php" );
47 include_once( "Block.php" );
48 include_once( "SearchEngine.php" );
49 include_once( "DifferenceEngine.php" );
50 include_once( "MessageCache.php" );
51 include_once( "BlockCache.php" );
52 include_once( "Parser.php" );
53 include_once( "ParserCache.php" );
54
55 wfProfileOut( "$fname-includes" );
56 wfProfileIn( "$fname-memcached" );
57 global $wgUser, $wgLang, $wgOut, $wgTitle;
58 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
59 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
60 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
61 global $wgMsgCacheExpiry, $wgDBname, $wgCommandLineMode;
62 global $wgBlockCache, $wgParserCache, $wgParser;
63
64 # Useful debug output
65 if ( function_exists( "getallheaders" ) ) {
66 wfDebug( "\nStart request\n" );
67 wfDebug( "$REQUEST_METHOD $REQUEST_URI\n" );
68 $headers = getallheaders();
69 foreach ($headers as $name => $value) {
70 wfDebug( "$name: $value\n" );
71 }
72 wfDebug( "\n" );
73 } else {
74 wfDebug( "$REQUEST_METHOD $REQUEST_URI\n" );
75 }
76
77 # Fix "magic" quotes
78 if ( get_magic_quotes_gpc() ) {
79 foreach ( $_REQUEST as $field => $value ) {
80 $_REQUEST[$field] = stripslashes( $value );
81 }
82 }
83
84 # Set up Memcached
85 #
86 class MemCachedClientforWiki extends memcached {
87 function _debugprint( $text ) {
88 wfDebug( "memcached: $text\n" );
89 }
90 }
91
92 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
93 # It acts as a memcached server with no RAM, that is, all objects are
94 # cleared the moment they are set. All set operations succeed and all
95 # get operations return null.
96
97 class FakeMemCachedClient {
98 function add ($key, $val, $exp = 0) { return true; }
99 function decr ($key, $amt=1) { return null; }
100 function delete ($key, $time = 0) { return false; }
101 function disconnect_all () { }
102 function enable_compress ($enable) { }
103 function forget_dead_hosts () { }
104 function get ($key) { return null; }
105 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
106 function incr ($key, $amt=1) { return null; }
107 function replace ($key, $value, $exp=0) { return false; }
108 function run_command ($sock, $cmd) { return null; }
109 function set ($key, $value, $exp=0){ return true; }
110 function set_compress_threshold ($thresh){ }
111 function set_debug ($dbg) { }
112 function set_servers ($list) { }
113 }
114
115 if( $wgUseMemCached ) {
116 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
117 $wgMemc->set_servers( $wgMemCachedServers );
118 $wgMemc->set_debug( $wgMemCachedDebug );
119
120 # Test it to see if it's working
121 # This is necessary because otherwise wfMsg would be extremely inefficient
122 if ( !$wgMemc->set( "test", "", 0 ) ) {
123 wfDebug( "Memcached failed setup test - connection error?\n" );
124 $wgUseMemCached = false;
125 $wgMemc = new FakeMemCachedClient();
126 }
127 } else {
128 $wgMemc = new FakeMemCachedClient();
129 }
130
131 wfProfileOut( "$fname-memcached" );
132 wfProfileIn( "$fname-misc" );
133
134 include_once( "Language.php" );
135
136 $wgMessageCache = new MessageCache;
137
138 $wgLangClass = "Language" . ucfirst( $wgLanguageCode );
139 if( ! class_exists( $wgLangClass ) ) {
140 include_once( "LanguageUtf8.php" );
141 $wgLangClass = "LanguageUtf8";
142 }
143
144 $wgLang = new $wgLangClass();
145 if ( !is_object($wgLang) ) {
146 print "No language class ($wgLang)\N";
147 }
148 $wgMessageCache->initialise( $wgUseMemCached, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
149
150 $wgOut = new OutputPage();
151 wfDebug( "\n\n" );
152
153 if ( $wgUseDynamicDates ) {
154 include_once( "DateFormatter.php" );
155 global $wgDateFormatter;
156 $wgDateFormatter = new DateFormatter;
157 }
158
159 if( !$wgCommandLineMode && isset( $_COOKIE[ini_get("session.name")] ) ) {
160 User::SetupSession();
161 }
162
163 $wgBlockCache = new BlockCache( true );
164 $wgUser = User::loadFromSession();
165 $wgDeferredUpdateList = array();
166 $wgLinkCache = new LinkCache();
167 $wgMagicWords = array();
168 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
169 $wgParserCache = new ParserCache();
170 $wgParser = new Parser();
171 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
172
173 wfProfileOut( "$fname-misc" );
174 wfProfileOut( $fname );
175
176 ?>