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 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
25 if( !isset( $wgProfiling ) )
28 if ( function_exists( 'wfProfileIn' ) ) {
29 /* nada, everything should be done already */
30 } elseif ( $wgProfiling and (0 == rand() %
$wgProfileSampleRate ) ) {
31 require_once( 'Profiling.php' );
33 if ($wgProfilerType == "") {
34 $wgProfiler = new Profiler();
36 $prclass="Profiler{$wgProfilerType}";
37 require_once( $prclass.".php" );
38 $wgProfiler = new $prclass();
41 require_once( 'ProfilerStub.php' );
45 wfProfileIn( $fname );
46 wfProfileIn( $fname.'-includes' );
48 require_once( 'AutoLoader.php' );
49 require_once( 'GlobalFunctions.php' );
50 require_once( 'Hooks.php' );
51 require_once( 'Namespace.php' );
52 require_once( 'User.php' );
53 require_once( 'Skin.php' );
54 require_once( 'OutputPage.php' );
55 require_once( 'Title.php' );
56 require_once( 'MagicWord.php' );
57 require_once( 'Block.php' );
58 require_once( 'MessageCache.php' );
59 require_once( 'Parser.php' );
60 require_once( 'ParserCache.php' );
61 require_once( 'WebRequest.php' );
62 require_once( 'LoadBalancer.php' );
63 require_once( 'HistoryBlob.php' );
64 require_once( 'ProxyTools.php' );
65 require_once( 'ObjectCache.php' );
66 require_once( 'WikiError.php' );
67 require_once( 'SpecialPage.php' );
69 if ( $wgUseDynamicDates ) {
70 require_once( 'DateFormatter.php' );
73 wfProfileOut( $fname.'-includes' );
74 wfProfileIn( $fname.'-misc1' );
76 $wgIP = false; # Load on demand
77 $wgRequest = new WebRequest();
78 if ( function_exists( 'posix_uname' ) ) {
79 $wguname = posix_uname();
80 $wgNodeName = $wguname['nodename'];
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" );
101 $wgSkipSkins[] = $wgSkipSkin;
104 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
106 wfProfileOut( $fname.'-misc1' );
107 wfProfileIn( $fname.'-memcached' );
109 $wgMemc =& wfGetMainCache();
110 $messageMemc =& wfGetMessageCacheStorage();
111 $parserMemc =& wfGetParserCacheStorage();
113 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
114 "\nMessage cache: " . get_class( $messageMemc ) .
115 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
117 wfProfileOut( $fname.'-memcached' );
118 wfProfileIn( $fname.'-SetupSession' );
121 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
122 } elseif ( $wgSharedDB ) {
123 $wgCookiePrefix = $wgSharedDB;
125 $wgCookiePrefix = $wgDBname;
128 # If session.auto_start is there, we can't touch session name
130 if (!ini_get('session.auto_start')) {
131 session_name( $wgCookiePrefix . '_session' );
134 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
135 wfIncrStats( 'request_with_session' );
136 User
::SetupSession();
137 $wgSessionStarted = true;
139 wfIncrStats( 'request_without_session' );
140 $wgSessionStarted = false;
143 wfProfileOut( $fname.'-SetupSession' );
144 wfProfileIn( $fname.'-database' );
146 if ( !$wgDBservers ) {
147 $wgDBservers = array(array(
148 'host' => $wgDBserver,
150 'password' => $wgDBpassword,
151 'dbname' => $wgDBname,
154 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
157 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
158 $wgLoadBalancer->loadMasterPos();
160 wfProfileOut( $fname.'-database' );
161 wfProfileIn( $fname.'-language1' );
163 require_once( "$IP/languages/Language.php" );
165 function setupLangObj($langclass) {
168 if( ! class_exists( $langclass ) ) {
169 # Default to English/UTF-8
170 $baseclass = 'LanguageUtf8';
171 require_once( "$IP/languages/$baseclass.php" );
172 $lc = strtolower(substr($langclass, 8));
174 class $langclass extends $baseclass {
175 function getVariants() {
176 return array(\"$lc\");
183 $lang = new $langclass();
188 # $wgLanguageCode may be changed later to fit with user preference.
189 # The content language will remain fixed as per the configuration,
191 $wgContLanguageCode = $wgLanguageCode;
192 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
194 $wgContLang = setupLangObj( $wgContLangClass );
195 $wgContLang->initEncoding();
197 wfProfileOut( $fname.'-language1' );
198 wfProfileIn( $fname.'-User' );
200 # Skin setup functions
201 # Entries can be added to this variable during the inclusion
202 # of the extension file. Skins can then perform any necessary initialisation.
204 foreach ( $wgSkinExtensionFunctions as $func ) {
205 call_user_func( $func );
208 if( !is_object( $wgAuth ) ) {
209 require_once( 'AuthPlugin.php' );
210 $wgAuth = new AuthPlugin();
213 if( $wgCommandLineMode ) {
214 # Used for some maintenance scripts; user session cookies can screw things up
215 # when the database is in an in-between state.
216 $wgUser = new User();
217 # Prevent loading User settings from the DB.
218 $wgUser->setLoaded( true );
221 wfRunHooks('AutoAuthenticate',array(&$wgUser));
222 if ($wgUser === null) {
223 $wgUser = User
::loadFromSession();
227 wfProfileOut( $fname.'-User' );
228 wfProfileIn( $fname.'-language2' );
230 // wgLanguageCode now specifically means the UI language
231 $wgLanguageCode = $wgRequest->getText('uselang', '');
232 if ($wgLanguageCode == '')
233 $wgLanguageCode = $wgUser->getOption('language');
234 # Validate $wgLanguageCode, which will soon be sent to an eval()
235 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
236 $wgLanguageCode = $wgContLanguageCode;
239 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
241 if( $wgLangClass == $wgContLangClass ) {
242 $wgLang = &$wgContLang;
244 wfSuppressWarnings();
245 // Preload base classes to work around APC/PHP5 bug
246 include_once("$IP/languages/$wgLangClass.deps.php");
247 include_once("$IP/languages/$wgLangClass.php");
250 $wgLang = setupLangObj( $wgLangClass );
253 wfProfileOut( $fname.'-language2' );
254 wfProfileIn( $fname.'-MessageCache' );
256 $wgMessageCache = new MessageCache
;
257 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
259 wfProfileOut( $fname.'-MessageCache' );
262 # I guess the warning about UI switching might still apply...
264 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
265 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
266 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
268 # To disable it, the easiest thing could be to uncomment the
269 # following; they should effectively disable the UI switch functionality
271 # $wgLangClass = $wgContLangClass;
272 # $wgLanguageCode = $wgContLanguageCode;
273 # $wgLang = $wgContLang;
275 # TODO: Need to change reference to $wgLang to $wgContLang at proper
276 # places, including namespaces, dates in signatures, magic words,
279 # TODO: Need to look at the issue of input/output encoding
283 wfProfileIn( $fname.'-OutputPage' );
285 $wgOut = new OutputPage();
287 wfProfileOut( $fname.'-OutputPage' );
288 wfProfileIn( $fname.'-misc2' );
290 $wgDeferredUpdateList = array();
291 $wgPostCommitUpdateList = array();
293 $wgMagicWords = array();
294 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
296 if ( $wgUseXMLparser ) {
297 require_once( 'ParserXML.php' );
298 $wgParser = new ParserXML();
300 $wgParser = new Parser();
302 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
303 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
306 # Placeholders in case of DB error
307 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
308 $wgArticle = new Article($wgTitle);
310 wfProfileOut( $fname.'-misc2' );
311 wfProfileIn( $fname.'-extensions' );
313 # Extension setup functions for extensions other than skins
314 # Entries should be added to this variable during the inclusion
315 # of the extension file. This allows the extension to perform
316 # any necessary initialisation in the fully initialised environment
317 foreach ( $wgExtensionFunctions as $func ) {
318 call_user_func( $func );
322 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
323 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
324 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
325 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
329 $wgFullyInitialised = true;
330 wfProfileOut( $fname.'-extensions' );
331 wfProfileOut( $fname );