* Fixed magic quotes in $_REQUEST, in Setup.php
[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 print "$field: $value -> {$_REQUEST[$field]}<br>\n";
82 }
83 }
84
85 # Set up Memcached
86 #
87 class MemCachedClientforWiki extends memcached {
88 function _debugprint( $text ) {
89 wfDebug( "memcached: $text\n" );
90 }
91 }
92
93 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
94 # It acts as a memcached server with no RAM, that is, all objects are
95 # cleared the moment they are set. All set operations succeed and all
96 # get operations return null.
97
98 class FakeMemCachedClient {
99 function add ($key, $val, $exp = 0) { return true; }
100 function decr ($key, $amt=1) { return null; }
101 function delete ($key, $time = 0) { return false; }
102 function disconnect_all () { }
103 function enable_compress ($enable) { }
104 function forget_dead_hosts () { }
105 function get ($key) { return null; }
106 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
107 function incr ($key, $amt=1) { return null; }
108 function replace ($key, $value, $exp=0) { return false; }
109 function run_command ($sock, $cmd) { return null; }
110 function set ($key, $value, $exp=0){ return true; }
111 function set_compress_threshold ($thresh){ }
112 function set_debug ($dbg) { }
113 function set_servers ($list) { }
114 }
115
116 if( $wgUseMemCached ) {
117 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
118 $wgMemc->set_servers( $wgMemCachedServers );
119 $wgMemc->set_debug( $wgMemCachedDebug );
120
121 # Test it to see if it's working
122 # This is necessary because otherwise wfMsg would be extremely inefficient
123 if ( !$wgMemc->set( "test", "", 0 ) ) {
124 wfDebug( "Memcached failed setup test - connection error?\n" );
125 $wgUseMemCached = false;
126 $wgMemc = new FakeMemCachedClient();
127 }
128 } else {
129 $wgMemc = new FakeMemCachedClient();
130 }
131
132 wfProfileOut( "$fname-memcached" );
133 wfProfileIn( "$fname-misc" );
134
135 include_once( "Language.php" );
136
137 $wgMessageCache = new MessageCache;
138
139 $wgLangClass = "Language" . ucfirst( $wgLanguageCode );
140 if( ! class_exists( $wgLangClass ) ) {
141 include_once( "LanguageUtf8.php" );
142 $wgLangClass = "LanguageUtf8";
143 }
144
145 $wgLang = new $wgLangClass();
146 if ( !is_object($wgLang) ) {
147 print "No language class ($wgLang)\N";
148 }
149 $wgMessageCache->initialise( $wgUseMemCached, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
150
151 $wgOut = new OutputPage();
152 wfDebug( "\n\n" );
153
154 if ( $wgUseDynamicDates ) {
155 include_once( "DateFormatter.php" );
156 global $wgDateFormatter;
157 $wgDateFormatter = new DateFormatter;
158 }
159
160 if( !$wgCommandLineMode && isset( $_COOKIE[ini_get("session.name")] ) ) {
161 User::SetupSession();
162 }
163
164 $wgBlockCache = new BlockCache( true );
165 $wgUser = User::loadFromSession();
166 $wgDeferredUpdateList = array();
167 $wgLinkCache = new LinkCache();
168 $wgMagicWords = array();
169 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
170 $wgParserCache = new ParserCache();
171 $wgParser = new Parser();
172 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
173
174 wfProfileOut( "$fname-misc" );
175 wfProfileOut( $fname );
176
177 ?>