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' ) ) {
12 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
16 # The main wiki script and things like database
17 # conversion and maintenance scripts all share a
18 # common setup of including lots of classes and
19 # setting up a few globals.
23 wfProfileIn( $fname );
25 // Check to see if we are at the file scope
26 if ( !isset( $wgVersion ) ) {
27 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
31 require_once( "$IP/includes/AutoLoader.php" );
33 wfProfileIn( $fname.'-exception' );
34 require_once( "$IP/includes/Exception.php" );
35 wfInstallExceptionHandler();
36 wfProfileOut( $fname.'-exception' );
38 wfProfileIn( $fname.'-includes' );
40 require_once( "$IP/includes/GlobalFunctions.php" );
41 require_once( "$IP/includes/Hooks.php" );
42 require_once( "$IP/includes/Namespace.php" );
43 require_once( "$IP/includes/User.php" );
44 require_once( "$IP/includes/OutputPage.php" );
45 require_once( "$IP/includes/MessageCache.php" );
46 require_once( "$IP/includes/Parser.php" );
47 require_once( "$IP/includes/LoadBalancer.php" );
48 require_once( "$IP/includes/IP.php" );
49 require_once( "$IP/includes/ProxyTools.php" );
50 require_once( "$IP/includes/ObjectCache.php" );
51 require_once( "$IP/includes/ImageFunctions.php" );
53 if ( $wgUseDynamicDates ) {
54 require_once( "$IP/includes/DateFormatter.php" );
57 wfProfileOut( $fname.'-includes' );
58 wfProfileIn( $fname.'-misc1' );
60 $wgIP = false; # Load on demand
61 $wgRequest = new WebRequest();
62 if ( function_exists( 'posix_uname' ) ) {
63 $wguname = posix_uname();
64 $wgNodeName = $wguname['nodename'];
70 if ( $wgCommandLineMode ) {
71 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
72 } elseif ( function_exists( 'getallheaders' ) ) {
73 wfDebug( "\n\nStart request\n" );
74 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
75 $headers = getallheaders();
76 foreach ($headers as $name => $value) {
77 wfDebug( "$name: $value\n" );
80 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
81 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
85 $wgSkipSkins[] = $wgSkipSkin;
88 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
90 wfProfileOut( $fname.'-misc1' );
91 wfProfileIn( $fname.'-memcached' );
93 $wgMemc =& wfGetMainCache();
94 $messageMemc =& wfGetMessageCacheStorage();
95 $parserMemc =& wfGetParserCacheStorage();
97 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
98 "\nMessage cache: " . get_class( $messageMemc ) .
99 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
101 wfProfileOut( $fname.'-memcached' );
102 wfProfileIn( $fname.'-SetupSession' );
105 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
106 } elseif ( $wgSharedDB ) {
107 $wgCookiePrefix = $wgSharedDB;
109 $wgCookiePrefix = $wgDBname;
112 # If session.auto_start is there, we can't touch session name
114 if( !ini_get( 'session.auto_start' ) )
115 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
117 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
118 wfIncrStats( 'request_with_session' );
119 User
::SetupSession();
120 $wgSessionStarted = true;
122 wfIncrStats( 'request_without_session' );
123 $wgSessionStarted = false;
126 wfProfileOut( $fname.'-SetupSession' );
127 wfProfileIn( $fname.'-database' );
129 if ( !$wgDBservers ) {
130 $wgDBservers = array(array(
131 'host' => $wgDBserver,
133 'password' => $wgDBpassword,
134 'dbname' => $wgDBname,
137 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
140 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
141 $wgLoadBalancer->loadMasterPos();
143 wfProfileOut( $fname.'-database' );
144 wfProfileIn( $fname.'-language1' );
146 require_once( "$IP/languages/Language.php" );
148 function setupLangObj($langclass) {
151 if( ! class_exists( $langclass ) ) {
152 # Default to English/UTF-8
153 $baseclass = 'LanguageUtf8';
154 require_once( "$IP/languages/$baseclass.php" );
155 $lc = strtolower(substr($langclass, 8));
157 class $langclass extends $baseclass {
158 function getVariants() {
159 return array(\"$lc\");
166 $lang = new $langclass();
171 # $wgLanguageCode may be changed later to fit with user preference.
172 # The content language will remain fixed as per the configuration,
174 $wgContLanguageCode = $wgLanguageCode;
175 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
177 $wgContLang = setupLangObj( $wgContLangClass );
178 $wgContLang->initEncoding();
180 wfProfileOut( $fname.'-language1' );
181 wfProfileIn( $fname.'-User' );
183 # Skin setup functions
184 # Entries can be added to this variable during the inclusion
185 # of the extension file. Skins can then perform any necessary initialisation.
187 foreach ( $wgSkinExtensionFunctions as $func ) {
188 call_user_func( $func );
191 if( !is_object( $wgAuth ) ) {
192 require_once( 'AuthPlugin.php' );
193 $wgAuth = new AuthPlugin();
196 if( $wgCommandLineMode ) {
197 # Used for some maintenance scripts; user session cookies can screw things up
198 # when the database is in an in-between state.
199 $wgUser = new User();
200 # Prevent loading User settings from the DB.
201 $wgUser->setLoaded( true );
204 wfRunHooks('AutoAuthenticate',array(&$wgUser));
205 if ($wgUser === null) {
206 $wgUser = User
::loadFromSession();
210 wfProfileOut( $fname.'-User' );
211 wfProfileIn( $fname.'-language2' );
213 // wgLanguageCode now specifically means the UI language
214 $wgLanguageCode = $wgRequest->getText('uselang', '');
215 if ($wgLanguageCode == '')
216 $wgLanguageCode = $wgUser->getOption('language');
217 # Validate $wgLanguageCode, which will soon be sent to an eval()
218 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
219 $wgLanguageCode = $wgContLanguageCode;
222 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
224 if( $wgLangClass == $wgContLangClass ) {
225 $wgLang = &$wgContLang;
227 wfSuppressWarnings();
228 // Preload base classes to work around APC/PHP5 bug
229 include_once("$IP/languages/$wgLangClass.deps.php");
230 include_once("$IP/languages/$wgLangClass.php");
233 $wgLang = setupLangObj( $wgLangClass );
236 wfProfileOut( $fname.'-language2' );
237 wfProfileIn( $fname.'-MessageCache' );
239 $wgMessageCache = new MessageCache( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
241 wfProfileOut( $fname.'-MessageCache' );
244 # I guess the warning about UI switching might still apply...
246 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
247 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
248 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
250 # To disable it, the easiest thing could be to uncomment the
251 # following; they should effectively disable the UI switch functionality
253 # $wgLangClass = $wgContLangClass;
254 # $wgLanguageCode = $wgContLanguageCode;
255 # $wgLang = $wgContLang;
257 # TODO: Need to change reference to $wgLang to $wgContLang at proper
258 # places, including namespaces, dates in signatures, magic words,
261 # TODO: Need to look at the issue of input/output encoding
265 wfProfileIn( $fname.'-OutputPage' );
267 $wgOut = new OutputPage();
269 wfProfileOut( $fname.'-OutputPage' );
270 wfProfileIn( $fname.'-misc2' );
272 $wgDeferredUpdateList = array();
273 $wgPostCommitUpdateList = array();
275 $wgParser = new Parser();
277 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
278 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
281 # Placeholders in case of DB error
282 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
283 $wgArticle = new Article($wgTitle);
285 wfProfileOut( $fname.'-misc2' );
286 wfProfileIn( $fname.'-extensions' );
288 # Extension setup functions for extensions other than skins
289 # Entries should be added to this variable during the inclusion
290 # of the extension file. This allows the extension to perform
291 # any necessary initialisation in the fully initialised environment
292 foreach ( $wgExtensionFunctions as $func ) {
293 call_user_func( $func );
297 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
298 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
299 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
300 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
304 $wgFullyInitialised = true;
305 wfProfileOut( $fname.'-extensions' );
306 wfProfileOut( $fname );