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 die( "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n" );
24 if( !isset( $wgProfiling ) )
27 if ( is_object($wgProfiler) ) {
28 /* nada, everything should be done already */
29 } elseif ( $wgProfiling and (0 == rand() %
$wgProfileSampleRate ) ) {
30 require_once( 'Profiling.php' );
32 if ($wgProfilerType == "") {
33 $wgProfiler = new Profiler();
35 $prclass="Profiler{$wgProfilerType}";
36 require_once( $prclass.".php" );
37 $wgProfiler = new $prclass();
40 function wfProfileIn( $fn = '' ) {
41 global $hackwhere, $wgDBname;
43 if (function_exists("setproctitle"))
44 setproctitle($fn . " [$wgDBname]");
46 function wfProfileOut( $fn = '' ) {
47 global $hackwhere, $wgDBname;
48 if (count($hackwhere))
49 array_pop($hackwhere);
50 if (function_exists("setproctitle") && count($hackwhere))
51 setproctitle($hackwhere[count($hackwhere)-1] . " [$wgDBname]");
53 function wfGetProfilingOutput( $s, $e ) {}
54 function wfProfileClose() {}
55 function wfLogProfilingData() {}
59 wfProfileIn( $fname );
60 wfProfileIn( $fname.'-includes' );
62 require_once( 'GlobalFunctions.php' );
63 require_once( 'Hooks.php' );
64 require_once( 'Namespace.php' );
65 require_once( 'RecentChange.php' );
66 require_once( 'User.php' );
67 require_once( 'Skin.php' );
68 require_once( 'OutputPage.php' );
69 require_once( 'LinkCache.php' );
70 require_once( 'Title.php' );
71 require_once( 'Article.php' );
72 require_once( 'MagicWord.php' );
73 require_once( 'Block.php' );
74 require_once( 'MessageCache.php' );
75 require_once( 'Parser.php' );
76 require_once( 'ParserCache.php' );
77 require_once( 'WebRequest.php' );
78 require_once( 'LoadBalancer.php' );
79 require_once( 'HistoryBlob.php' );
80 require_once( 'ProxyTools.php' );
81 require_once( 'ObjectCache.php' );
82 require_once( 'WikiError.php' );
83 require_once( 'SpecialPage.php' );
85 if ( $wgUseDynamicDates ) {
86 require_once( 'DateFormatter.php' );
89 wfProfileOut( $fname.'-includes' );
90 wfProfileIn( $fname.'-misc1' );
92 $wgIP = false; # Load on demand
93 $wgRequest = new WebRequest();
94 if ( function_exists( 'posix_uname' ) ) {
95 $wguname = posix_uname();
98 if ( $wgCommandLineMode ) {
99 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
100 } elseif ( function_exists( 'getallheaders' ) ) {
101 wfDebug( "\n\nStart request\n" );
102 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
103 $headers = getallheaders();
104 foreach ($headers as $name => $value) {
105 wfDebug( "$name: $value\n" );
108 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
109 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
113 $wgSkipSkins[] = $wgSkipSkin;
116 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
118 wfProfileOut( $fname.'-misc1' );
119 wfProfileIn( $fname.'-memcached' );
121 $wgMemc =& wfGetMainCache();
122 $messageMemc =& wfGetMessageCacheStorage();
123 $parserMemc =& wfGetParserCacheStorage();
125 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
126 "\nMessage cache: " . get_class( $messageMemc ) .
127 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
129 wfProfileOut( $fname.'-memcached' );
130 wfProfileIn( $fname.'-SetupSession' );
133 session_name( $wgDBname . '_' . $wgDBprefix . '_session' );
135 session_name( $wgDBname . '_session' );
138 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
139 wfIncrStats( 'request_with_session' );
140 User
::SetupSession();
141 $wgSessionStarted = true;
143 wfIncrStats( 'request_without_session' );
144 $wgSessionStarted = false;
147 wfProfileOut( $fname.'-SetupSession' );
148 wfProfileIn( $fname.'-database' );
150 if ( !$wgDBservers ) {
151 $wgDBservers = array(array(
152 'host' => $wgDBserver,
154 'password' => $wgDBpassword,
155 'dbname' => $wgDBname,
158 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
161 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
162 $wgLoadBalancer->loadMasterPos();
164 wfProfileOut( $fname.'-database' );
165 wfProfileIn( $fname.'-language1' );
167 require_once( "$IP/languages/Language.php" );
169 function setupLangObj($langclass) {
172 if( ! class_exists( $langclass ) ) {
173 # Default to English/UTF-8
174 $baseclass = 'LanguageUtf8';
175 require_once( "$IP/languages/$baseclass.php" );
176 $lc = strtolower(substr($langclass, 8));
178 class $langclass extends $baseclass {
179 function getVariants() {
180 return array(\"$lc\");
187 $lang = new $langclass();
192 # $wgLanguageCode may be changed later to fit with user preference.
193 # The content language will remain fixed as per the configuration,
195 $wgContLanguageCode = $wgLanguageCode;
196 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
198 $wgContLang = setupLangObj( $wgContLangClass );
199 $wgContLang->initEncoding();
201 wfProfileOut( $fname.'-language1' );
202 wfProfileIn( $fname.'-User' );
204 # Skin setup functions
205 # Entries can be added to this variable during the inclusion
206 # of the extension file. Skins can then perform any necessary initialisation.
207 foreach ( $wgSkinExtensionFunctions as $func ) {
208 require_once 'PersistentObject.php';
210 call_user_func( $func );
213 if( !is_object( $wgAuth ) ) {
214 require_once( 'AuthPlugin.php' );
215 $wgAuth = new AuthPlugin();
218 if( $wgCommandLineMode ) {
219 # Used for some maintenance scripts; user session cookies can screw things up
220 # when the database is in an in-between state.
221 $wgUser = new User();
222 # Prevent loading User settings from the DB.
223 $wgUser->setLoaded( true );
226 wfRunHooks('AutoAuthenticate',array(&$wgUser));
227 if ($wgUser === null) {
228 $wgUser = User
::loadFromSession();
232 wfProfileOut( $fname.'-User' );
233 wfProfileIn( $fname.'-language2' );
235 // wgLanguageCode now specifically means the UI language
236 $wgLanguageCode = $wgRequest->getText('uselang', '');
237 if ($wgLanguageCode == '')
238 $wgLanguageCode = $wgUser->getOption('language');
239 # Validate $wgLanguageCode, which will soon be sent to an eval()
240 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
241 $wgLanguageCode = $wgContLanguageCode;
244 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
246 if( $wgLangClass == $wgContLangClass ) {
247 $wgLang = &$wgContLang;
249 wfSuppressWarnings();
250 include_once("$IP/languages/$wgLangClass.php");
253 $wgLang = setupLangObj( $wgLangClass );
256 wfProfileOut( $fname.'-language2' );
257 wfProfileIn( $fname.'-MessageCache' );
259 $wgMessageCache = new MessageCache
;
260 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
262 wfProfileOut( $fname.'-MessageCache' );
265 # I guess the warning about UI switching might still apply...
267 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
268 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
269 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
271 # To disable it, the easiest thing could be to uncomment the
272 # following; they should effectively disable the UI switch functionality
274 # $wgLangClass = $wgContLangClass;
275 # $wgLanguageCode = $wgContLanguageCode;
276 # $wgLang = $wgContLang;
278 # TODO: Need to change reference to $wgLang to $wgContLang at proper
279 # places, including namespaces, dates in signatures, magic words,
282 # TODO: Need to look at the issue of input/output encoding
286 wfProfileIn( $fname.'-OutputPage' );
288 $wgOut = new OutputPage();
290 wfProfileOut( $fname.'-OutputPage' );
291 wfProfileIn( $fname.'-misc2' );
293 $wgDeferredUpdateList = array();
294 $wgPostCommitUpdateList = array();
296 $wgLinkCache = new LinkCache();
297 $wgMagicWords = array();
298 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
299 $wgParserCache = new ParserCache( $messageMemc );
301 if ( $wgUseXMLparser ) {
302 require_once( 'ParserXML.php' );
303 $wgParser = new ParserXML();
305 $wgParser = new Parser();
307 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
308 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
311 # Placeholders in case of DB error
312 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
313 $wgArticle = new Article($wgTitle);
315 wfProfileOut( $fname.'-misc2' );
316 wfProfileIn( $fname.'-extensions' );
318 # Extension setup functions for extensions other than skins
319 # Entries should be added to this variable during the inclusion
320 # of the extension file. This allows the extension to perform
321 # any necessary initialisation in the fully initialised environment
322 foreach ( $wgExtensionFunctions as $func ) {
323 require_once 'PersistentObject.php';
325 call_user_func( $func );
329 $wgFullyInitialised = true;
330 wfProfileOut( $fname.'-extensions' );
331 wfProfileOut( $fname );