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