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 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
25 if( !isset( $wgProfiling ) )
28 require_once( 'AutoLoader.php' );
30 if ( function_exists( 'wfProfileIn' ) ) {
31 /* nada, everything should be done already */
32 } elseif ( $wgProfiling and (0 == rand() %
$wgProfileSampleRate ) ) {
34 if ($wgProfilerType == "") {
35 $wgProfiler = new Profiler();
37 $prclass="Profiler{$wgProfilerType}";
38 require_once( $prclass.".php" );
39 $wgProfiler = new $prclass();
42 require_once( 'ProfilerStub.php' );
46 wfProfileIn( $fname );
48 wfProfileIn( $fname.'-exception' );
49 require_once( 'Exception.php' );
50 wfInstallExceptionHandler();
51 wfProfileOut( $fname.'-exception' );
53 wfProfileIn( $fname.'-includes' );
55 require_once( 'GlobalFunctions.php' );
56 require_once( 'Hooks.php' );
57 require_once( 'Namespace.php' );
58 require_once( 'User.php' );
59 require_once( 'Skin.php' );
60 require_once( 'OutputPage.php' );
61 require_once( 'MagicWord.php' );
62 require_once( 'Block.php' );
63 require_once( 'MessageCache.php' );
64 require_once( 'Parser.php' );
65 require_once( 'LoadBalancer.php' );
66 require_once( 'HistoryBlob.php' );
67 require_once( 'ProxyTools.php' );
68 require_once( 'ObjectCache.php' );
70 if ( $wgUseDynamicDates ) {
71 require_once( 'DateFormatter.php' );
74 wfProfileOut( $fname.'-includes' );
75 wfProfileIn( $fname.'-misc1' );
77 $wgIP = false; # Load on demand
78 $wgRequest = new WebRequest();
79 if ( function_exists( 'posix_uname' ) ) {
80 $wguname = posix_uname();
81 $wgNodeName = $wguname['nodename'];
87 if ( $wgCommandLineMode ) {
88 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
89 } elseif ( function_exists( 'getallheaders' ) ) {
90 wfDebug( "\n\nStart request\n" );
91 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
92 $headers = getallheaders();
93 foreach ($headers as $name => $value) {
94 wfDebug( "$name: $value\n" );
97 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
98 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
102 $wgSkipSkins[] = $wgSkipSkin;
105 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
107 wfProfileOut( $fname.'-misc1' );
108 wfProfileIn( $fname.'-memcached' );
110 $wgMemc =& wfGetMainCache();
111 $messageMemc =& wfGetMessageCacheStorage();
112 $parserMemc =& wfGetParserCacheStorage();
114 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
115 "\nMessage cache: " . get_class( $messageMemc ) .
116 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
118 wfProfileOut( $fname.'-memcached' );
119 wfProfileIn( $fname.'-SetupSession' );
122 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
123 } elseif ( $wgSharedDB ) {
124 $wgCookiePrefix = $wgSharedDB;
126 $wgCookiePrefix = $wgDBname;
129 # If session.auto_start is there, we can't touch session name
131 if (!ini_get('session.auto_start')) {
132 session_name( $wgCookiePrefix . '_session' );
135 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
136 wfIncrStats( 'request_with_session' );
137 User
::SetupSession();
138 $wgSessionStarted = true;
140 wfIncrStats( 'request_without_session' );
141 $wgSessionStarted = false;
144 wfProfileOut( $fname.'-SetupSession' );
145 wfProfileIn( $fname.'-database' );
147 if ( !$wgDBservers ) {
148 $wgDBservers = array(array(
149 'host' => $wgDBserver,
152 'password' => $wgDBpassword,
153 'dbname' => $wgDBname,
156 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
159 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
160 $wgLoadBalancer->loadMasterPos();
162 wfProfileOut( $fname.'-database' );
163 wfProfileIn( $fname.'-language1' );
165 require_once( "$IP/languages/Language.php" );
167 function setupLangObj($langclass) {
170 if( ! class_exists( $langclass ) ) {
171 # Default to English/UTF-8
172 $baseclass = 'LanguageUtf8';
173 require_once( "$IP/languages/$baseclass.php" );
174 $lc = strtolower(substr($langclass, 8));
176 class $langclass extends $baseclass {
177 function getVariants() {
178 return array(\"$lc\");
185 $lang = new $langclass();
190 # $wgLanguageCode may be changed later to fit with user preference.
191 # The content language will remain fixed as per the configuration,
193 $wgContLanguageCode = $wgLanguageCode;
194 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
196 $wgContLang = setupLangObj( $wgContLangClass );
197 $wgContLang->initEncoding();
199 wfProfileOut( $fname.'-language1' );
200 wfProfileIn( $fname.'-User' );
202 # Skin setup functions
203 # Entries can be added to this variable during the inclusion
204 # of the extension file. Skins can then perform any necessary initialisation.
206 foreach ( $wgSkinExtensionFunctions as $func ) {
207 call_user_func( $func );
210 if( !is_object( $wgAuth ) ) {
211 require_once( 'AuthPlugin.php' );
212 $wgAuth = new AuthPlugin();
215 if( $wgCommandLineMode ) {
216 # Used for some maintenance scripts; user session cookies can screw things up
217 # when the database is in an in-between state.
218 $wgUser = new User();
219 # Prevent loading User settings from the DB.
220 $wgUser->setLoaded( true );
223 wfRunHooks('AutoAuthenticate',array(&$wgUser));
224 if ($wgUser === null) {
225 $wgUser = User
::loadFromSession();
229 wfProfileOut( $fname.'-User' );
230 wfProfileIn( $fname.'-language2' );
232 // wgLanguageCode now specifically means the UI language
233 $wgLanguageCode = $wgRequest->getText('uselang', '');
234 if ($wgLanguageCode == '')
235 $wgLanguageCode = $wgUser->getOption('language');
236 # Validate $wgLanguageCode, which will soon be sent to an eval()
237 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
238 $wgLanguageCode = $wgContLanguageCode;
241 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
243 if( $wgLangClass == $wgContLangClass ) {
244 $wgLang = &$wgContLang;
246 wfSuppressWarnings();
247 // Preload base classes to work around APC/PHP5 bug
248 include_once("$IP/languages/$wgLangClass.deps.php");
249 include_once("$IP/languages/$wgLangClass.php");
252 $wgLang = setupLangObj( $wgLangClass );
255 wfProfileOut( $fname.'-language2' );
256 wfProfileIn( $fname.'-MessageCache' );
258 $wgMessageCache = new MessageCache
;
259 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
261 wfProfileOut( $fname.'-MessageCache' );
264 # I guess the warning about UI switching might still apply...
266 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
267 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
268 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
270 # To disable it, the easiest thing could be to uncomment the
271 # following; they should effectively disable the UI switch functionality
273 # $wgLangClass = $wgContLangClass;
274 # $wgLanguageCode = $wgContLanguageCode;
275 # $wgLang = $wgContLang;
277 # TODO: Need to change reference to $wgLang to $wgContLang at proper
278 # places, including namespaces, dates in signatures, magic words,
281 # TODO: Need to look at the issue of input/output encoding
285 wfProfileIn( $fname.'-OutputPage' );
287 $wgOut = new OutputPage();
289 wfProfileOut( $fname.'-OutputPage' );
290 wfProfileIn( $fname.'-misc2' );
292 $wgDeferredUpdateList = array();
293 $wgPostCommitUpdateList = array();
295 $wgMagicWords = array();
296 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
298 if ( $wgUseXMLparser ) {
299 require_once( 'ParserXML.php' );
300 $wgParser = new ParserXML();
302 $wgParser = new Parser();
304 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
305 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
308 # Placeholders in case of DB error
309 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
310 $wgArticle = new Article($wgTitle);
312 wfProfileOut( $fname.'-misc2' );
313 wfProfileIn( $fname.'-extensions' );
315 # Extension setup functions for extensions other than skins
316 # Entries should be added to this variable during the inclusion
317 # of the extension file. This allows the extension to perform
318 # any necessary initialisation in the fully initialised environment
319 foreach ( $wgExtensionFunctions as $func ) {
320 call_user_func( $func );
324 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
325 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
326 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
327 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
331 $wgFullyInitialised = true;
332 wfProfileOut( $fname.'-extensions' );
333 wfProfileOut( $fname );