Overridable debug printouts in new memcached client.
[lhc/web/wiklou.git] / includes / Setup.php
1 <?
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 $fname = "Setup.php";
21 wfProfileIn( $fname );
22 global $wgUseDynamicDates;
23 wfProfileIn( "$fname-includes" );
24
25 include_once( "GlobalFunctions.php" );
26 include_once( "Namespace.php" );
27 include_once( "RecentChange.php" );
28 include_once( "Skin.php" );
29 include_once( "OutputPage.php" );
30 include_once( "User.php" );
31 include_once( "LinkCache.php" );
32 include_once( "Title.php" );
33 include_once( "Article.php" );
34 include_once( "MagicWord.php" );
35 include_once( "memcached-client.php" );
36 include_once( "Block.php" );
37 include_once( "SearchEngine.php" );
38 include_once( "DifferenceEngine.php" );
39 include_once( "MessageCache.php" );
40
41 wfProfileOut( "$fname-includes" );
42 wfProfileIn( "$fname-memcached" );
43 global $wgUser, $wgLang, $wgOut, $wgTitle;
44 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
45 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
46 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
47 global $wgMsgCacheExpiry, $wgDBname, $wgCommandLineMode;
48
49 class MemCachedClientforWiki extends memcached {
50 function _debugprint( $text ) {
51 wfDebug( "memcached: $text\n" );
52 }
53 }
54
55 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
56 # It acts as a memcached server with no RAM, that is, all objects are
57 # cleared the moment they are set. All set operations succeed and all
58 # get operations return null.
59
60 class FakeMemCachedClient {
61 function add ($key, $val, $exp = 0) { return true; }
62 function decr ($key, $amt=1) { return null; }
63 function delete ($key, $time = 0) { return false; }
64 function disconnect_all () { }
65 function enable_compress ($enable) { }
66 function forget_dead_hosts () { }
67 function get ($key) { return null; }
68 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
69 function incr ($key, $amt=1) { return null; }
70 function replace ($key, $value, $exp=0) { return false; }
71 function run_command ($sock, $cmd) { return null; }
72 function set ($key, $value, $exp=0){ return true; }
73 function set_compress_threshold ($thresh){ }
74 function set_debug ($dbg) { }
75 function set_servers ($list) { }
76 }
77
78 if( $wgUseMemCached ) {
79 $wgMemc = new MemCachedClientforWiki( array('persistant' => true) );
80 $wgMemc->set_servers( $wgMemCachedServers );
81 $wgMemc->set_debug( $wgMemCachedDebug );
82
83 # Test it to see if it's working
84 # This is necessary because otherwise wfMsg would be extremely inefficient
85 if ( !$wgMemc->set( "test", "", 0 ) ) {
86 wfDebug( "Memcached failed setup test - connection error?\n" );
87 $wgUseMemCached = false;
88 $wgMemc = new FakeMemCachedClient();
89 }
90 } else {
91 $wgMemc = new FakeMemCachedClient();
92 }
93
94 wfProfileOut( "$fname-memcached" );
95 wfProfileIn( "$fname-misc" );
96
97 include_once( "Language.php" );
98
99 $wgMessageCache = new MessageCache;
100
101 $wgOut = new OutputPage();
102 wfDebug( "\n\n" );
103
104 $wgLangClass = "Language" . ucfirst( $wgLanguageCode );
105 if( ! class_exists( $wgLangClass ) ) {
106 include_once( "LanguageUtf8.php" );
107 $wgLangClass = "LanguageUtf8";
108 }
109
110 $wgLang = new $wgLangClass();
111 if ( !is_object($wgLang) ) {
112 print "No language class ($wgLang)\N";
113 }
114 $wgMessageCache->initialise( $wgUseMemCached, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
115
116 if ( $wgUseDynamicDates ) {
117 include_once( "DateFormatter.php" );
118 global $wgDateFormatter;
119 $wgDateFormatter = new DateFormatter;
120 }
121
122 if( !$wgCommandLineMode ) {
123 if( $wgSessionsInMemcached ) {
124 include_once( "MemcachedSessions.php" );
125 }
126 session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
127 session_cache_limiter( "private, must-revalidate" );
128 session_start();
129 session_register( "wsUserID" );
130 session_register( "wsUserName" );
131 session_register( "wsUserPassword" );
132 session_register( "wsUploadFiles" );
133 }
134
135 $wgUser = User::loadFromSession();
136 $wgDeferredUpdateList = array();
137 $wgLinkCache = new LinkCache();
138 $wgMagicWords = array();
139 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
140
141 wfProfileOut( "$fname-misc" );
142 wfProfileOut( $fname );
143
144 ?>