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