f7753f08b4f33d2c8c7526e609925c836d666c0d
[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 wfProfileOut( $fname.'-misc1' );
105 wfProfileIn( $fname.'-memcached' );
106
107 $wgMemc =& wfGetMainCache();
108 $messageMemc =& wfGetMessageCacheStorage();
109 $parserMemc =& wfGetParserCacheStorage();
110
111 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
112 "\nMessage cache: " . get_class( $messageMemc ) .
113 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
114
115 wfProfileOut( $fname.'-memcached' );
116 wfProfileIn( $fname.'-SetupSession' );
117
118 if ( $wgDBprefix ) {
119 session_name( $wgDBname . '_' . $wgDBprefix . '_session' );
120 } else {
121 session_name( $wgDBname . '_session' );
122 }
123
124 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
125 User::SetupSession();
126 $wgSessionStarted = true;
127 } else {
128 $wgSessionStarted = false;
129 }
130
131 wfProfileOut( $fname.'-SetupSession' );
132 wfProfileIn( $fname.'-database' );
133
134 if ( !$wgDBservers ) {
135 $wgDBservers = array(array(
136 'host' => $wgDBserver,
137 'user' => $wgDBuser,
138 'password' => $wgDBpassword,
139 'dbname' => $wgDBname,
140 'type' => $wgDBtype,
141 'load' => 1,
142 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
143 ));
144 }
145 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
146 $wgLoadBalancer->loadMasterPos();
147
148 wfProfileOut( $fname.'-database' );
149 wfProfileIn( $fname.'-language1' );
150
151 require_once( "$IP/languages/Language.php" );
152
153 function setupLangObj(&$langclass) {
154 global $IP;
155
156 if( ! class_exists( $langclass ) ) {
157 # Default to English/UTF-8
158 $baseclass = 'LanguageUtf8';
159 require_once( "$IP/languages/$baseclass.php" );
160 $lc = strtolower(substr($langclass, 8));
161 $snip = "
162 class $langclass extends $baseclass {
163 function getVariants() {
164 return array(\"$lc\");
165 }
166
167 }";
168 eval($snip);
169 }
170
171 $lang = new $langclass();
172
173 return $lang;
174 }
175
176 # $wgLanguageCode may be changed later to fit with user preference.
177 # The content language will remain fixed as per the configuration,
178 # so let's keep it.
179 $wgContLanguageCode = $wgLanguageCode;
180 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
181
182 $wgContLang = setupLangObj( $wgContLangClass );
183 $wgContLang->initEncoding();
184
185 wfProfileOut( $fname.'-language1' );
186 wfProfileIn( $fname.'-User' );
187
188 # Skin setup functions
189 # Entries can be added to this variable during the inclusion
190 # of the extension file. Skins can then perform any necessary initialisation.
191 foreach ( $wgSkinExtensionFunctions as $func ) {
192 $func();
193 }
194
195 if( !is_object( $wgAuth ) ) {
196 require_once( 'AuthPlugin.php' );
197 $wgAuth = new AuthPlugin();
198 }
199
200 if( $wgCommandLineMode ) {
201 # Used for some maintenance scripts; user session cookies can screw things up
202 # when the database is in an in-between state.
203 $wgUser = new User();
204 # Prevent loading User settings from the DB.
205 $wgUser->setLoaded( true );
206 } else {
207 $wgUser = User::loadFromSession();
208 }
209
210 wfProfileOut( $fname.'-User' );
211 wfProfileIn( $fname.'-language2' );
212
213 // wgLanguageCode now specifically means the UI language
214 $wgLanguageCode = $wgUser->getOption('language');
215 # Validate $wgLanguageCode, which will soon be sent to an eval()
216 if( empty( $wgLanguageCode ) || preg_match( '/^[^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 include_once("$IP/languages/$wgLangClass.php");
227 wfRestoreWarnings();
228
229 $wgLang = setupLangObj( $wgLangClass );
230 }
231
232 wfProfileOut( $fname.'-language' );
233 wfProfileIn( $fname.'-MessageCache' );
234
235 $wgMessageCache = new MessageCache;
236 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
237
238 wfProfileOut( $fname.'-MessageCache' );
239
240 #
241 # I guess the warning about UI switching might still apply...
242 #
243 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
244 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
245 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
246 #
247 # To disable it, the easiest thing could be to uncomment the
248 # following; they should effectively disable the UI switch functionality
249 #
250 # $wgLangClass = $wgContLangClass;
251 # $wgLanguageCode = $wgContLanguageCode;
252 # $wgLang = $wgContLang;
253 #
254 # TODO: Need to change reference to $wgLang to $wgContLang at proper
255 # places, including namespaces, dates in signatures, magic words,
256 # and links
257 #
258 # TODO: Need to look at the issue of input/output encoding
259 #
260
261
262 wfProfileIn( $fname.'-OutputPage' );
263
264 $wgOut = new OutputPage();
265
266 wfProfileOut( $fname.'-OutputPage' );
267 wfProfileIn( $fname.'-BlockCache' );
268
269 $wgBlockCache = new BlockCache( true );
270
271 wfProfileOut( $fname.'-BlockCache' );
272 wfProfileIn( $fname.'-misc2' );
273
274 $wgDeferredUpdateList = array();
275 $wgPostCommitUpdateList = array();
276
277 $wgLinkCache = new LinkCache();
278 $wgMagicWords = array();
279 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
280 $wgParserCache = new ParserCache( $messageMemc );
281
282 if ( $wgUseXMLparser ) {
283 require_once( 'ParserXML.php' );
284 $wgParser = new ParserXML();
285 } else {
286 $wgParser = new Parser();
287 }
288 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
289 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
290 wfSeedRandom();
291
292 # Placeholders in case of DB error
293 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' );
294 $wgArticle = new Article($wgTitle);
295
296 wfProfileOut( $fname.'-misc2' );
297 wfProfileIn( $fname.'-extensions' );
298
299 # Extension setup functions for extensions other than skins
300 # Entries should be added to this variable during the inclusion
301 # of the extension file. This allows the extension to perform
302 # any necessary initialisation in the fully initialised environment
303 foreach ( $wgExtensionFunctions as $func ) {
304 $func();
305 }
306
307 wfDebug( "\n" );
308 $wgFullyInitialised = true;
309 wfProfileOut( $fname.'-extensions' );
310 wfProfileOut( $fname );
311
312 }
313 ?>