dedf6a44a2b3eecbe65c05381c4b415b79821b86
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 require('AutoLoader.php');
27 if( !isset( $wgProfiling ) )
30 if ( function_exists( 'wfProfileIn' ) ) {
31 /* nada, everything should be done already */
32 } elseif ( $wgProfiling and (0 == rand() %
$wgProfileSampleRate ) ) {
34 if ($wgProfilerType == "") {
35 $wgProfiler = new Profiler();
37 $prclass="Profiler{$wgProfilerType}";
38 require_once( $prclass.".php" );
39 $wgProfiler = new $prclass();
42 require_once( 'ProfilerStub.php' );
46 wfProfileIn( $fname );
47 wfProfileIn( $fname.'-includes' );
49 require_once( 'GlobalFunctions.php' );
50 require_once( 'Hooks.php' );
51 require_once( 'Namespace.php' );
52 require_once( 'MagicWord.php' );
55 wfProfileOut( $fname.'-includes' );
56 wfProfileIn( $fname.'-misc1' );
58 $wgIP = false; # Load on demand
59 $wgRequest = new WebRequest();
60 if ( function_exists( 'posix_uname' ) ) {
61 $wguname = posix_uname();
62 $wgNodeName = $wguname['nodename'];
68 if ( $wgCommandLineMode ) {
69 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
70 } elseif ( function_exists( 'getallheaders' ) ) {
71 wfDebug( "\n\nStart request\n" );
72 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
73 $headers = getallheaders();
74 foreach ($headers as $name => $value) {
75 wfDebug( "$name: $value\n" );
78 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
79 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
83 $wgSkipSkins[] = $wgSkipSkin;
86 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
88 wfProfileOut( $fname.'-misc1' );
89 wfProfileIn( $fname.'-memcached' );
91 $wgMemc =& ObjectCacheManager
::getMainCache();
92 $messageMemc =& ObjectCacheManager
::getMessageCache();
93 $parserMemc =& ObjectCacheManager
::getParserCache();
95 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
96 "\nMessage cache: " . get_class( $messageMemc ) .
97 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
99 wfProfileOut( $fname.'-memcached' );
100 wfProfileIn( $fname.'-SetupSession' );
103 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
104 } elseif ( $wgSharedDB ) {
105 $wgCookiePrefix = $wgSharedDB;
107 $wgCookiePrefix = $wgDBname;
110 # If session.auto_start is there, we can't touch session name
112 if (!ini_get('session.auto_start')) {
113 session_name( $wgCookiePrefix . '_session' );
116 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
117 wfIncrStats( 'request_with_session' );
118 User
::SetupSession();
119 $wgSessionStarted = true;
121 wfIncrStats( 'request_without_session' );
122 $wgSessionStarted = false;
125 wfProfileOut( $fname.'-SetupSession' );
126 wfProfileIn( $fname.'-database' );
128 if ( !$wgDBservers ) {
129 $wgDBservers = array(array(
130 'host' => $wgDBserver,
132 'password' => $wgDBpassword,
133 'dbname' => $wgDBname,
136 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
139 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
140 $wgLoadBalancer->loadMasterPos();
142 wfProfileOut( $fname.'-database' );
143 wfProfileIn( $fname.'-language1' );
145 require_once( "$IP/languages/Language.php" );
147 function setupLangObj($langclass) {
150 if( ! class_exists( $langclass ) ) {
151 # Default to English/UTF-8
152 $baseclass = 'LanguageUtf8';
153 require_once( "$IP/languages/$baseclass.php" );
154 $lc = strtolower(substr($langclass, 8));
156 class $langclass extends $baseclass {
157 function getVariants() {
158 return array(\"$lc\");
165 $lang = new $langclass();
170 # $wgLanguageCode may be changed later to fit with user preference.
171 # The content language will remain fixed as per the configuration,
173 $wgContLanguageCode = $wgLanguageCode;
174 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
176 $wgContLang = setupLangObj( $wgContLangClass );
177 $wgContLang->initEncoding();
179 wfProfileOut( $fname.'-language1' );
180 wfProfileIn( $fname.'-User' );
182 # Skin setup functions
183 # Entries can be added to this variable during the inclusion
184 # of the extension file. Skins can then perform any necessary initialisation.
186 foreach ( $wgSkinExtensionFunctions as $func ) {
187 call_user_func( $func );
190 if( !is_object( $wgAuth ) ) {
191 $wgAuth = new AuthPlugin();
194 if( $wgCommandLineMode ) {
195 # Used for some maintenance scripts; user session cookies can screw things up
196 # when the database is in an in-between state.
197 $wgUser = new User();
198 # Prevent loading User settings from the DB.
199 $wgUser->setLoaded( true );
202 wfRunHooks('AutoAuthenticate',array(&$wgUser));
203 if ($wgUser === null) {
204 $wgUser = User
::loadFromSession();
208 wfProfileOut( $fname.'-User' );
209 wfProfileIn( $fname.'-language2' );
211 // wgLanguageCode now specifically means the UI language
212 $wgLanguageCode = $wgRequest->getText('uselang', '');
213 if ($wgLanguageCode == '')
214 $wgLanguageCode = $wgUser->getOption('language');
215 # Validate $wgLanguageCode, which will soon be sent to an eval()
216 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
217 $wgLanguageCode = $wgContLanguageCode;
220 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
222 if( $wgLangClass == $wgContLangClass ) {
223 $wgLang = &$wgContLang;
225 wfSuppressWarnings();
226 // Preload base classes to work around APC/PHP5 bug
227 include_once("$IP/languages/$wgLangClass.deps.php");
228 include_once("$IP/languages/$wgLangClass.php");
231 $wgLang = setupLangObj( $wgLangClass );
234 wfProfileOut( $fname.'-language2' );
235 wfProfileIn( $fname.'-MessageCache' );
237 $wgMessageCache = new MessageCache
;
238 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
240 wfProfileOut( $fname.'-MessageCache' );
243 # I guess the warning about UI switching might still apply...
245 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
246 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
247 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
249 # To disable it, the easiest thing could be to uncomment the
250 # following; they should effectively disable the UI switch functionality
252 # $wgLangClass = $wgContLangClass;
253 # $wgLanguageCode = $wgContLanguageCode;
254 # $wgLang = $wgContLang;
256 # TODO: Need to change reference to $wgLang to $wgContLang at proper
257 # places, including namespaces, dates in signatures, magic words,
260 # TODO: Need to look at the issue of input/output encoding
264 wfProfileIn( $fname.'-OutputPage' );
266 $wgOut = new OutputPage();
268 wfProfileOut( $fname.'-OutputPage' );
269 wfProfileIn( $fname.'-misc2' );
271 $wgDeferredUpdateList = array();
272 $wgPostCommitUpdateList = array();
274 $wgMagicWords = array();
275 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
277 if ( $wgUseXMLparser ) {
278 $wgParser = new ParserXML();
280 $wgParser = new Parser();
282 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
283 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
286 # Placeholders in case of DB error
287 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
288 $wgArticle = new Article($wgTitle);
290 wfProfileOut( $fname.'-misc2' );
291 wfProfileIn( $fname.'-extensions' );
293 # Extension setup functions for extensions other than skins
294 # Entries should be added to this variable during the inclusion
295 # of the extension file. This allows the extension to perform
296 # any necessary initialisation in the fully initialised environment
297 foreach ( $wgExtensionFunctions as $func ) {
298 call_user_func( $func );
302 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
303 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
304 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
305 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
309 $wgFullyInitialised = true;
310 wfProfileOut( $fname.'-extensions' );
311 wfProfileOut( $fname );