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' );
51 require_once( 'GlobalFunctions.php' );
52 require_once( 'Hooks.php' );
53 require_once( 'Namespace.php' );
54 require_once( 'RecentChange.php' );
55 require_once( 'User.php' );
56 require_once( 'Skin.php' );
57 require_once( 'OutputPage.php' );
58 require_once( 'LinkCache.php' );
59 require_once( 'Title.php' );
60 require_once( 'Article.php' );
61 require_once( 'MagicWord.php' );
62 require_once( 'Block.php' );
63 require_once( 'MessageCache.php' );
64 require_once( 'BlockCache.php' );
65 require_once( 'Parser.php' );
66 require_once( 'ParserCache.php' );
67 require_once( 'WebRequest.php' );
68 require_once( 'LoadBalancer.php' );
69 require_once( 'HistoryBlob.php' );
70 require_once( 'ProxyTools.php' );
71 require_once( 'ObjectCache.php' );
72 require_once( 'WikiError.php' );
74 if ( $wgUseDynamicDates ) {
75 require_once( 'DateFormatter.php' );
78 wfProfileOut( $fname.'-includes' );
79 wfProfileIn( $fname.'-misc1' );
82 $wgRequest = new WebRequest();
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" );
99 # Disable linkscc except if the old existence check method is enabled
100 if (!$wgUseOldExistenceCheck) {
101 $wgEnablePersistentLC = false;
104 wfProfileOut( $fname.'-misc1' );
105 wfProfileIn( $fname.'-memcached' );
107 $wgMemc =& wfGetMainCache();
108 $messageMemc =& wfGetMessageCacheStorage();
109 $parserMemc =& wfGetParserCacheStorage();
111 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
112 "\nMessage cache: " . get_class( $messageMemc ) .
113 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
115 wfProfileOut( $fname.'-memcached' );
116 wfProfileIn( $fname.'-SetupSession' );
119 session_name( $wgDBname . '_' . $wgDBprefix . '_session' );
121 session_name( $wgDBname . '_session' );
124 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
125 User
::SetupSession();
126 $wgSessionStarted = true;
128 $wgSessionStarted = false;
131 wfProfileOut( $fname.'-SetupSession' );
132 wfProfileIn( $fname.'-database' );
134 if ( !$wgDBservers ) {
135 $wgDBservers = array(array(
136 'host' => $wgDBserver,
138 'password' => $wgDBpassword,
139 'dbname' => $wgDBname,
142 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
145 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
146 $wgLoadBalancer->loadMasterPos();
148 wfProfileOut( $fname.'-database' );
149 wfProfileIn( $fname.'-language1' );
151 require_once( "$IP/languages/Language.php" );
153 wfProfileOut( $fname.'-language1' );
154 wfProfileIn( $fname.'-User' );
156 # Skin setup functions
157 # Entries can be added to this variable during the inclusion
158 # of the extension file. Skins can then perform any necessary initialisation.
159 foreach ( $wgSkinExtensionFunctions as $func ) {
163 if( !is_object( $wgAuth ) ) {
164 require_once( 'AuthPlugin.php' );
165 $wgAuth = new AuthPlugin();
168 if( $wgCommandLineMode ) {
169 # Used for some maintenance scripts; user session cookies can screw things up
170 # when the database is in an in-between state.
171 $wgUser = new User();
172 # Prevent loading User settings from the DB.
173 $wgUser->setLoaded( true );
175 $wgUser = User
::loadFromSession();
178 wfProfileOut( $fname.'-User' );
179 wfProfileIn( $fname.'-language2' );
181 function setupLangObj(&$langclass) {
184 if( ! class_exists( $langclass ) ) {
185 # Default to English/UTF-8
186 $baseclass = 'LanguageUtf8';
187 require_once( "$IP/languages/$baseclass.php" );
188 $lc = strtolower(substr($langclass, 8));
190 class $langclass extends $baseclass {
191 function getVariants() {
192 return array(\"$lc\");
199 $lang = new $langclass();
204 # $wgLanguageCode may be changed later to fit with user preference.
205 # The content language will remain fixed as per the configuration,
207 $wgContLanguageCode = $wgLanguageCode;
208 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
210 $wgContLang = setupLangObj( $wgContLangClass );
211 $wgContLang->initEncoding();
213 // set default user option from content language
214 if( !$wgUser->mDataLoaded
) {
215 $wgUser->loadDefaultFromLanguage();
218 // wgLanguageCode now specifically means the UI language
219 $wgLanguageCode = $wgUser->getOption('language');
220 # Validate $wgLanguageCode, which will soon be sent to an eval()
221 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z\-]*$/', $wgLanguageCode ) ) {
222 $wgLanguageCode = $wgContLanguageCode;
225 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
227 if( $wgLangClass == $wgContLangClass ) {
228 $wgLang = &$wgContLang;
230 wfSuppressWarnings();
231 include_once("$IP/languages/$wgLangClass.php");
234 $wgLang = setupLangObj( $wgLangClass );
237 wfProfileOut( $fname.'-language' );
238 wfProfileIn( $fname.'-MessageCache' );
240 $wgMessageCache = new MessageCache
;
241 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
243 wfProfileOut( $fname.'-MessageCache' );
246 # I guess the warning about UI switching might still apply...
248 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
249 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
250 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
252 # To disable it, the easiest thing could be to uncomment the
253 # following; they should effectively disable the UI switch functionality
255 # $wgLangClass = $wgContLangClass;
256 # $wgLanguageCode = $wgContLanguageCode;
257 # $wgLang = $wgContLang;
259 # TODO: Need to change reference to $wgLang to $wgContLang at proper
260 # places, including namespaces, dates in signatures, magic words,
263 # TODO: Need to look at the issue of input/output encoding
267 wfProfileIn( $fname.'-OutputPage' );
269 $wgOut = new OutputPage();
271 wfProfileOut( $fname.'-OutputPage' );
272 wfProfileIn( $fname.'-BlockCache' );
274 $wgBlockCache = new BlockCache( true );
276 wfProfileOut( $fname.'-BlockCache' );
277 wfProfileIn( $fname.'-misc2' );
279 $wgDeferredUpdateList = array();
280 $wgPostCommitUpdateList = array();
282 $wgLinkCache = new LinkCache();
283 $wgMagicWords = array();
284 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
285 $wgParserCache = new ParserCache( $messageMemc );
287 if ( $wgUseXMLparser ) {
288 require_once( 'ParserXML.php' );
289 $wgParser = new ParserXML();
291 $wgParser = new Parser();
293 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
294 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
297 # Placeholders in case of DB error
298 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
299 $wgArticle = new Article($wgTitle);
301 wfProfileOut( $fname.'-misc2' );
302 wfProfileIn( $fname.'-extensions' );
304 # Extension setup functions for extensions other than skins
305 # Entries should be added to this variable during the inclusion
306 # of the extension file. This allows the extension to perform
307 # any necessary initialisation in the fully initialised environment
308 foreach ( $wgExtensionFunctions as $func ) {
313 $wgFullyInitialised = true;
314 wfProfileOut( $fname.'-extensions' );
315 wfProfileOut( $fname );