* Parser.php was being included twice in a row
[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
73 if ( $wgUseDynamicDates ) {
74 require_once( 'DateFormatter.php' );
75 }
76
77 wfProfileOut( $fname.'-includes' );
78 wfProfileIn( $fname.'-misc1' );
79
80 $wgIP = wfGetIP();
81 $wgRequest = new WebRequest();
82
83 # Useful debug output
84 if ( $wgCommandLineMode ) {
85 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
86 } elseif ( function_exists( 'getallheaders' ) ) {
87 wfDebug( "\n\nStart request\n" );
88 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
89 $headers = getallheaders();
90 foreach ($headers as $name => $value) {
91 wfDebug( "$name: $value\n" );
92 }
93 wfDebug( "\n" );
94 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
95 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
96 }
97
98 # Disable linkscc except if the old existence check method is enabled
99 if (!$wgUseOldExistenceCheck) {
100 $wgEnablePersistentLC = false;
101 }
102
103 wfProfileOut( $fname.'-misc1' );
104 wfProfileIn( $fname.'-memcached' );
105
106 $wgMemc =& wfGetMainCache();
107 $messageMemc =& wfGetMessageCacheStorage();
108 $parserMemc =& wfGetParserCacheStorage();
109
110 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
111 "\nMessage cache: " . get_class( $messageMemc ) .
112 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
113
114 wfProfileOut( $fname.'-memcached' );
115 wfProfileIn( $fname.'-SetupSession' );
116
117 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) || isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
118 User::SetupSession();
119 $wgSessionStarted = true;
120 } else {
121 $wgSessionStarted = false;
122 }
123
124 wfProfileOut( $fname.'-SetupSession' );
125 wfProfileIn( $fname.'-database' );
126
127 if ( !$wgDBservers ) {
128 $wgDBservers = array(array(
129 'host' => $wgDBserver,
130 'user' => $wgDBuser,
131 'password' => $wgDBpassword,
132 'dbname' => $wgDBname,
133 'type' => $wgDBtype,
134 'load' => 1,
135 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
136 ));
137 }
138 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
139 $wgLoadBalancer->loadMasterPos();
140
141 wfProfileOut( $fname.'-database' );
142 wfProfileIn( $fname.'-language1' );
143
144 require_once( "$IP/languages/Language.php" );
145
146 wfProfileOut( $fname.'-language1' );
147 wfProfileIn( $fname.'-User' );
148
149 # Skin setup functions
150 # Entries can be added to this variable during the inclusion
151 # of the extension file. Skins can then perform any necessary initialisation.
152 foreach ( $wgSkinExtensionFunctions as $func ) {
153 $func();
154 }
155
156 if( !is_object( $wgAuth ) ) {
157 require_once( 'AuthPlugin.php' );
158 $wgAuth = new AuthPlugin();
159 }
160
161 if( $wgCommandLineMode ) {
162 # Used for some maintenance scripts; user session cookies can screw things up
163 # when the database is in an in-between state.
164 $wgUser = new User();
165 # Prevent loading User settings from the DB.
166 $wgUser->setLoaded( true );
167 } else {
168 $wgUser = User::loadFromSession();
169 }
170
171 wfProfileOut( $fname.'-User' );
172 wfProfileIn( $fname.'-language2' );
173
174 function setupLangObj(&$langclass) {
175 global $IP;
176
177 if( ! class_exists( $langclass ) ) {
178 # Default to English/UTF-8
179 $baseclass = 'LanguageUtf8';
180 require_once( "$IP/languages/$baseclass.php" );
181 $lc = strtolower(substr($langclass, 8));
182 $snip = "
183 class $langclass extends $baseclass {
184 function getVariants() {
185 return array(\"$lc\");
186 }
187
188 }";
189 eval($snip);
190 }
191
192 $lang = new $langclass();
193
194 return $lang;
195 }
196
197 # $wgLanguageCode may be changed later to fit with user preference.
198 # The content language will remain fixed as per the configuration,
199 # so let's keep it.
200 $wgContLanguageCode = $wgLanguageCode;
201 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
202
203 $wgContLang = setupLangObj( $wgContLangClass );
204 $wgContLang->initEncoding();
205
206 // set default user option from content language
207 if( !$wgUser->mDataLoaded ) {
208 $wgUser->loadDefaultFromLanguage();
209 }
210
211 // wgLanguageCode now specifically means the UI language
212 $wgLanguageCode = $wgUser->getOption('language');
213 # Validate $wgLanguageCode, which will soon be sent to an eval()
214 if( empty( $wgLanguageCode ) || !preg_match( '/^[a-z\-]*$/', $wgLanguageCode ) ) {
215 $wgLanguageCode = $wgContLanguageCode;
216 }
217
218 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
219
220 if( $wgLangClass == $wgContLangClass ) {
221 $wgLang = &$wgContLang;
222 } else {
223 wfSuppressWarnings();
224 include_once("$IP/languages/$wgLangClass.php");
225 wfRestoreWarnings();
226
227 $wgLang = setupLangObj( $wgLangClass );
228 }
229
230 wfProfileOut( $fname.'-language' );
231 wfProfileIn( $fname.'-MessageCache' );
232
233 $wgMessageCache = new MessageCache;
234 $wgMessageCache->initialise( $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.'-BlockCache' );
266
267 $wgBlockCache = new BlockCache( true );
268
269 wfProfileOut( $fname.'-BlockCache' );
270 wfProfileIn( $fname.'-misc2' );
271
272 $wgDeferredUpdateList = array();
273 $wgPostCommitUpdateList = array();
274
275 $wgLinkCache = new LinkCache();
276 $wgMagicWords = array();
277 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
278 $wgParserCache = new ParserCache( $messageMemc );
279
280 if ( $wgUseXMLparser ) {
281 require_once( 'ParserXML.php' );
282 $wgParser = new ParserXML();
283 } else {
284 $wgParser = new Parser();
285 }
286 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
287 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
288 wfSeedRandom();
289
290 # Placeholders in case of DB error
291 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' );
292 $wgArticle = new Article($wgTitle);
293
294 wfProfileOut( $fname.'-misc2' );
295 wfProfileIn( $fname.'-extensions' );
296
297 # Extension setup functions for extensions other than skins
298 # Entries should be added to this variable during the inclusion
299 # of the extension file. This allows the extension to perform
300 # any necessary initialisation in the fully initialised environment
301 foreach ( $wgExtensionFunctions as $func ) {
302 $func();
303 }
304
305 wfDebug( "\n" );
306 $wgFullyInitialised = true;
307 wfProfileOut( $fname.'-extensions' );
308 wfProfileOut( $fname );
309
310 }
311 ?>