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 ( function_exists( 'wfProfileIn' ) ) {
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 require_once( 'ProfilerStub.php' );
44 wfProfileIn( $fname );
45 wfProfileIn( $fname.'-includes' );
47 require_once( 'GlobalFunctions.php' );
48 require_once( 'Hooks.php' );
49 require_once( 'Namespace.php' );
50 require_once( 'User.php' );
51 require_once( 'Skin.php' );
52 require_once( 'OutputPage.php' );
53 require_once( 'LinkCache.php' );
54 require_once( 'LinkBatch.php' );
55 require_once( 'Title.php' );
56 require_once( 'Article.php' );
57 require_once( 'MagicWord.php' );
58 require_once( 'Block.php' );
59 require_once( 'MessageCache.php' );
60 require_once( 'Parser.php' );
61 require_once( 'ParserCache.php' );
62 require_once( 'WebRequest.php' );
63 require_once( 'LoadBalancer.php' );
64 require_once( 'HistoryBlob.php' );
65 require_once( 'ProxyTools.php' );
66 require_once( 'ObjectCache.php' );
67 require_once( 'WikiError.php' );
68 require_once( 'SpecialPage.php' );
70 if ( $wgUseDynamicDates ) {
71 require_once( 'DateFormatter.php' );
74 wfProfileOut( $fname.'-includes' );
75 wfProfileIn( $fname.'-misc1' );
77 $wgIP = false; # Load on demand
78 $wgRequest = new WebRequest();
79 if ( function_exists( 'posix_uname' ) ) {
80 $wguname = posix_uname();
83 if ( $wgCommandLineMode ) {
84 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
85 } elseif ( function_exists( 'getallheaders' ) ) {
86 wfDebug( "\n\nStart request\n" );
87 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
88 $headers = getallheaders();
89 foreach ($headers as $name => $value) {
90 wfDebug( "$name: $value\n" );
93 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
94 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
98 $wgSkipSkins[] = $wgSkipSkin;
101 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
103 wfProfileOut( $fname.'-misc1' );
104 wfProfileIn( $fname.'-memcached' );
106 $wgMemc =& wfGetMainCache();
107 $messageMemc =& wfGetMessageCacheStorage();
108 $parserMemc =& wfGetParserCacheStorage();
110 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
111 "\nMessage cache: " . get_class( $messageMemc ) .
112 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
114 wfProfileOut( $fname.'-memcached' );
115 wfProfileIn( $fname.'-SetupSession' );
118 session_name( $wgDBname . '_' . $wgDBprefix . '_session' );
120 session_name( $wgDBname . '_session' );
123 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
124 wfIncrStats( 'request_with_session' );
125 User
::SetupSession();
126 $wgSessionStarted = true;
128 wfIncrStats( 'request_without_session' );
129 $wgSessionStarted = false;
132 wfProfileOut( $fname.'-SetupSession' );
133 wfProfileIn( $fname.'-database' );
135 if ( !$wgDBservers ) {
136 $wgDBservers = array(array(
137 'host' => $wgDBserver,
139 'password' => $wgDBpassword,
140 'dbname' => $wgDBname,
143 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
146 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
147 $wgLoadBalancer->loadMasterPos();
149 wfProfileOut( $fname.'-database' );
150 wfProfileIn( $fname.'-language1' );
152 require_once( "$IP/languages/Language.php" );
154 function setupLangObj($langclass) {
157 if( ! class_exists( $langclass ) ) {
158 # Default to English/UTF-8
159 $baseclass = 'LanguageUtf8';
160 require_once( "$IP/languages/$baseclass.php" );
161 $lc = strtolower(substr($langclass, 8));
163 class $langclass extends $baseclass {
164 function getVariants() {
165 return array(\"$lc\");
172 $lang = new $langclass();
177 # $wgLanguageCode may be changed later to fit with user preference.
178 # The content language will remain fixed as per the configuration,
180 $wgContLanguageCode = $wgLanguageCode;
181 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
183 $wgContLang = setupLangObj( $wgContLangClass );
184 $wgContLang->initEncoding();
186 wfProfileOut( $fname.'-language1' );
187 wfProfileIn( $fname.'-User' );
189 # Skin setup functions
190 # Entries can be added to this variable during the inclusion
191 # of the extension file. Skins can then perform any necessary initialisation.
192 foreach ( $wgSkinExtensionFunctions as $func ) {
193 require_once 'PersistentObject.php';
195 call_user_func( $func );
198 if( !is_object( $wgAuth ) ) {
199 require_once( 'AuthPlugin.php' );
200 $wgAuth = new AuthPlugin();
203 if( $wgCommandLineMode ) {
204 # Used for some maintenance scripts; user session cookies can screw things up
205 # when the database is in an in-between state.
206 $wgUser = new User();
207 # Prevent loading User settings from the DB.
208 $wgUser->setLoaded( true );
211 wfRunHooks('AutoAuthenticate',array(&$wgUser));
212 if ($wgUser === null) {
213 $wgUser = User
::loadFromSession();
217 wfProfileOut( $fname.'-User' );
218 wfProfileIn( $fname.'-language2' );
220 // wgLanguageCode now specifically means the UI language
221 $wgLanguageCode = $wgRequest->getText('uselang', '');
222 if ($wgLanguageCode == '')
223 $wgLanguageCode = $wgUser->getOption('language');
224 # Validate $wgLanguageCode, which will soon be sent to an eval()
225 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
226 $wgLanguageCode = $wgContLanguageCode;
229 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
231 if( $wgLangClass == $wgContLangClass ) {
232 $wgLang = &$wgContLang;
234 wfSuppressWarnings();
235 include_once("$IP/languages/$wgLangClass.php");
238 $wgLang = setupLangObj( $wgLangClass );
241 wfProfileOut( $fname.'-language2' );
242 wfProfileIn( $fname.'-MessageCache' );
244 $wgMessageCache = new MessageCache
;
245 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
247 wfProfileOut( $fname.'-MessageCache' );
251 # I guess the warning about UI switching might still apply...
253 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
254 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
255 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
257 # To disable it, the easiest thing could be to uncomment the
258 # following; they should effectively disable the UI switch functionality
260 # $wgLangClass = $wgContLangClass;
261 # $wgLanguageCode = $wgContLanguageCode;
262 # $wgLang = $wgContLang;
264 # TODO: Need to change reference to $wgLang to $wgContLang at proper
265 # places, including namespaces, dates in signatures, magic words,
268 # TODO: Need to look at the issue of input/output encoding
272 wfProfileIn( $fname.'-OutputPage' );
274 $wgOut = new OutputPage();
276 wfProfileOut( $fname.'-OutputPage' );
277 wfProfileIn( $fname.'-misc2' );
279 $wgDeferredUpdateList = array();
280 $wgPostCommitUpdateList = array();
282 $wgMagicWords = array();
283 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
285 if ( $wgUseXMLparser ) {
286 require_once( 'ParserXML.php' );
287 $wgParser = new ParserXML();
289 $wgParser = new Parser();
291 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
292 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
295 # Placeholders in case of DB error
296 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
297 $wgArticle = new Article($wgTitle);
299 wfProfileOut( $fname.'-misc2' );
300 wfProfileIn( $fname.'-extensions' );
302 # Extension setup functions for extensions other than skins
303 # Entries should be added to this variable during the inclusion
304 # of the extension file. This allows the extension to perform
305 # any necessary initialisation in the fully initialised environment
306 foreach ( $wgExtensionFunctions as $func ) {
307 require_once 'PersistentObject.php';
309 call_user_func( $func );
313 $wgFullyInitialised = true;
314 wfProfileOut( $fname.'-extensions' );
318 wfProfileIn( $fname.'-upgrades' );
321 $wgUpgrader->setUpgradeFunction ( "MediaWiki" , "wfMediaWikiUpgrade" ) ;
323 function wfMediaWikiUpgrade ( &$upgrader ) {
325 if ( $upgrader->needsUpgrade ( "MediaWiki" , "1.6" ) ) {
326 $upgrader->startTransaction() ;
328 $upgrader->endTransaction() ;
334 # Upgrade software, if necessary
337 wfProfileOut( $fname.'-upgrades' );
339 wfProfileOut( $fname );