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 ( $wgProfiling and (0 == rand() %
$wgProfileSampleRate ) ) {
28 require_once( 'Profiling.php' );
30 function wfProfileIn( $fn = '' ) {
31 global $hackwhere, $wgDBname;
33 if (function_exists("setproctitle"))
34 setproctitle($fn . " [$wgDBname]");
36 function wfProfileOut( $fn = '' ) {
37 global $hackwhere, $wgDBname;
38 if (count($hackwhere))
39 array_pop($hackwhere);
40 if (function_exists("setproctitle") && count($hackwhere))
41 setproctitle($hackwhere[count($hackwhere)-1] . " [$wgDBname]");
43 function wfGetProfilingOutput( $s, $e ) {}
44 function wfProfileClose() {}
48 wfProfileIn( $fname );
49 wfProfileIn( $fname.'-includes' );
52 require_once( 'GlobalFunctions.php' );
53 require_once( 'Hooks.php' );
54 require_once( 'Namespace.php' );
55 require_once( 'RecentChange.php' );
56 require_once( 'User.php' );
57 require_once( 'Skin.php' );
58 require_once( 'OutputPage.php' );
59 require_once( 'LinkCache.php' );
60 require_once( 'Title.php' );
61 require_once( 'Article.php' );
62 require_once( 'MagicWord.php' );
63 require_once( 'Block.php' );
64 require_once( 'MessageCache.php' );
65 require_once( 'BlockCache.php' );
66 require_once( 'Parser.php' );
67 require_once( 'Parser.php' );
68 require_once( 'ParserCache.php' );
69 require_once( 'WebRequest.php' );
70 require_once( 'LoadBalancer.php' );
71 require_once( 'HistoryBlob.php' );
72 require_once( 'ProxyTools.php' );
73 require_once( 'ObjectCache.php' );
75 if ( $wgUseDynamicDates ) {
76 require_once( 'DateFormatter.php' );
79 wfProfileOut( $fname.'-includes' );
80 wfProfileIn( $fname.'-misc1' );
83 $wgRequest = new WebRequest();
86 if ( $wgCommandLineMode ) {
87 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
88 } elseif ( function_exists( 'getallheaders' ) ) {
89 wfDebug( "\n\nStart request\n" );
90 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
91 $headers = getallheaders();
92 foreach ($headers as $name => $value) {
93 wfDebug( "$name: $value\n" );
96 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
97 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
100 # Disable linkscc except if the old existence check method is enabled
101 if (!$wgUseOldExistenceCheck) {
102 $wgEnablePersistentLC = false;
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' );
119 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
120 User
::SetupSession();
121 $wgSessionStarted = true;
123 $wgSessionStarted = false;
126 wfProfileOut( $fname.'-SetupSession' );
127 wfProfileIn( $fname.'-database' );
129 if ( !$wgDBservers ) {
130 $wgDBservers = array(array(
131 'host' => $wgDBserver,
133 'password' => $wgDBpassword,
134 'dbname' => $wgDBname,
137 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
140 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
141 $wgLoadBalancer->loadMasterPos();
143 wfProfileOut( $fname.'-database' );
144 wfProfileIn( $fname.'-language1' );
146 require_once( "$IP/languages/Language.php" );
148 wfProfileOut( $fname.'-language1' );
149 wfProfileIn( $fname.'-User' );
151 # Skin setup functions
152 # Entries can be added to this variable during the inclusion
153 # of the extension file. Skins can then perform any necessary initialisation.
154 foreach ( $wgSkinExtensionFunctions as $func ) {
158 if( !is_object( $wgAuth ) ) {
159 require_once( 'AuthPlugin.php' );
160 $wgAuth = new AuthPlugin();
163 if( $wgCommandLineMode ) {
164 # Used for some maintenance scripts; user session cookies can screw things up
165 # when the database is in an in-between state.
166 $wgUser = new User();
167 # Prevent loading User settings from the DB.
168 $wgUser->setLoaded( true );
170 $wgUser = User
::loadFromSession();
173 wfProfileOut( $fname.'-User' );
174 wfProfileIn( $fname.'-language2' );
176 function setupLangObj(&$langclass) {
179 if( ! class_exists( $langclass ) ) {
180 # Default to English/UTF-8
181 $baseclass = 'LanguageUtf8';
182 require_once( "$IP/languages/$baseclass.php" );
183 $lc = strtolower(substr($langclass, 8));
185 class $langclass extends $baseclass {
186 function getVariants() {
187 return array(\"$lc\");
194 $lang = new $langclass();
199 # $wgLanguageCode may be changed later to fit with user preference.
200 # The content language will remain fixed as per the configuration,
202 $wgContLanguageCode = $wgLanguageCode;
203 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
205 $wgContLang = setupLangObj( $wgContLangClass );
206 $wgContLang->initEncoding();
208 // set default user option from content language
209 if( !$wgUser->mDataLoaded
) {
210 $wgUser->loadDefaultFromLanguage();
213 // wgLanguageCode now specifically means the UI language
214 $wgLanguageCode = $wgUser->getOption('language');
215 # Validate $wgLanguageCode, which will soon be sent to an eval()
216 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z\-]*$/', $wgLanguageCode ) ) {
217 $wgLanguageCode = $wgContLanguageCode;
220 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
222 if( $wgLangClass == $wgContLangClass ) {
223 $wgLang = &$wgContLang;
225 wfSuppressWarnings();
226 include_once("$IP/languages/$wgLangClass.php");
229 $wgLang = setupLangObj( $wgLangClass );
232 wfProfileOut( $fname.'-language' );
233 wfProfileIn( $fname.'-MessageCache' );
235 $wgMessageCache = new MessageCache
;
236 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
238 wfProfileOut( $fname.'-MessageCache' );
241 # I guess the warning about UI switching might still apply...
243 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
244 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
245 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
247 # To disable it, the easiest thing could be to uncomment the
248 # following; they should effectively disable the UI switch functionality
250 # $wgLangClass = $wgContLangClass;
251 # $wgLanguageCode = $wgContLanguageCode;
252 # $wgLang = $wgContLang;
254 # TODO: Need to change reference to $wgLang to $wgContLang at proper
255 # places, including namespaces, dates in signatures, magic words,
258 # TODO: Need to look at the issue of input/output encoding
262 wfProfileIn( $fname.'-OutputPage' );
264 $wgOut = new OutputPage();
266 wfProfileOut( $fname.'-OutputPage' );
267 wfProfileIn( $fname.'-BlockCache' );
269 $wgBlockCache = new BlockCache( true );
271 wfProfileOut( $fname.'-BlockCache' );
272 wfProfileIn( $fname.'-misc2' );
274 $wgDeferredUpdateList = array();
275 $wgPostCommitUpdateList = array();
277 $wgLinkCache = new LinkCache();
278 $wgMagicWords = array();
279 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
280 $wgParserCache = new ParserCache( $messageMemc );
282 if ( $wgUseXMLparser ) {
283 require_once( 'ParserXML.php' );
284 $wgParser = new ParserXML();
286 $wgParser = new Parser();
288 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
289 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
292 # Placeholders in case of DB error
293 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
294 $wgArticle = new Article($wgTitle);
296 wfProfileOut( $fname.'-misc2' );
297 wfProfileIn( $fname.'-extensions' );
299 # Extension setup functions for extensions other than skins
300 # Entries should be added to this variable during the inclusion
301 # of the extension file. This allows the extension to perform
302 # any necessary initialisation in the fully initialised environment
303 foreach ( $wgExtensionFunctions as $func ) {
308 $wgFullyInitialised = true;
309 wfProfileOut( $fname.'-extensions' );
310 wfProfileOut( $fname );