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