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 * Initialise $wgLocalFileRepo from backwards-compatible settings
64 if ( !$wgLocalFileRepo ) {
65 $wgLocalFileRepo = array(
66 'class' => 'LocalRepo',
68 'directory' => $wgUploadDirectory,
69 'url' => $wgUploadBaseUrl ?
$wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
70 'hashLevels' => $wgHashedUploadDirectory ?
2 : 0,
71 'thumbScriptUrl' => $wgThumbnailScriptPath,
72 'transformVia404' => !$wgGenerateThumbnailOnParse,
73 'initialCapital' => $wgCapitalLinks,
74 'deletedDir' => $wgFileStore['deleted']['directory'],
75 'deletedHashLevels' => $wgFileStore['deleted']['hash']
79 * Initialise shared repo from backwards-compatible settings
81 if ( $wgUseSharedUploads ) {
82 if ( $wgSharedUploadDBname ) {
83 $wgForeignFileRepos[] = array(
84 'class' => 'ForeignDBRepo',
86 'directory' => $wgSharedUploadDirectory,
87 'url' => $wgSharedUploadPath,
88 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
89 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
90 'transformVia404' => !$wgGenerateThumbnailOnParse,
91 'dbType' => $wgDBtype,
92 'dbServer' => $wgDBserver,
93 'dbUser' => $wgDBuser,
94 'dbPassword' => $wgDBpassword,
95 'dbName' => $wgSharedUploadDBname,
96 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
,
97 'tablePrefix' => $wgSharedUploadDBprefix,
98 'hasSharedCache' => $wgCacheSharedUploads,
99 'descBaseUrl' => $wgRepositoryBaseUrl,
100 'fetchDescription' => $wgFetchCommonsDescriptions,
103 $wgForeignFileRepos[] = array(
106 'directory' => $wgSharedUploadDirectory,
107 'url' => $wgSharedUploadPath,
108 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
109 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
110 'transformVia404' => !$wgGenerateThumbnailOnParse,
111 'descBaseUrl' => $wgRepositoryBaseUrl,
112 'fetchDescription' => $wgFetchCommonsDescriptions,
118 * Workaround for http://bugs.php.net/bug.php?id=45132
119 * escapeshellarg() destroys non-ASCII characters if LANG is not a UTF-8 locale
121 if ( version_compare( PHP_VERSION
, '5.2.6', '>=' ) ) {
122 putenv( 'LC_CTYPE=en_US.UTF-8' );
123 setlocale( LC_CTYPE
, 'en_US.UTF-8' );
126 if ( !class_exists( 'AutoLoader' ) ) {
127 require_once( "$IP/includes/AutoLoader.php" );
130 wfProfileIn( $fname.'-exception' );
131 require_once( "$IP/includes/Exception.php" );
132 wfInstallExceptionHandler();
133 wfProfileOut( $fname.'-exception' );
135 wfProfileIn( $fname.'-includes' );
136 require_once( "$IP/includes/GlobalFunctions.php" );
137 require_once( "$IP/includes/Hooks.php" );
138 require_once( "$IP/includes/Namespace.php" );
139 require_once( "$IP/includes/ProxyTools.php" );
140 require_once( "$IP/includes/ObjectCache.php" );
141 require_once( "$IP/includes/ImageFunctions.php" );
142 require_once( "$IP/includes/StubObject.php" );
143 wfProfileOut( $fname.'-includes' );
144 wfProfileIn( $fname.'-misc1' );
147 $wgIP = false; # Load on demand
148 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
149 $wgRequest = new WebRequest
;
150 if ( function_exists( 'posix_uname' ) ) {
151 $wguname = posix_uname();
152 $wgNodeName = $wguname['nodename'];
157 # Useful debug output
158 if ( $wgCommandLineMode ) {
159 wfDebug( "\n\nStart command line script $self\n" );
160 } elseif ( function_exists( 'getallheaders' ) ) {
161 wfDebug( "\n\nStart request\n" );
162 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
163 $headers = getallheaders();
164 foreach ($headers as $name => $value) {
165 wfDebug( "$name: $value\n" );
168 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
169 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
172 if( $wgRCFilterByAge ) {
173 ## Trim down $wgRCLinkDays so that it only lists links which are valid
174 ## as determined by $wgRCMaxAge.
175 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
177 for( $i = 0; $i < count($wgRCLinkDays); $i++
) {
178 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
179 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+
1, false );
186 $wgSkipSkins[] = $wgSkipSkin;
189 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
191 if($wgMetaNamespace === FALSE) {
192 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
195 # These are now the same, always
196 # To determine the user language, use $wgLang->getCode()
197 $wgContLanguageCode = $wgLanguageCode;
199 wfProfileOut( $fname.'-misc1' );
200 wfProfileIn( $fname.'-memcached' );
202 $wgMemc =& wfGetMainCache();
203 $messageMemc =& wfGetMessageCacheStorage();
204 $parserMemc =& wfGetParserCacheStorage();
206 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
207 "\nMessage cache: " . get_class( $messageMemc ) .
208 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
210 wfProfileOut( $fname.'-memcached' );
211 wfProfileIn( $fname.'-SetupSession' );
213 # Set default shared prefix
214 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
216 if( !$wgCookiePrefix ) {
217 if ( in_array('user', $wgSharedTables) && $wgSharedDB && $wgSharedPrefix ) {
218 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
219 } elseif ( in_array('user', $wgSharedTables) && $wgSharedDB ) {
220 $wgCookiePrefix = $wgSharedDB;
221 } elseif ( $wgDBprefix ) {
222 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
224 $wgCookiePrefix = $wgDBname;
227 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
229 # If session.auto_start is there, we can't touch session name
231 if( !wfIniGetBool( 'session.auto_start' ) )
232 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
234 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
235 wfIncrStats( 'request_with_session' );
237 $wgSessionStarted = true;
239 wfIncrStats( 'request_without_session' );
240 $wgSessionStarted = false;
243 wfProfileOut( $fname.'-SetupSession' );
244 wfProfileIn( $fname.'-globals' );
246 $wgContLang = new StubContLang
;
248 // Now that variant lists may be available...
249 $wgRequest->interpolateTitle();
251 $wgUser = new StubUser
;
252 $wgLang = new StubUserLang
;
253 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
254 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
256 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
257 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
259 wfProfileOut( $fname.'-globals' );
260 wfProfileIn( $fname.'-User' );
262 # Skin setup functions
263 # Entries can be added to this variable during the inclusion
264 # of the extension file. Skins can then perform any necessary initialisation.
266 foreach ( $wgSkinExtensionFunctions as $func ) {
267 call_user_func( $func );
270 if( !is_object( $wgAuth ) ) {
271 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
272 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
275 wfProfileOut( $fname.'-User' );
277 wfProfileIn( $fname.'-misc2' );
279 $wgDeferredUpdateList = array();
280 $wgPostCommitUpdateList = array();
282 if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
283 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
284 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
285 if( $wgAjaxLicensePreview )
286 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
288 # Placeholders in case of DB error
292 wfProfileOut( $fname.'-misc2' );
293 wfProfileIn( $fname.'-extensions' );
295 # Extension setup functions for extensions other than skins
296 # Entries should be added to this variable during the inclusion
297 # of the extension file. This allows the extension to perform
298 # any necessary initialisation in the fully initialised environment
299 foreach ( $wgExtensionFunctions as $func ) {
300 $profName = $fname.'-extensions-'.strval( $func );
301 wfProfileIn( $profName );
302 call_user_func( $func );
303 wfProfileOut( $profName );
307 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
308 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
309 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
310 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
313 wfDebug( "Fully initialised\n" );
314 $wgFullyInitialised = true;
315 wfProfileOut( $fname.'-extensions' );
316 wfProfileOut( $fname );