a63cf3fe1b93151666459e9e6f5f682370f315da
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( 'RecentChange.php' );
51 require_once( 'User.php' );
52 require_once( 'Skin.php' );
53 require_once( 'OutputPage.php' );
54 require_once( 'LinkCache.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' );
250 # I guess the warning about UI switching might still apply...
252 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
253 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
254 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
256 # To disable it, the easiest thing could be to uncomment the
257 # following; they should effectively disable the UI switch functionality
259 # $wgLangClass = $wgContLangClass;
260 # $wgLanguageCode = $wgContLanguageCode;
261 # $wgLang = $wgContLang;
263 # TODO: Need to change reference to $wgLang to $wgContLang at proper
264 # places, including namespaces, dates in signatures, magic words,
267 # TODO: Need to look at the issue of input/output encoding
271 wfProfileIn( $fname.'-OutputPage' );
273 $wgOut = new OutputPage();
275 wfProfileOut( $fname.'-OutputPage' );
276 wfProfileIn( $fname.'-misc2' );
278 $wgDeferredUpdateList = array();
279 $wgPostCommitUpdateList = array();
281 $wgLinkCache = new LinkCache();
282 $wgMagicWords = array();
283 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
284 $wgParserCache = new ParserCache( $messageMemc );
286 if ( $wgUseXMLparser ) {
287 require_once( 'ParserXML.php' );
288 $wgParser = new ParserXML();
290 $wgParser = new Parser();
292 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
293 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
296 # Placeholders in case of DB error
297 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
298 $wgArticle = new Article($wgTitle);
300 wfProfileOut( $fname.'-misc2' );
301 wfProfileIn( $fname.'-extensions' );
303 # Extension setup functions for extensions other than skins
304 # Entries should be added to this variable during the inclusion
305 # of the extension file. This allows the extension to perform
306 # any necessary initialisation in the fully initialised environment
307 foreach ( $wgExtensionFunctions as $func ) {
308 require_once 'PersistentObject.php';
310 call_user_func( $func );
314 $wgFullyInitialised = true;
315 wfProfileOut( $fname.'-extensions' );
316 wfProfileOut( $fname );