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( "$IP/includes/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( "$IP/includes/ProfilerStub.php" );
46 wfProfileIn( $fname );
48 wfProfileIn( $fname.'-exception' );
49 require_once( "$IP/includes/Exception.php" );
50 wfInstallExceptionHandler();
51 wfProfileOut( $fname.'-exception' );
53 wfProfileIn( $fname.'-includes' );
55 require_once( "$IP/includes/GlobalFunctions.php" );
56 require_once( "$IP/includes/Hooks.php" );
57 require_once( "$IP/includes/Namespace.php" );
58 require_once( "$IP/includes/User.php" );
59 require_once( "$IP/includes/OutputPage.php" );
60 require_once( "$IP/includes/MagicWord.php" );
61 require_once( "$IP/includes/MessageCache.php" );
62 require_once( "$IP/includes/Parser.php" );
63 require_once( "$IP/includes/LoadBalancer.php" );
64 require_once( "$IP/includes/ProxyTools.php" );
65 require_once( "$IP/includes/ObjectCache.php" );
66 require_once( "$IP/includes/ImageFunctions.php" );
68 if ( $wgUseDynamicDates ) {
69 require_once( "$IP/includes/DateFormatter.php" );
72 wfProfileOut( $fname.'-includes' );
73 wfProfileIn( $fname.'-misc1' );
75 $wgIP = false; # Load on demand
76 $wgRequest = new WebRequest();
77 if ( function_exists( 'posix_uname' ) ) {
78 $wguname = posix_uname();
79 $wgNodeName = $wguname['nodename'];
85 if ( $wgCommandLineMode ) {
86 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
87 } elseif ( function_exists( 'getallheaders' ) ) {
88 wfDebug( "\n\nStart request\n" );
89 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
90 $headers = getallheaders();
91 foreach ($headers as $name => $value) {
92 wfDebug( "$name: $value\n" );
95 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
96 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
100 $wgSkipSkins[] = $wgSkipSkin;
103 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
105 wfProfileOut( $fname.'-misc1' );
106 wfProfileIn( $fname.'-memcached' );
108 $wgMemc =& wfGetMainCache();
109 $messageMemc =& wfGetMessageCacheStorage();
110 $parserMemc =& wfGetParserCacheStorage();
112 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
113 "\nMessage cache: " . get_class( $messageMemc ) .
114 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
116 wfProfileOut( $fname.'-memcached' );
117 wfProfileIn( $fname.'-SetupSession' );
120 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
121 } elseif ( $wgSharedDB ) {
122 $wgCookiePrefix = $wgSharedDB;
124 $wgCookiePrefix = $wgDBname;
127 # If session.auto_start is there, we can't touch session name
129 if( !ini_get( 'session.auto_start' ) )
130 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
132 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
133 wfIncrStats( 'request_with_session' );
134 User
::SetupSession();
135 $wgSessionStarted = true;
137 wfIncrStats( 'request_without_session' );
138 $wgSessionStarted = false;
141 wfProfileOut( $fname.'-SetupSession' );
142 wfProfileIn( $fname.'-database' );
144 if ( !$wgDBservers ) {
145 $wgDBservers = array(array(
146 'host' => $wgDBserver,
148 'password' => $wgDBpassword,
149 'dbname' => $wgDBname,
152 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
155 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
156 $wgLoadBalancer->loadMasterPos();
158 wfProfileOut( $fname.'-database' );
159 wfProfileIn( $fname.'-language1' );
161 require_once( "$IP/languages/Language.php" );
163 function setupLangObj($langclass) {
166 if( ! class_exists( $langclass ) ) {
167 # Default to English/UTF-8
168 $baseclass = 'LanguageUtf8';
169 require_once( "$IP/languages/$baseclass.php" );
170 $lc = strtolower(substr($langclass, 8));
172 class $langclass extends $baseclass {
173 function getVariants() {
174 return array(\"$lc\");
181 $lang = new $langclass();
186 # $wgLanguageCode may be changed later to fit with user preference.
187 # The content language will remain fixed as per the configuration,
189 $wgContLanguageCode = $wgLanguageCode;
190 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
192 $wgContLang = setupLangObj( $wgContLangClass );
193 $wgContLang->initEncoding();
195 wfProfileOut( $fname.'-language1' );
196 wfProfileIn( $fname.'-User' );
198 # Skin setup functions
199 # Entries can be added to this variable during the inclusion
200 # of the extension file. Skins can then perform any necessary initialisation.
202 foreach ( $wgSkinExtensionFunctions as $func ) {
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 // Preload base classes to work around APC/PHP5 bug
244 include_once("$IP/languages/$wgLangClass.deps.php");
245 include_once("$IP/languages/$wgLangClass.php");
248 $wgLang = setupLangObj( $wgLangClass );
251 wfProfileOut( $fname.'-language2' );
252 wfProfileIn( $fname.'-MessageCache' );
254 $wgMessageCache = new MessageCache( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
256 wfProfileOut( $fname.'-MessageCache' );
259 # I guess the warning about UI switching might still apply...
261 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
262 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
263 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
265 # To disable it, the easiest thing could be to uncomment the
266 # following; they should effectively disable the UI switch functionality
268 # $wgLangClass = $wgContLangClass;
269 # $wgLanguageCode = $wgContLanguageCode;
270 # $wgLang = $wgContLang;
272 # TODO: Need to change reference to $wgLang to $wgContLang at proper
273 # places, including namespaces, dates in signatures, magic words,
276 # TODO: Need to look at the issue of input/output encoding
280 wfProfileIn( $fname.'-OutputPage' );
282 $wgOut = new OutputPage();
284 wfProfileOut( $fname.'-OutputPage' );
285 wfProfileIn( $fname.'-misc2' );
287 $wgDeferredUpdateList = array();
288 $wgPostCommitUpdateList = array();
290 $wgMagicWords = array();
292 if ( $wgUseXMLparser ) {
293 require_once( 'ParserXML.php' );
294 $wgParser = new ParserXML();
296 $wgParser = new Parser();
298 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
299 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
302 # Placeholders in case of DB error
303 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
304 $wgArticle = new Article($wgTitle);
306 wfProfileOut( $fname.'-misc2' );
307 wfProfileIn( $fname.'-extensions' );
309 # Extension setup functions for extensions other than skins
310 # Entries should be added to this variable during the inclusion
311 # of the extension file. This allows the extension to perform
312 # any necessary initialisation in the fully initialised environment
313 foreach ( $wgExtensionFunctions as $func ) {
314 call_user_func( $func );
318 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
319 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
320 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
321 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
325 $wgFullyInitialised = true;
326 wfProfileOut( $fname.'-extensions' );
327 wfProfileOut( $fname );