ae9496ff72e50f0d2d1319bf371d7362b8273805
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/ProxyTools.php" );
49 require_once( "$IP/includes/ObjectCache.php" );
50 require_once( "$IP/includes/ImageFunctions.php" );
52 wfProfileOut( $fname.'-includes' );
53 wfProfileIn( $fname.'-misc1' );
55 $wgIP = false; # Load on demand
56 $wgRequest = new WebRequest();
57 if ( function_exists( 'posix_uname' ) ) {
58 $wguname = posix_uname();
59 $wgNodeName = $wguname['nodename'];
65 if ( $wgCommandLineMode ) {
66 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
67 } elseif ( function_exists( 'getallheaders' ) ) {
68 wfDebug( "\n\nStart request\n" );
69 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
70 $headers = getallheaders();
71 foreach ($headers as $name => $value) {
72 wfDebug( "$name: $value\n" );
75 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
76 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
80 $wgSkipSkins[] = $wgSkipSkin;
83 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
85 wfProfileOut( $fname.'-misc1' );
86 wfProfileIn( $fname.'-memcached' );
88 $wgMemc =& wfGetMainCache();
89 $messageMemc =& wfGetMessageCacheStorage();
90 $parserMemc =& wfGetParserCacheStorage();
92 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
93 "\nMessage cache: " . get_class( $messageMemc ) .
94 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
96 wfProfileOut( $fname.'-memcached' );
97 wfProfileIn( $fname.'-SetupSession' );
100 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
101 } elseif ( $wgSharedDB ) {
102 $wgCookiePrefix = $wgSharedDB;
104 $wgCookiePrefix = $wgDBname;
107 # If session.auto_start is there, we can't touch session name
109 if( !ini_get( 'session.auto_start' ) )
110 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
112 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
113 wfIncrStats( 'request_with_session' );
114 User
::SetupSession();
115 $wgSessionStarted = true;
117 wfIncrStats( 'request_without_session' );
118 $wgSessionStarted = false;
121 wfProfileOut( $fname.'-SetupSession' );
122 wfProfileIn( $fname.'-database' );
124 if ( !$wgDBservers ) {
125 $wgDBservers = array(array(
126 'host' => $wgDBserver,
128 'password' => $wgDBpassword,
129 'dbname' => $wgDBname,
132 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
135 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
136 $wgLoadBalancer->loadMasterPos();
138 wfProfileOut( $fname.'-database' );
139 wfProfileIn( $fname.'-language1' );
141 require_once( "$IP/languages/Language.php" );
143 function setupLangObj($langclass) {
146 if( ! class_exists( $langclass ) ) {
147 # Default to English/UTF-8
148 $baseclass = 'LanguageUtf8';
149 require_once( "$IP/languages/$baseclass.php" );
150 $lc = strtolower(substr($langclass, 8));
152 class $langclass extends $baseclass {
153 function getVariants() {
154 return array(\"$lc\");
161 $lang = new $langclass();
166 # $wgLanguageCode may be changed later to fit with user preference.
167 # The content language will remain fixed as per the configuration,
169 $wgContLanguageCode = $wgLanguageCode;
170 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
172 $wgContLang = setupLangObj( $wgContLangClass );
173 $wgContLang->initEncoding();
175 wfProfileOut( $fname.'-language1' );
176 wfProfileIn( $fname.'-User' );
178 # Skin setup functions
179 # Entries can be added to this variable during the inclusion
180 # of the extension file. Skins can then perform any necessary initialisation.
182 foreach ( $wgSkinExtensionFunctions as $func ) {
183 call_user_func( $func );
186 if( !is_object( $wgAuth ) ) {
187 require_once( 'AuthPlugin.php' );
188 $wgAuth = new AuthPlugin();
191 if( $wgCommandLineMode ) {
192 # Used for some maintenance scripts; user session cookies can screw things up
193 # when the database is in an in-between state.
194 $wgUser = new User();
195 # Prevent loading User settings from the DB.
196 $wgUser->setLoaded( true );
199 wfRunHooks('AutoAuthenticate',array(&$wgUser));
200 if ($wgUser === null) {
201 $wgUser = User
::loadFromSession();
205 wfProfileOut( $fname.'-User' );
206 wfProfileIn( $fname.'-language2' );
208 // wgLanguageCode now specifically means the UI language
209 $wgLanguageCode = $wgRequest->getText('uselang', '');
210 if ($wgLanguageCode == '')
211 $wgLanguageCode = $wgUser->getOption('language');
212 # Validate $wgLanguageCode, which will soon be sent to an eval()
213 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
214 $wgLanguageCode = $wgContLanguageCode;
217 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
219 if( $wgLangClass == $wgContLangClass ) {
220 $wgLang = &$wgContLang;
222 wfSuppressWarnings();
223 // Preload base classes to work around APC/PHP5 bug
224 include_once("$IP/languages/$wgLangClass.deps.php");
225 include_once("$IP/languages/$wgLangClass.php");
228 $wgLang = setupLangObj( $wgLangClass );
231 wfProfileOut( $fname.'-language2' );
232 wfProfileIn( $fname.'-MessageCache' );
234 $wgMessageCache = new MessageCache( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
236 wfProfileOut( $fname.'-MessageCache' );
239 # I guess the warning about UI switching might still apply...
241 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
242 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
243 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
245 # To disable it, the easiest thing could be to uncomment the
246 # following; they should effectively disable the UI switch functionality
248 # $wgLangClass = $wgContLangClass;
249 # $wgLanguageCode = $wgContLanguageCode;
250 # $wgLang = $wgContLang;
252 # TODO: Need to change reference to $wgLang to $wgContLang at proper
253 # places, including namespaces, dates in signatures, magic words,
256 # TODO: Need to look at the issue of input/output encoding
260 wfProfileIn( $fname.'-OutputPage' );
262 $wgOut = new OutputPage();
264 wfProfileOut( $fname.'-OutputPage' );
265 wfProfileIn( $fname.'-misc2' );
267 $wgDeferredUpdateList = array();
268 $wgPostCommitUpdateList = array();
270 $wgParser = new Parser();
272 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
273 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
276 # Placeholders in case of DB error
277 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
278 $wgArticle = new Article($wgTitle);
280 wfProfileOut( $fname.'-misc2' );
281 wfProfileIn( $fname.'-extensions' );
283 # Extension setup functions for extensions other than skins
284 # Entries should be added to this variable during the inclusion
285 # of the extension file. This allows the extension to perform
286 # any necessary initialisation in the fully initialised environment
287 foreach ( $wgExtensionFunctions as $func ) {
288 call_user_func( $func );
292 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
293 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
294 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
295 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
299 $wgFullyInitialised = true;
300 wfProfileOut( $fname.'-extensions' );
301 wfProfileOut( $fname );