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 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
72 * and "File_talk". The old names "Image" and "Image_talk" are
73 * retained as aliases for backwards compatibility.
75 $wgNamespaceAliases['Image'] = NS_FILE
;
76 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
79 * Initialise $wgLocalFileRepo from backwards-compatible settings
81 if ( !$wgLocalFileRepo ) {
82 $wgLocalFileRepo = array(
83 'class' => 'LocalRepo',
85 'directory' => $wgUploadDirectory,
86 'url' => $wgUploadBaseUrl ?
$wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
87 'hashLevels' => $wgHashedUploadDirectory ?
2 : 0,
88 'thumbScriptUrl' => $wgThumbnailScriptPath,
89 'transformVia404' => !$wgGenerateThumbnailOnParse,
90 'initialCapital' => $wgCapitalLinks,
91 'deletedDir' => $wgFileStore['deleted']['directory'],
92 'deletedHashLevels' => $wgFileStore['deleted']['hash']
96 * Initialise shared repo from backwards-compatible settings
98 if ( $wgUseSharedUploads ) {
99 if ( $wgSharedUploadDBname ) {
100 $wgForeignFileRepos[] = array(
101 'class' => 'ForeignDBRepo',
103 'directory' => $wgSharedUploadDirectory,
104 'url' => $wgSharedUploadPath,
105 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
106 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
107 'transformVia404' => !$wgGenerateThumbnailOnParse,
108 'dbType' => $wgDBtype,
109 'dbServer' => $wgDBserver,
110 'dbUser' => $wgDBuser,
111 'dbPassword' => $wgDBpassword,
112 'dbName' => $wgSharedUploadDBname,
113 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
,
114 'tablePrefix' => $wgSharedUploadDBprefix,
115 'hasSharedCache' => $wgCacheSharedUploads,
116 'descBaseUrl' => $wgRepositoryBaseUrl,
117 'fetchDescription' => $wgFetchCommonsDescriptions,
120 $wgForeignFileRepos[] = array(
123 'directory' => $wgSharedUploadDirectory,
124 'url' => $wgSharedUploadPath,
125 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
126 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
127 'transformVia404' => !$wgGenerateThumbnailOnParse,
128 'descBaseUrl' => $wgRepositoryBaseUrl,
129 'fetchDescription' => $wgFetchCommonsDescriptions,
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' );
154 $wgIP = false; # Load on demand
155 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
156 $wgRequest = new WebRequest
;
158 # Useful debug output
159 if ( $wgCommandLineMode ) {
160 wfDebug( "\n\nStart command line script $self\n" );
161 } elseif ( function_exists( 'getallheaders' ) ) {
162 wfDebug( "\n\nStart request\n" );
163 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
164 $headers = getallheaders();
165 foreach ($headers as $name => $value) {
166 wfDebug( "$name: $value\n" );
169 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
170 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
173 if( $wgRCFilterByAge ) {
174 ## Trim down $wgRCLinkDays so that it only lists links which are valid
175 ## as determined by $wgRCMaxAge.
176 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
178 for( $i = 0; $i < count($wgRCLinkDays); $i++
) {
179 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
180 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+
1, false );
187 $wgSkipSkins[] = $wgSkipSkin;
190 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
192 if($wgMetaNamespace === FALSE) {
193 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
196 # These are now the same, always
197 # To determine the user language, use $wgLang->getCode()
198 $wgContLanguageCode = $wgLanguageCode;
200 # Easy to forget to falsify $wgShowIPinHeader for static caches.
201 # If file cache or squid cache is on, just disable this (DWIMD).
202 if( $wgUseFileCache ||
$wgUseSquid ) $wgShowIPinHeader = false;
204 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
205 # in favor of $wgHiddenPrefs, handle b/c here
206 if( !$wgAllowRealName ) {
207 $wgHiddenPrefs[] = 'realname';
210 if( !$wgAllowUserSkin ) {
211 $wgHiddenPrefs[] = 'skin';
214 wfProfileOut( $fname.'-misc1' );
215 wfProfileIn( $fname.'-memcached' );
217 $wgMemc =& wfGetMainCache();
218 $messageMemc =& wfGetMessageCacheStorage();
219 $parserMemc =& wfGetParserCacheStorage();
221 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
222 "\nMessage cache: " . get_class( $messageMemc ) .
223 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
225 wfProfileOut( $fname.'-memcached' );
227 ## Most of the config is out, some might want to run hooks here.
228 wfRunHooks( 'SetupAfterCache' );
230 wfProfileIn( $fname.'-SetupSession' );
232 # Set default shared prefix
233 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
235 if( !$wgCookiePrefix ) {
236 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
237 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
238 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
239 $wgCookiePrefix = $wgSharedDB;
240 } elseif ( $wgDBprefix ) {
241 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
243 $wgCookiePrefix = $wgDBname;
246 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
248 # If session.auto_start is there, we can't touch session name
250 if( !wfIniGetBool( 'session.auto_start' ) )
251 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
253 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
254 wfIncrStats( 'request_with_session' );
256 $wgSessionStarted = true;
258 wfIncrStats( 'request_without_session' );
259 $wgSessionStarted = false;
262 wfProfileOut( $fname.'-SetupSession' );
263 wfProfileIn( $fname.'-globals' );
265 $wgContLang = new StubContLang
;
267 // Now that variant lists may be available...
268 $wgRequest->interpolateTitle();
270 $wgUser = new StubUser
;
271 $wgLang = new StubUserLang
;
272 $wgVariant = new StubUserVariant
;
273 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
274 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
276 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
277 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
279 wfProfileOut( $fname.'-globals' );
280 wfProfileIn( $fname.'-User' );
282 # Skin setup functions
283 # Entries can be added to this variable during the inclusion
284 # of the extension file. Skins can then perform any necessary initialisation.
286 foreach ( $wgSkinExtensionFunctions as $func ) {
287 call_user_func( $func );
290 if( !is_object( $wgAuth ) ) {
291 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
292 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
295 wfProfileOut( $fname.'-User' );
297 wfProfileIn( $fname.'-misc2' );
299 $wgDeferredUpdateList = array();
300 $wgPostCommitUpdateList = array();
302 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
303 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
304 if( $wgAjaxLicensePreview )
305 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
307 # Placeholders in case of DB error
311 wfProfileOut( $fname.'-misc2' );
312 wfProfileIn( $fname.'-extensions' );
314 # Extension setup functions for extensions other than skins
315 # Entries should be added to this variable during the inclusion
316 # of the extension file. This allows the extension to perform
317 # any necessary initialisation in the fully initialised environment
318 foreach ( $wgExtensionFunctions as $func ) {
319 # Allow closures in PHP 5.3+
320 if ( is_object( $func ) && $func instanceof Closure
)
321 $profName = $fname.'-extensions-closure';
322 elseif( is_array( $func ) )
323 $profName = $fname.'-extensions-'.implode( '::', $func );
325 $profName = $fname.'-extensions-'.strval( $func );
327 wfProfileIn( $profName );
328 call_user_func( $func );
329 wfProfileOut( $profName );
333 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
334 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
335 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
336 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
338 if( !empty($wgNewUserLog) ) {
340 $wgLogTypes[] = 'newusers';
341 $wgLogNames['newusers'] = 'newuserlogpage';
342 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
343 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
344 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
345 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
346 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
349 wfDebug( "Fully initialised\n" );
350 $wgFullyInitialised = true;
351 wfProfileOut( $fname.'-extensions' );
352 wfProfileOut( $fname );