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