1b31c1881be65dfacc83adda2c1b41d192289cf4
[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 }
46
47 $fname = 'Setup.php';
48 wfProfileIn( $fname );
49 wfProfileIn( $fname.'-includes' );
50
51 require_once( 'GlobalFunctions.php' );
52 require_once( 'Hooks.php' );
53 require_once( 'Namespace.php' );
54 require_once( 'RecentChange.php' );
55 require_once( 'User.php' );
56 require_once( 'Skin.php' );
57 require_once( 'OutputPage.php' );
58 require_once( 'LinkCache.php' );
59 require_once( 'Title.php' );
60 require_once( 'Article.php' );
61 require_once( 'MagicWord.php' );
62 require_once( 'Block.php' );
63 require_once( 'MessageCache.php' );
64 require_once( 'BlockCache.php' );
65 require_once( 'Parser.php' );
66 require_once( 'ParserCache.php' );
67 require_once( 'WebRequest.php' );
68 require_once( 'LoadBalancer.php' );
69 require_once( 'HistoryBlob.php' );
70 require_once( 'ProxyTools.php' );
71 require_once( 'ObjectCache.php' );
72 require_once( 'WikiError.php' );
73 require_once( 'SpecialPage.php' );
74
75 if ( $wgUseDynamicDates ) {
76 require_once( 'DateFormatter.php' );
77 }
78
79 wfProfileOut( $fname.'-includes' );
80 wfProfileIn( $fname.'-misc1' );
81
82 $wgIP = wfGetIP();
83 $wgRequest = new WebRequest();
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 session_name( $wgDBname . '_' . $wgDBprefix . '_session' );
122 } else {
123 session_name( $wgDBname . '_session' );
124 }
125
126 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
127 User::SetupSession();
128 $wgSessionStarted = true;
129 } else {
130 $wgSessionStarted = false;
131 }
132
133 wfProfileOut( $fname.'-SetupSession' );
134 wfProfileIn( $fname.'-database' );
135
136 if ( !$wgDBservers ) {
137 $wgDBservers = array(array(
138 'host' => $wgDBserver,
139 'user' => $wgDBuser,
140 'password' => $wgDBpassword,
141 'dbname' => $wgDBname,
142 'type' => $wgDBtype,
143 'load' => 1,
144 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
145 ));
146 }
147 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
148 $wgLoadBalancer->loadMasterPos();
149
150 wfProfileOut( $fname.'-database' );
151 wfProfileIn( $fname.'-language1' );
152
153 require_once( "$IP/languages/Language.php" );
154
155 function setupLangObj(&$langclass) {
156 global $IP;
157
158 if( ! class_exists( $langclass ) ) {
159 # Default to English/UTF-8
160 $baseclass = 'LanguageUtf8';
161 require_once( "$IP/languages/$baseclass.php" );
162 $lc = strtolower(substr($langclass, 8));
163 $snip = "
164 class $langclass extends $baseclass {
165 function getVariants() {
166 return array(\"$lc\");
167 }
168
169 }";
170 eval($snip);
171 }
172
173 $lang = new $langclass();
174
175 return $lang;
176 }
177
178 # $wgLanguageCode may be changed later to fit with user preference.
179 # The content language will remain fixed as per the configuration,
180 # so let's keep it.
181 $wgContLanguageCode = $wgLanguageCode;
182 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
183
184 $wgContLang = setupLangObj( $wgContLangClass );
185 $wgContLang->initEncoding();
186
187 wfProfileOut( $fname.'-language1' );
188 wfProfileIn( $fname.'-User' );
189
190 # Skin setup functions
191 # Entries can be added to this variable during the inclusion
192 # of the extension file. Skins can then perform any necessary initialisation.
193 foreach ( $wgSkinExtensionFunctions as $func ) {
194 $func();
195 }
196
197 if( !is_object( $wgAuth ) ) {
198 require_once( 'AuthPlugin.php' );
199 $wgAuth = new AuthPlugin();
200 }
201
202 if( $wgCommandLineMode ) {
203 # Used for some maintenance scripts; user session cookies can screw things up
204 # when the database is in an in-between state.
205 $wgUser = new User();
206 # Prevent loading User settings from the DB.
207 $wgUser->setLoaded( true );
208 } else {
209 $wgUser = User::loadFromSession();
210 }
211
212 wfProfileOut( $fname.'-User' );
213 wfProfileIn( $fname.'-language2' );
214
215 // wgLanguageCode now specifically means the UI language
216 $wgLanguageCode = $wgUser->getOption('language');
217 # Validate $wgLanguageCode, which will soon be sent to an eval()
218 if( empty( $wgLanguageCode ) || preg_match( '/^[^a-z-]*$/', $wgLanguageCode ) ) {
219 $wgLanguageCode = $wgContLanguageCode;
220 }
221
222 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
223
224 if( $wgLangClass == $wgContLangClass ) {
225 $wgLang = &$wgContLang;
226 } else {
227 wfSuppressWarnings();
228 include_once("$IP/languages/$wgLangClass.php");
229 wfRestoreWarnings();
230
231 $wgLang = setupLangObj( $wgLangClass );
232 }
233
234 wfProfileOut( $fname.'-language' );
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.'-BlockCache' );
270
271 $wgBlockCache = new BlockCache( true );
272
273 wfProfileOut( $fname.'-BlockCache' );
274 wfProfileIn( $fname.'-misc2' );
275
276 $wgDeferredUpdateList = array();
277 $wgPostCommitUpdateList = array();
278
279 $wgLinkCache = new LinkCache();
280 $wgMagicWords = array();
281 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
282 $wgParserCache = new ParserCache( $messageMemc );
283
284 if ( $wgUseXMLparser ) {
285 require_once( 'ParserXML.php' );
286 $wgParser = new ParserXML();
287 } else {
288 $wgParser = new Parser();
289 }
290 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
291 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
292 wfSeedRandom();
293
294 # Placeholders in case of DB error
295 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' );
296 $wgArticle = new Article($wgTitle);
297
298 wfProfileOut( $fname.'-misc2' );
299 wfProfileIn( $fname.'-extensions' );
300
301 # Extension setup functions for extensions other than skins
302 # Entries should be added to this variable during the inclusion
303 # of the extension file. This allows the extension to perform
304 # any necessary initialisation in the fully initialised environment
305 foreach ( $wgExtensionFunctions as $func ) {
306 $func();
307 }
308
309 wfDebug( "\n" );
310 $wgFullyInitialised = true;
311 wfProfileOut( $fname.'-extensions' );
312 wfProfileOut( $fname );
313
314 }
315 ?>