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