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