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