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