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