AutoLoad LinkCache & LinkBatch
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 * @package MediaWiki
5 */
6
7 /**
8 * This file is not a valid entry point, perform no further processing unless
9 * MEDIAWIKI is defined
10 */
11 if( defined( 'MEDIAWIKI' ) ) {
12
13 # The main wiki script and things like database
14 # conversion and maintenance scripts all share a
15 # common setup of including lots of classes and
16 # setting up a few globals.
17 #
18
19 // Check to see if we are at the file scope
20 if ( !isset( $wgVersion ) ) {
21 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
22 die( -1 );
23 }
24
25 if( !isset( $wgProfiling ) )
26 $wgProfiling = false;
27
28 if ( function_exists( 'wfProfileIn' ) ) {
29 /* nada, everything should be done already */
30 } elseif ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
31 require_once( 'Profiling.php' );
32 $wgProfiling = true;
33 if ($wgProfilerType == "") {
34 $wgProfiler = new Profiler();
35 } else {
36 $prclass="Profiler{$wgProfilerType}";
37 require_once( $prclass.".php" );
38 $wgProfiler = new $prclass();
39 }
40 } else {
41 require_once( 'ProfilerStub.php' );
42 }
43
44 $fname = 'Setup.php';
45 wfProfileIn( $fname );
46 wfProfileIn( $fname.'-includes' );
47
48 require_once( 'AutoLoader.php' );
49 require_once( 'GlobalFunctions.php' );
50 require_once( 'Hooks.php' );
51 require_once( 'Namespace.php' );
52 require_once( 'User.php' );
53 require_once( 'Skin.php' );
54 require_once( 'OutputPage.php' );
55 require_once( 'Title.php' );
56 require_once( 'MagicWord.php' );
57 require_once( 'Block.php' );
58 require_once( 'MessageCache.php' );
59 require_once( 'Parser.php' );
60 require_once( 'ParserCache.php' );
61 require_once( 'WebRequest.php' );
62 require_once( 'LoadBalancer.php' );
63 require_once( 'HistoryBlob.php' );
64 require_once( 'ProxyTools.php' );
65 require_once( 'ObjectCache.php' );
66 require_once( 'WikiError.php' );
67 require_once( 'SpecialPage.php' );
68
69 if ( $wgUseDynamicDates ) {
70 require_once( 'DateFormatter.php' );
71 }
72
73 wfProfileOut( $fname.'-includes' );
74 wfProfileIn( $fname.'-misc1' );
75
76 $wgIP = false; # Load on demand
77 $wgRequest = new WebRequest();
78 if ( function_exists( 'posix_uname' ) ) {
79 $wguname = posix_uname();
80 $wgNodeName = $wguname['nodename'];
81 } else {
82 $wgNodeName = '';
83 }
84
85 # Useful debug output
86 if ( $wgCommandLineMode ) {
87 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
88 } elseif ( function_exists( 'getallheaders' ) ) {
89 wfDebug( "\n\nStart request\n" );
90 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
91 $headers = getallheaders();
92 foreach ($headers as $name => $value) {
93 wfDebug( "$name: $value\n" );
94 }
95 wfDebug( "\n" );
96 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
97 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
98 }
99
100 if ( $wgSkipSkin ) {
101 $wgSkipSkins[] = $wgSkipSkin;
102 }
103
104 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
105
106 wfProfileOut( $fname.'-misc1' );
107 wfProfileIn( $fname.'-memcached' );
108
109 $wgMemc =& wfGetMainCache();
110 $messageMemc =& wfGetMessageCacheStorage();
111 $parserMemc =& wfGetParserCacheStorage();
112
113 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
114 "\nMessage cache: " . get_class( $messageMemc ) .
115 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
116
117 wfProfileOut( $fname.'-memcached' );
118 wfProfileIn( $fname.'-SetupSession' );
119
120 if ( $wgDBprefix ) {
121 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
122 } elseif ( $wgSharedDB ) {
123 $wgCookiePrefix = $wgSharedDB;
124 } else {
125 $wgCookiePrefix = $wgDBname;
126 }
127
128 # If session.auto_start is there, we can't touch session name
129 #
130 if (!ini_get('session.auto_start')) {
131 session_name( $wgCookiePrefix . '_session' );
132 }
133
134 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
135 wfIncrStats( 'request_with_session' );
136 User::SetupSession();
137 $wgSessionStarted = true;
138 } else {
139 wfIncrStats( 'request_without_session' );
140 $wgSessionStarted = false;
141 }
142
143 wfProfileOut( $fname.'-SetupSession' );
144 wfProfileIn( $fname.'-database' );
145
146 if ( !$wgDBservers ) {
147 $wgDBservers = array(array(
148 'host' => $wgDBserver,
149 'user' => $wgDBuser,
150 'password' => $wgDBpassword,
151 'dbname' => $wgDBname,
152 'type' => $wgDBtype,
153 'load' => 1,
154 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
155 ));
156 }
157 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
158 $wgLoadBalancer->loadMasterPos();
159
160 wfProfileOut( $fname.'-database' );
161 wfProfileIn( $fname.'-language1' );
162
163 require_once( "$IP/languages/Language.php" );
164
165 function setupLangObj($langclass) {
166 global $IP;
167
168 if( ! class_exists( $langclass ) ) {
169 # Default to English/UTF-8
170 $baseclass = 'LanguageUtf8';
171 require_once( "$IP/languages/$baseclass.php" );
172 $lc = strtolower(substr($langclass, 8));
173 $snip = "
174 class $langclass extends $baseclass {
175 function getVariants() {
176 return array(\"$lc\");
177 }
178
179 }";
180 eval($snip);
181 }
182
183 $lang = new $langclass();
184
185 return $lang;
186 }
187
188 # $wgLanguageCode may be changed later to fit with user preference.
189 # The content language will remain fixed as per the configuration,
190 # so let's keep it.
191 $wgContLanguageCode = $wgLanguageCode;
192 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
193
194 $wgContLang = setupLangObj( $wgContLangClass );
195 $wgContLang->initEncoding();
196
197 wfProfileOut( $fname.'-language1' );
198 wfProfileIn( $fname.'-User' );
199
200 # Skin setup functions
201 # Entries can be added to this variable during the inclusion
202 # of the extension file. Skins can then perform any necessary initialisation.
203 #
204 foreach ( $wgSkinExtensionFunctions as $func ) {
205 call_user_func( $func );
206 }
207
208 if( !is_object( $wgAuth ) ) {
209 require_once( 'AuthPlugin.php' );
210 $wgAuth = new AuthPlugin();
211 }
212
213 if( $wgCommandLineMode ) {
214 # Used for some maintenance scripts; user session cookies can screw things up
215 # when the database is in an in-between state.
216 $wgUser = new User();
217 # Prevent loading User settings from the DB.
218 $wgUser->setLoaded( true );
219 } else {
220 $wgUser = null;
221 wfRunHooks('AutoAuthenticate',array(&$wgUser));
222 if ($wgUser === null) {
223 $wgUser = User::loadFromSession();
224 }
225 }
226
227 wfProfileOut( $fname.'-User' );
228 wfProfileIn( $fname.'-language2' );
229
230 // wgLanguageCode now specifically means the UI language
231 $wgLanguageCode = $wgRequest->getText('uselang', '');
232 if ($wgLanguageCode == '')
233 $wgLanguageCode = $wgUser->getOption('language');
234 # Validate $wgLanguageCode, which will soon be sent to an eval()
235 if( empty( $wgLanguageCode ) || !preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
236 $wgLanguageCode = $wgContLanguageCode;
237 }
238
239 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
240
241 if( $wgLangClass == $wgContLangClass ) {
242 $wgLang = &$wgContLang;
243 } else {
244 wfSuppressWarnings();
245 // Preload base classes to work around APC/PHP5 bug
246 include_once("$IP/languages/$wgLangClass.deps.php");
247 include_once("$IP/languages/$wgLangClass.php");
248 wfRestoreWarnings();
249
250 $wgLang = setupLangObj( $wgLangClass );
251 }
252
253 wfProfileOut( $fname.'-language2' );
254 wfProfileIn( $fname.'-MessageCache' );
255
256 $wgMessageCache = new MessageCache;
257 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
258
259 wfProfileOut( $fname.'-MessageCache' );
260
261 #
262 # I guess the warning about UI switching might still apply...
263 #
264 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
265 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
266 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
267 #
268 # To disable it, the easiest thing could be to uncomment the
269 # following; they should effectively disable the UI switch functionality
270 #
271 # $wgLangClass = $wgContLangClass;
272 # $wgLanguageCode = $wgContLanguageCode;
273 # $wgLang = $wgContLang;
274 #
275 # TODO: Need to change reference to $wgLang to $wgContLang at proper
276 # places, including namespaces, dates in signatures, magic words,
277 # and links
278 #
279 # TODO: Need to look at the issue of input/output encoding
280 #
281
282
283 wfProfileIn( $fname.'-OutputPage' );
284
285 $wgOut = new OutputPage();
286
287 wfProfileOut( $fname.'-OutputPage' );
288 wfProfileIn( $fname.'-misc2' );
289
290 $wgDeferredUpdateList = array();
291 $wgPostCommitUpdateList = array();
292
293 $wgMagicWords = array();
294 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
295
296 if ( $wgUseXMLparser ) {
297 require_once( 'ParserXML.php' );
298 $wgParser = new ParserXML();
299 } else {
300 $wgParser = new Parser();
301 }
302 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
303 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
304 wfSeedRandom();
305
306 # Placeholders in case of DB error
307 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' );
308 $wgArticle = new Article($wgTitle);
309
310 wfProfileOut( $fname.'-misc2' );
311 wfProfileIn( $fname.'-extensions' );
312
313 # Extension setup functions for extensions other than skins
314 # Entries should be added to this variable during the inclusion
315 # of the extension file. This allows the extension to perform
316 # any necessary initialisation in the fully initialised environment
317 foreach ( $wgExtensionFunctions as $func ) {
318 call_user_func( $func );
319 }
320
321 // For compatibility
322 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
323 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
324 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
325 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
326
327
328 wfDebug( "\n" );
329 $wgFullyInitialised = true;
330 wfProfileOut( $fname.'-extensions' );
331 wfProfileOut( $fname );
332
333 }
334 ?>