3 * Include most things that's need to customize the site
7 * This file is not a valid entry point, perform no further processing unless
10 if( !defined( 'MEDIAWIKI' ) ) {
11 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
15 # The main wiki script and things like database
16 # conversion and maintenance scripts all share a
17 # common setup of including lots of classes and
18 # setting up a few globals.
22 wfProfileIn( $fname );
24 // Check to see if we are at the file scope
25 if ( !isset( $wgVersion ) ) {
26 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
30 // Set various default paths sensibly...
31 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
32 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
34 if( $wgArticlePath === false ) {
35 if( $wgUsePathInfo ) {
36 $wgArticlePath = "$wgScript/$1";
38 $wgArticlePath = "$wgScript?title=$1";
42 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
43 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
45 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
47 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
48 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
50 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
51 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
52 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
54 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
55 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
57 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
58 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
62 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
63 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
65 * Note that this is the definition of editinterface and it can be granted to
66 * all users if desired.
68 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
71 * Initialise $wgLocalFileRepo from backwards-compatible settings
73 if ( !$wgLocalFileRepo ) {
74 $wgLocalFileRepo = array(
75 'class' => 'LocalRepo',
77 'directory' => $wgUploadDirectory,
78 'url' => $wgUploadBaseUrl ?
$wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
79 'hashLevels' => $wgHashedUploadDirectory ?
2 : 0,
80 'thumbScriptUrl' => $wgThumbnailScriptPath,
81 'transformVia404' => !$wgGenerateThumbnailOnParse,
82 'initialCapital' => $wgCapitalLinks,
83 'deletedDir' => $wgFileStore['deleted']['directory'],
84 'deletedHashLevels' => $wgFileStore['deleted']['hash']
88 * Initialise shared repo from backwards-compatible settings
90 if ( $wgUseSharedUploads ) {
91 if ( $wgSharedUploadDBname ) {
92 $wgForeignFileRepos[] = array(
93 'class' => 'ForeignDBRepo',
95 'directory' => $wgSharedUploadDirectory,
96 'url' => $wgSharedUploadPath,
97 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
98 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
99 'transformVia404' => !$wgGenerateThumbnailOnParse,
100 'dbType' => $wgDBtype,
101 'dbServer' => $wgDBserver,
102 'dbUser' => $wgDBuser,
103 'dbPassword' => $wgDBpassword,
104 'dbName' => $wgSharedUploadDBname,
105 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
,
106 'tablePrefix' => $wgSharedUploadDBprefix,
107 'hasSharedCache' => $wgCacheSharedUploads,
108 'descBaseUrl' => $wgRepositoryBaseUrl,
109 'fetchDescription' => $wgFetchCommonsDescriptions,
112 $wgForeignFileRepos[] = array(
115 'directory' => $wgSharedUploadDirectory,
116 'url' => $wgSharedUploadPath,
117 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
118 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
119 'transformVia404' => !$wgGenerateThumbnailOnParse,
120 'descBaseUrl' => $wgRepositoryBaseUrl,
121 'fetchDescription' => $wgFetchCommonsDescriptions,
127 * Workaround for http://bugs.php.net/bug.php?id=45132
128 * escapeshellarg() destroys non-ASCII characters if LANG is not a UTF-8 locale
130 putenv( 'LC_CTYPE=en_US.UTF-8' );
131 setlocale( LC_CTYPE
, 'en_US.UTF-8' );
133 if ( !class_exists( 'AutoLoader' ) ) {
134 require_once( "$IP/includes/AutoLoader.php" );
137 wfProfileIn( $fname.'-exception' );
138 require_once( "$IP/includes/Exception.php" );
139 wfInstallExceptionHandler();
140 wfProfileOut( $fname.'-exception' );
142 wfProfileIn( $fname.'-includes' );
143 require_once( "$IP/includes/GlobalFunctions.php" );
144 require_once( "$IP/includes/Hooks.php" );
145 require_once( "$IP/includes/Namespace.php" );
146 require_once( "$IP/includes/ProxyTools.php" );
147 require_once( "$IP/includes/ObjectCache.php" );
148 require_once( "$IP/includes/ImageFunctions.php" );
149 require_once( "$IP/includes/StubObject.php" );
150 wfProfileOut( $fname.'-includes' );
151 wfProfileIn( $fname.'-misc1' );
153 # Override SecretKey with ProxyKey if a site is using the old setting
154 if ( isset( $wgProxyKey ) ) {
155 $wgSecretKey = $wgProxyKey;
158 $wgIP = false; # Load on demand
159 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
160 $wgRequest = new WebRequest
;
161 if ( function_exists( 'posix_uname' ) ) {
162 $wguname = posix_uname();
163 $wgNodeName = $wguname['nodename'];
168 # Useful debug output
169 if ( $wgCommandLineMode ) {
170 wfDebug( "\n\nStart command line script $self\n" );
171 } elseif ( function_exists( 'getallheaders' ) ) {
172 wfDebug( "\n\nStart request\n" );
173 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
174 $headers = getallheaders();
175 foreach ($headers as $name => $value) {
176 wfDebug( "$name: $value\n" );
179 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
180 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
183 if( $wgRCFilterByAge ) {
184 ## Trim down $wgRCLinkDays so that it only lists links which are valid
185 ## as determined by $wgRCMaxAge.
186 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
188 for( $i = 0; $i < count($wgRCLinkDays); $i++
) {
189 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
190 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+
1, false );
197 $wgSkipSkins[] = $wgSkipSkin;
200 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
202 if($wgMetaNamespace === FALSE) {
203 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
206 # These are now the same, always
207 # To determine the user language, use $wgLang->getCode()
208 $wgContLanguageCode = $wgLanguageCode;
210 wfProfileOut( $fname.'-misc1' );
211 wfProfileIn( $fname.'-memcached' );
213 $wgMemc =& wfGetMainCache();
214 $messageMemc =& wfGetMessageCacheStorage();
215 $parserMemc =& wfGetParserCacheStorage();
217 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
218 "\nMessage cache: " . get_class( $messageMemc ) .
219 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
221 wfProfileOut( $fname.'-memcached' );
222 wfProfileIn( $fname.'-SetupSession' );
224 # Set default shared prefix
225 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
227 if( !$wgCookiePrefix ) {
228 if ( in_array('user', $wgSharedTables) && $wgSharedDB && $wgSharedPrefix ) {
229 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
230 } elseif ( in_array('user', $wgSharedTables) && $wgSharedDB ) {
231 $wgCookiePrefix = $wgSharedDB;
232 } elseif ( $wgDBprefix ) {
233 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
235 $wgCookiePrefix = $wgDBname;
238 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
240 # If session.auto_start is there, we can't touch session name
242 if( !wfIniGetBool( 'session.auto_start' ) )
243 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
245 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
246 wfIncrStats( 'request_with_session' );
248 $wgSessionStarted = true;
250 wfIncrStats( 'request_without_session' );
251 $wgSessionStarted = false;
254 wfProfileOut( $fname.'-SetupSession' );
255 wfProfileIn( $fname.'-globals' );
257 $wgContLang = new StubContLang
;
259 // Now that variant lists may be available...
260 $wgRequest->interpolateTitle();
262 $wgUser = new StubUser
;
263 $wgLang = new StubUserLang
;
264 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
265 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
267 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
268 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
270 wfProfileOut( $fname.'-globals' );
271 wfProfileIn( $fname.'-User' );
273 # Skin setup functions
274 # Entries can be added to this variable during the inclusion
275 # of the extension file. Skins can then perform any necessary initialisation.
277 foreach ( $wgSkinExtensionFunctions as $func ) {
278 call_user_func( $func );
281 if( !is_object( $wgAuth ) ) {
282 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
283 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
286 wfProfileOut( $fname.'-User' );
288 wfProfileIn( $fname.'-misc2' );
290 $wgDeferredUpdateList = array();
291 $wgPostCommitUpdateList = array();
293 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
294 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
295 if( $wgAjaxLicensePreview )
296 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
298 # Placeholders in case of DB error
302 wfProfileOut( $fname.'-misc2' );
303 wfProfileIn( $fname.'-extensions' );
305 # Extension setup functions for extensions other than skins
306 # Entries should be added to this variable during the inclusion
307 # of the extension file. This allows the extension to perform
308 # any necessary initialisation in the fully initialised environment
309 foreach ( $wgExtensionFunctions as $func ) {
310 $profName = $fname.'-extensions-'.strval( $func );
311 wfProfileIn( $profName );
312 call_user_func( $func );
313 wfProfileOut( $profName );
317 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
318 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
319 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
320 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
323 wfDebug( "Fully initialised\n" );
324 $wgFullyInitialised = true;
325 wfProfileOut( $fname.'-extensions' );
326 wfProfileOut( $fname );