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' );
73 if ( $wgUseDynamicDates ) {
74 require_once( 'DateFormatter.php' );
77 wfProfileOut( $fname.'-includes' );
78 wfProfileIn( $fname.'-misc1' );
81 $wgRequest = new WebRequest();
84 if ( $wgCommandLineMode ) {
85 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
86 } elseif ( function_exists( 'getallheaders' ) ) {
87 wfDebug( "\n\nStart request\n" );
88 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
89 $headers = getallheaders();
90 foreach ($headers as $name => $value) {
91 wfDebug( "$name: $value\n" );
94 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
95 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
98 # Disable linkscc except if the old existence check method is enabled
99 if (!$wgUseOldExistenceCheck) {
100 $wgEnablePersistentLC = false;
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' );
117 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) ||
isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
118 User
::SetupSession();
119 $wgSessionStarted = true;
121 $wgSessionStarted = false;
124 wfProfileOut( $fname.'-SetupSession' );
125 wfProfileIn( $fname.'-database' );
127 if ( !$wgDBservers ) {
128 $wgDBservers = array(array(
129 'host' => $wgDBserver,
131 'password' => $wgDBpassword,
132 'dbname' => $wgDBname,
135 'flags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
138 $wgLoadBalancer = LoadBalancer
::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
139 $wgLoadBalancer->loadMasterPos();
141 wfProfileOut( $fname.'-database' );
142 wfProfileIn( $fname.'-language1' );
144 require_once( "$IP/languages/Language.php" );
146 wfProfileOut( $fname.'-language1' );
147 wfProfileIn( $fname.'-User' );
149 # Skin setup functions
150 # Entries can be added to this variable during the inclusion
151 # of the extension file. Skins can then perform any necessary initialisation.
152 foreach ( $wgSkinExtensionFunctions as $func ) {
156 if( !is_object( $wgAuth ) ) {
157 require_once( 'AuthPlugin.php' );
158 $wgAuth = new AuthPlugin();
161 if( $wgCommandLineMode ) {
162 # Used for some maintenance scripts; user session cookies can screw things up
163 # when the database is in an in-between state.
164 $wgUser = new User();
165 # Prevent loading User settings from the DB.
166 $wgUser->setLoaded( true );
168 $wgUser = User
::loadFromSession();
171 wfProfileOut( $fname.'-User' );
172 wfProfileIn( $fname.'-language2' );
174 function setupLangObj(&$langclass) {
177 if( ! class_exists( $langclass ) ) {
178 # Default to English/UTF-8
179 $baseclass = 'LanguageUtf8';
180 require_once( "$IP/languages/$baseclass.php" );
181 $lc = strtolower(substr($langclass, 8));
183 class $langclass extends $baseclass {
184 function getVariants() {
185 return array(\"$lc\");
192 $lang = new $langclass();
197 # $wgLanguageCode may be changed later to fit with user preference.
198 # The content language will remain fixed as per the configuration,
200 $wgContLanguageCode = $wgLanguageCode;
201 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
203 $wgContLang = setupLangObj( $wgContLangClass );
204 $wgContLang->initEncoding();
206 // set default user option from content language
207 if( !$wgUser->mDataLoaded
) {
208 $wgUser->loadDefaultFromLanguage();
211 // wgLanguageCode now specifically means the UI language
212 $wgLanguageCode = $wgUser->getOption('language');
213 # Validate $wgLanguageCode, which will soon be sent to an eval()
214 if( empty( $wgLanguageCode ) ||
!preg_match( '/^[a-z\-]*$/', $wgLanguageCode ) ) {
215 $wgLanguageCode = $wgContLanguageCode;
218 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
220 if( $wgLangClass == $wgContLangClass ) {
221 $wgLang = &$wgContLang;
223 wfSuppressWarnings();
224 include_once("$IP/languages/$wgLangClass.php");
227 $wgLang = setupLangObj( $wgLangClass );
230 wfProfileOut( $fname.'-language' );
231 wfProfileIn( $fname.'-MessageCache' );
233 $wgMessageCache = new MessageCache
;
234 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
236 wfProfileOut( $fname.'-MessageCache' );
239 # I guess the warning about UI switching might still apply...
241 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
242 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
243 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
245 # To disable it, the easiest thing could be to uncomment the
246 # following; they should effectively disable the UI switch functionality
248 # $wgLangClass = $wgContLangClass;
249 # $wgLanguageCode = $wgContLanguageCode;
250 # $wgLang = $wgContLang;
252 # TODO: Need to change reference to $wgLang to $wgContLang at proper
253 # places, including namespaces, dates in signatures, magic words,
256 # TODO: Need to look at the issue of input/output encoding
260 wfProfileIn( $fname.'-OutputPage' );
262 $wgOut = new OutputPage();
264 wfProfileOut( $fname.'-OutputPage' );
265 wfProfileIn( $fname.'-BlockCache' );
267 $wgBlockCache = new BlockCache( true );
269 wfProfileOut( $fname.'-BlockCache' );
270 wfProfileIn( $fname.'-misc2' );
272 $wgDeferredUpdateList = array();
273 $wgPostCommitUpdateList = array();
275 $wgLinkCache = new LinkCache();
276 $wgMagicWords = array();
277 $wgMwRedir =& MagicWord
::get( MAG_REDIRECT
);
278 $wgParserCache = new ParserCache( $messageMemc );
280 if ( $wgUseXMLparser ) {
281 require_once( 'ParserXML.php' );
282 $wgParser = new ParserXML();
284 $wgParser = new Parser();
286 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
287 $wgMsgParserOptions = ParserOptions
::newFromUser($wgUser);
290 # Placeholders in case of DB error
291 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Error' );
292 $wgArticle = new Article($wgTitle);
294 wfProfileOut( $fname.'-misc2' );
295 wfProfileIn( $fname.'-extensions' );
297 # Extension setup functions for extensions other than skins
298 # Entries should be added to this variable during the inclusion
299 # of the extension file. This allows the extension to perform
300 # any necessary initialisation in the fully initialised environment
301 foreach ( $wgExtensionFunctions as $func ) {
306 $wgFullyInitialised = true;
307 wfProfileOut( $fname.'-extensions' );
308 wfProfileOut( $fname );