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/MagicWord.php" );
46 require_once( "$IP/includes/MessageCache.php" );
47 require_once( "$IP/includes/Parser.php" );
48 require_once( "$IP/includes/LoadBalancer.php" );
49 require_once( "$IP/includes/IP.php" );
50 require_once( "$IP/includes/ProxyTools.php" );
51 require_once( "$IP/includes/ObjectCache.php" );
52 require_once( "$IP/includes/ImageFunctions.php" );
54 if ( $wgUseDynamicDates ) {
55 require_once( "$IP/includes/DateFormatter.php" );
58 wfProfileOut( $fname.'-includes' );
59 wfProfileIn( $fname.'-misc1' );
61 $wgIP = false; # Load on demand
62 $wgRequest = new WebRequest();
63 if ( function_exists( 'posix_uname' ) ) {
64 $wguname = posix_uname();
65 $wgNodeName = $wguname['nodename'];
71 if ( $wgCommandLineMode ) {
72 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
73 } elseif ( function_exists( 'getallheaders' ) ) {
74 wfDebug( "\n\nStart request\n" );
75 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
76 $headers = getallheaders();
77 foreach ($headers as $name => $value) {
78 wfDebug( "$name: $value\n" );
81 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
82 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
86 $wgSkipSkins[] = $wgSkipSkin;
89 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
91 wfProfileOut( $fname.'-misc1' );
92 wfProfileIn( $fname.'-memcached' );
94 $wgMemc =& wfGetMainCache();
95 $messageMemc =& wfGetMessageCacheStorage();
96 $parserMemc =& wfGetParserCacheStorage();
98 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
99 "\nMessage cache: " . get_class( $messageMemc ) .
100 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
102 wfProfileOut( $fname.'-memcached' );
103 wfProfileIn( $fname.'-SetupSession' );
106 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
107 } elseif ( $wgSharedDB ) {
108 $wgCookiePrefix = $wgSharedDB;
110 $wgCookiePrefix = $wgDBname;
113 # If session.auto_start is there, we can't touch session name
115 if( !ini_get( 'session.auto_start' ) )
116 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
118 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
119 wfIncrStats( 'request_with_session' );
120 User
::SetupSession();
121 $wgSessionStarted = true;
123 wfIncrStats( 'request_without_session' );
124 $wgSessionStarted = false;
127 wfProfileOut( $fname.'-SetupSession' );
128 wfProfileIn( $fname.'-database' );
130 if ( !$wgDBservers ) {
131 $wgDBservers = array(array(
132 'host' => $wgDBserver,
134 'password' => $wgDBpassword,
135 'dbname' => $wgDBname,
138 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
141 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
142 $wgLoadBalancer->loadMasterPos();
144 wfProfileOut( $fname.'-database' );
145 wfProfileIn( $fname.'-language1' );
147 require_once( "$IP/languages/Language.php" );
149 function setupLangObj($langclass) {
152 if( ! class_exists( $langclass ) ) {
153 # Default to English/UTF-8
154 $baseclass = 'LanguageUtf8';
155 require_once( "$IP/languages/$baseclass.php" );
156 $lc = strtolower(substr($langclass, 8));
158 class $langclass extends $baseclass {
159 function getVariants() {
160 return array(\"$lc\");
167 $lang = new $langclass();
172 # $wgLanguageCode may be changed later to fit with user preference.
173 # The content language will remain fixed as per the configuration,
175 $wgContLanguageCode = $wgLanguageCode;
176 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
178 $wgContLang = setupLangObj( $wgContLangClass );
179 $wgContLang->initEncoding();
181 wfProfileOut( $fname.'-language1' );
182 wfProfileIn( $fname.'-User' );
184 # Skin setup functions
185 # Entries can be added to this variable during the inclusion
186 # of the extension file. Skins can then perform any necessary initialisation.
188 foreach ( $wgSkinExtensionFunctions as $func ) {
189 call_user_func( $func );
192 if( !is_object( $wgAuth ) ) {
193 require_once( 'AuthPlugin.php' );
194 $wgAuth = new AuthPlugin();
197 if( $wgCommandLineMode ) {
198 # Used for some maintenance scripts; user session cookies can screw things up
199 # when the database is in an in-between state.
200 $wgUser = new User();
201 # Prevent loading User settings from the DB.
202 $wgUser->setLoaded( true );
205 wfRunHooks('AutoAuthenticate',array(&$wgUser));
206 if ($wgUser === null) {
207 $wgUser = User
::loadFromSession();
211 wfProfileOut( $fname.'-User' );
212 wfProfileIn( $fname.'-language2' );
214 // wgLanguageCode now specifically means the UI language
215 $wgLanguageCode = $wgRequest->getText('uselang', '');
216 if ($wgLanguageCode == '')
217 $wgLanguageCode = $wgUser->getOption('language');
218 # Validate $wgLanguageCode, which will soon be sent to an eval()
219 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
220 $wgLanguageCode = $wgContLanguageCode;
223 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
225 if( $wgLangClass == $wgContLangClass ) {
226 $wgLang = &$wgContLang;
228 wfSuppressWarnings();
229 // Preload base classes to work around APC/PHP5 bug
230 include_once("$IP/languages/$wgLangClass.deps.php");
231 include_once("$IP/languages/$wgLangClass.php");
234 $wgLang = setupLangObj( $wgLangClass );
237 wfProfileOut( $fname.'-language2' );
238 wfProfileIn( $fname.'-MessageCache' );
240 $wgMessageCache = new MessageCache( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
242 wfProfileOut( $fname.'-MessageCache' );
245 # I guess the warning about UI switching might still apply...
247 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
248 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
249 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
251 # To disable it, the easiest thing could be to uncomment the
252 # following; they should effectively disable the UI switch functionality
254 # $wgLangClass = $wgContLangClass;
255 # $wgLanguageCode = $wgContLanguageCode;
256 # $wgLang = $wgContLang;
258 # TODO: Need to change reference to $wgLang to $wgContLang at proper
259 # places, including namespaces, dates in signatures, magic words,
262 # TODO: Need to look at the issue of input/output encoding
266 wfProfileIn( $fname.'-OutputPage' );
268 $wgOut = new OutputPage();
270 wfProfileOut( $fname.'-OutputPage' );
271 wfProfileIn( $fname.'-misc2' );
273 $wgDeferredUpdateList = array();
274 $wgPostCommitUpdateList = array();
276 $wgMagicWords = array();
278 $wgParser = new Parser();
280 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
281 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
284 # Placeholders in case of DB error
285 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
286 $wgArticle = new Article($wgTitle);
288 wfProfileOut( $fname.'-misc2' );
289 wfProfileIn( $fname.'-extensions' );
291 # Extension setup functions for extensions other than skins
292 # Entries should be added to this variable during the inclusion
293 # of the extension file. This allows the extension to perform
294 # any necessary initialisation in the fully initialised environment
295 foreach ( $wgExtensionFunctions as $func ) {
296 call_user_func( $func );
300 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
301 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
302 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
303 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
307 $wgFullyInitialised = true;
308 wfProfileOut( $fname.'-extensions' );
309 wfProfileOut( $fname );