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' );
29 if ($wgProfilerType == "") {
30 $wgProfiler = new Profiler();
32 $prclass="Profiler{$wgProfilerType}";
33 require_once( $prclass.".php" );
34 $wgProfiler = new $prclass();
37 function wfProfileIn( $fn = '' ) {
38 global $hackwhere, $wgDBname;
40 if (function_exists("setproctitle"))
41 setproctitle($fn . " [$wgDBname]");
43 function wfProfileOut( $fn = '' ) {
44 global $hackwhere, $wgDBname;
45 if (count($hackwhere))
46 array_pop($hackwhere);
47 if (function_exists("setproctitle") && count($hackwhere))
48 setproctitle($hackwhere[count($hackwhere)-1] . " [$wgDBname]");
50 function wfGetProfilingOutput( $s, $e ) {}
51 function wfProfileClose() {}
52 function wfLogProfilingData() {}
56 wfProfileIn( $fname );
57 wfProfileIn( $fname.'-includes' );
59 require_once( 'GlobalFunctions.php' );
60 require_once( 'Hooks.php' );
61 require_once( 'Namespace.php' );
62 require_once( 'RecentChange.php' );
63 require_once( 'User.php' );
64 require_once( 'Skin.php' );
65 require_once( 'OutputPage.php' );
66 require_once( 'LinkCache.php' );
67 require_once( 'Title.php' );
68 require_once( 'Article.php' );
69 require_once( 'MagicWord.php' );
70 require_once( 'Block.php' );
71 require_once( 'MessageCache.php' );
72 require_once( 'Parser.php' );
73 require_once( 'ParserCache.php' );
74 require_once( 'WebRequest.php' );
75 require_once( 'LoadBalancer.php' );
76 require_once( 'HistoryBlob.php' );
77 require_once( 'ProxyTools.php' );
78 require_once( 'ObjectCache.php' );
79 require_once( 'WikiError.php' );
80 require_once( 'SpecialPage.php' );
82 if ( $wgUseDynamicDates ) {
83 require_once( 'DateFormatter.php' );
86 wfProfileOut( $fname.'-includes' );
87 wfProfileIn( $fname.'-misc1' );
89 $wgIP = false; # Load on demand
90 $wgRequest = new WebRequest();
93 if ( $wgCommandLineMode ) {
94 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
95 } elseif ( function_exists( 'getallheaders' ) ) {
96 wfDebug( "\n\nStart request\n" );
97 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
98 $headers = getallheaders();
99 foreach ($headers as $name => $value) {
100 wfDebug( "$name: $value\n" );
103 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
104 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
108 $wgSkipSkins[] = $wgSkipSkin;
111 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
113 wfProfileOut( $fname.'-misc1' );
114 wfProfileIn( $fname.'-memcached' );
116 $wgMemc =& wfGetMainCache();
117 $messageMemc =& wfGetMessageCacheStorage();
118 $parserMemc =& wfGetParserCacheStorage();
120 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
121 "\nMessage cache: " . get_class( $messageMemc ) .
122 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
124 wfProfileOut( $fname.'-memcached' );
125 wfProfileIn( $fname.'-SetupSession' );
128 session_name( $wgDBname . '_' . $wgDBprefix . '_session' );
130 session_name( $wgDBname . '_session' );
133 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
134 User
::SetupSession();
135 $wgSessionStarted = true;
137 $wgSessionStarted = false;
140 wfProfileOut( $fname.'-SetupSession' );
141 wfProfileIn( $fname.'-database' );
143 if ( !$wgDBservers ) {
144 $wgDBservers = array(array(
145 'host' => $wgDBserver,
147 'password' => $wgDBpassword,
148 'dbname' => $wgDBname,
151 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
154 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
155 $wgLoadBalancer->loadMasterPos();
157 wfProfileOut( $fname.'-database' );
158 wfProfileIn( $fname.'-language1' );
160 require_once( "$IP/languages/Language.php" );
162 function setupLangObj($langclass) {
165 if( ! class_exists( $langclass ) ) {
166 # Default to English/UTF-8
167 $baseclass = 'LanguageUtf8';
168 require_once( "$IP/languages/$baseclass.php" );
169 $lc = strtolower(substr($langclass, 8));
171 class $langclass extends $baseclass {
172 function getVariants() {
173 return array(\"$lc\");
180 $lang = new $langclass();
185 # $wgLanguageCode may be changed later to fit with user preference.
186 # The content language will remain fixed as per the configuration,
188 $wgContLanguageCode = $wgLanguageCode;
189 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
191 $wgContLang = setupLangObj( $wgContLangClass );
192 $wgContLang->initEncoding();
194 wfProfileOut( $fname.'-language1' );
195 wfProfileIn( $fname.'-User' );
197 # Skin setup functions
198 # Entries can be added to this variable during the inclusion
199 # of the extension file. Skins can then perform any necessary initialisation.
200 foreach ( $wgSkinExtensionFunctions as $func ) {
201 require_once 'PersistentObject.php';
203 call_user_func( $func );
206 if( !is_object( $wgAuth ) ) {
207 require_once( 'AuthPlugin.php' );
208 $wgAuth = new AuthPlugin();
211 if( $wgCommandLineMode ) {
212 # Used for some maintenance scripts; user session cookies can screw things up
213 # when the database is in an in-between state.
214 $wgUser = new User();
215 # Prevent loading User settings from the DB.
216 $wgUser->setLoaded( true );
219 wfRunHooks('AutoAuthenticate',array(&$wgUser));
220 if ($wgUser === null) {
221 $wgUser = User
::loadFromSession();
225 wfProfileOut( $fname.'-User' );
226 wfProfileIn( $fname.'-language2' );
228 // wgLanguageCode now specifically means the UI language
229 $wgLanguageCode = $wgRequest->getText('uselang', '');
230 if ($wgLanguageCode == '')
231 $wgLanguageCode = $wgUser->getOption('language');
232 # Validate $wgLanguageCode, which will soon be sent to an eval()
233 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
234 $wgLanguageCode = $wgContLanguageCode;
237 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
239 if( $wgLangClass == $wgContLangClass ) {
240 $wgLang = &$wgContLang;
242 wfSuppressWarnings();
243 include_once("$IP/languages/$wgLangClass.php");
246 $wgLang = setupLangObj( $wgLangClass );
249 wfProfileOut( $fname.'-language2' );
250 wfProfileIn( $fname.'-MessageCache' );
252 $wgMessageCache = new MessageCache
;
253 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
255 wfProfileOut( $fname.'-MessageCache' );
258 # I guess the warning about UI switching might still apply...
260 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
261 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
262 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
264 # To disable it, the easiest thing could be to uncomment the
265 # following; they should effectively disable the UI switch functionality
267 # $wgLangClass = $wgContLangClass;
268 # $wgLanguageCode = $wgContLanguageCode;
269 # $wgLang = $wgContLang;
271 # TODO: Need to change reference to $wgLang to $wgContLang at proper
272 # places, including namespaces, dates in signatures, magic words,
275 # TODO: Need to look at the issue of input/output encoding
279 wfProfileIn( $fname.'-OutputPage' );
281 $wgOut = new OutputPage();
283 wfProfileOut( $fname.'-OutputPage' );
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 ) {
316 require_once 'PersistentObject.php';
318 call_user_func( $func );
322 $wgFullyInitialised = true;
323 wfProfileOut( $fname.'-extensions' );
324 wfProfileOut( $fname );