3 * Include most things that's need to customize the site
8 * This file is not a valid entry point, perform no further processing unless
11 if( defined( 'MEDIAWIKI' ) ) {
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.
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" );
24 if( !isset( $wgProfiling ) )
27 if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
28 require_once( 'Profiling.php' );
30 function wfProfileIn( $fn = '' ) {
31 global $hackwhere, $wgDBname;
33 if (function_exists("setproctitle"))
34 setproctitle($fn . " [$wgDBname]");
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]");
43 function wfGetProfilingOutput( $s, $e ) {}
44 function wfProfileClose() {}
48 wfProfileIn( $fname );
49 wfProfileIn( $fname.'-includes' );
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' );
75 if ( $wgUseDynamicDates ) {
76 require_once( 'DateFormatter.php' );
79 wfProfileOut( $fname.'-includes' );
80 wfProfileIn( $fname.'-misc1' );
83 $wgRequest = new WebRequest();
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" );
96 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
97 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
101 $wgSkipSkins[] = $wgSkipSkin;
104 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
106 wfProfileOut( $fname.'-misc1' );
107 wfProfileIn( $fname.'-memcached' );
109 $wgMemc =& wfGetMainCache();
110 $messageMemc =& wfGetMessageCacheStorage();
111 $parserMemc =& wfGetParserCacheStorage();
113 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
114 "\nMessage cache: " . get_class( $messageMemc ) .
115 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
117 wfProfileOut( $fname.'-memcached' );
118 wfProfileIn( $fname.'-SetupSession' );
121 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
122 } elseif ( $wgSharedDB ) {
123 $wgCookiePrefix = $wgSharedDB;
125 $wgCookiePrefix = $wgDBname;
128 session_name( $wgCookiePrefix . '_session' );
130 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
131 User::SetupSession();
132 $wgSessionStarted = true;
134 $wgSessionStarted = false;
137 wfProfileOut( $fname.'-SetupSession' );
138 wfProfileIn( $fname.'-database' );
140 if ( !$wgDBservers ) {
141 $wgDBservers = array(array(
142 'host' => $wgDBserver,
144 'password' => $wgDBpassword,
145 'dbname' => $wgDBname,
148 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
151 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
152 $wgLoadBalancer->loadMasterPos();
154 wfProfileOut( $fname.'-database' );
155 wfProfileIn( $fname.'-language1' );
157 require_once( "$IP/languages/Language.php" );
159 function setupLangObj($langclass) {
162 if( ! class_exists( $langclass ) ) {
163 # Default to English/UTF-8
164 $baseclass = 'LanguageUtf8';
165 require_once( "$IP/languages/$baseclass.php" );
166 $lc = strtolower(substr($langclass, 8));
168 class $langclass extends $baseclass {
169 function getVariants() {
170 return array(\"$lc\");
177 $lang = new $langclass();
182 # $wgLanguageCode may be changed later to fit with user preference.
183 # The content language will remain fixed as per the configuration,
185 $wgContLanguageCode = $wgLanguageCode;
186 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
188 $wgContLang = setupLangObj( $wgContLangClass );
189 $wgContLang->initEncoding();
191 wfProfileOut( $fname.'-language1' );
192 wfProfileIn( $fname.'-User' );
194 # Skin setup functions
195 # Entries can be added to this variable during the inclusion
196 # of the extension file. Skins can then perform any necessary initialisation.
197 foreach ( $wgSkinExtensionFunctions as $func ) {
201 if( !is_object( $wgAuth ) ) {
202 require_once( 'AuthPlugin.php' );
203 $wgAuth = new AuthPlugin();
206 if( $wgCommandLineMode ) {
207 # Used for some maintenance scripts; user session cookies can screw things up
208 # when the database is in an in-between state.
209 $wgUser = new User();
210 # Prevent loading User settings from the DB.
211 $wgUser->setLoaded( true );
214 wfRunHooks('AutoAuthenticate',array(&$wgUser));
215 if ($wgUser === null) {
216 $wgUser = User::loadFromSession();
220 wfProfileOut( $fname.'-User' );
221 wfProfileIn( $fname.'-language2' );
223 // wgLanguageCode now specifically means the UI language
224 $wgLanguageCode = $wgRequest->getText('uselang', '');
225 if ($wgLanguageCode == '')
226 $wgLanguageCode = $wgUser->getOption('language');
227 # Validate $wgLanguageCode, which will soon be sent to an eval()
228 if( empty( $wgLanguageCode ) || !preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
229 $wgLanguageCode = $wgContLanguageCode;
232 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
234 if( $wgLangClass == $wgContLangClass ) {
235 $wgLang = &$wgContLang;
237 wfSuppressWarnings();
238 include_once("$IP/languages/$wgLangClass.php");
241 $wgLang = setupLangObj( $wgLangClass );
244 wfProfileOut( $fname.'-language2' );
245 wfProfileIn( $fname.'-MessageCache' );
247 $wgMessageCache = new MessageCache;
248 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
250 wfProfileOut( $fname.'-MessageCache' );
253 # I guess the warning about UI switching might still apply...
255 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
256 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
257 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
259 # To disable it, the easiest thing could be to uncomment the
260 # following; they should effectively disable the UI switch functionality
262 # $wgLangClass = $wgContLangClass;
263 # $wgLanguageCode = $wgContLanguageCode;
264 # $wgLang = $wgContLang;
266 # TODO: Need to change reference to $wgLang to $wgContLang at proper
267 # places, including namespaces, dates in signatures, magic words,
270 # TODO: Need to look at the issue of input/output encoding
274 wfProfileIn( $fname.'-OutputPage' );
276 $wgOut = new OutputPage();
278 wfProfileOut( $fname.'-OutputPage' );
279 wfProfileIn( $fname.'-BlockCache' );
281 $wgBlockCache = new BlockCache( true );
283 wfProfileOut( $fname.'-BlockCache' );
284 wfProfileIn( $fname.'-misc2' );
286 $wgDeferredUpdateList = array();
287 $wgPostCommitUpdateList = array();
289 $wgLinkCache = new LinkCache();
290 $wgMagicWords = array();
291 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
292 $wgParserCache = new ParserCache( $messageMemc );
294 if ( $wgUseXMLparser ) {
295 require_once( 'ParserXML.php' );
296 $wgParser = new ParserXML();
298 $wgParser = new Parser();
300 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
301 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
304 # Placeholders in case of DB error
305 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' );
306 $wgArticle = new Article($wgTitle);
308 wfProfileOut( $fname.'-misc2' );
309 wfProfileIn( $fname.'-extensions' );
311 # Extension setup functions for extensions other than skins
312 # Entries should be added to this variable during the inclusion
313 # of the extension file. This allows the extension to perform
314 # any necessary initialisation in the fully initialised environment
315 foreach ( $wgExtensionFunctions as $func ) {
320 $wgFullyInitialised = true;
321 wfProfileOut( $fname.'-extensions' );
322 wfProfileOut( $fname );