3 * Include most things that's need to customize the site
9 * This file is not a valid entry point, perform no further processing unless
10 * MEDIAWIKI is defined
12 if ( !defined( 'MEDIAWIKI' ) ) {
16 # The main wiki script and things like database
17 # conversion and maintenance scripts all share a
18 # common setup of including lots of classes and
19 # setting up a few globals.
23 wfProfileIn( $fname );
25 // Check to see if we are at the file scope
26 if ( !isset( $wgVersion ) ) {
27 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
31 // Set various default paths sensibly...
32 if ( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
33 if ( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
34 if ( $wgLoadScript === false ) $wgLoadScript = "$wgScriptPath/load$wgScriptExtension";
36 if ( $wgArticlePath === false ) {
37 if ( $wgUsePathInfo ) {
38 $wgArticlePath = "$wgScript/$1";
40 $wgArticlePath = "$wgScript?title=$1";
44 if ( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
45 if ( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins";
46 if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins";
47 if ( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
49 if ( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
51 if ( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
52 if ( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
54 if ( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
56 if ( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
57 if ( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
58 if ( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
60 if ( isset( $wgFileStore['deleted']['directory'] ) ) {
61 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
64 if ( isset( $wgFooterIcons['copyright'] ) &&
65 isset( $wgFooterIcons['copyright']['copyright'] ) &&
66 $wgFooterIcons['copyright']['copyright'] === array() )
68 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
69 $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
70 } elseif ( $wgRightsIcon ||
$wgRightsText ) {
71 $wgFooterIcons['copyright']['copyright'] = array(
72 'url' => $wgRightsUrl,
73 'src' => $wgRightsIcon,
74 'alt' => $wgRightsText,
77 unset( $wgFooterIcons['copyright']['copyright'] );
81 if ( isset( $wgFooterIcons['poweredby'] ) &&
82 isset( $wgFooterIcons['poweredby']['mediawiki'] ) &&
83 $wgFooterIcons['poweredby']['mediawiki']['src'] === null )
85 $wgFooterIcons['poweredby']['mediawiki']['src'] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
89 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
90 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
92 * Note that this is the definition of editinterface and it can be granted to
93 * all users if desired.
95 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
98 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
99 * and "File_talk". The old names "Image" and "Image_talk" are
100 * retained as aliases for backwards compatibility.
102 $wgNamespaceAliases['Image'] = NS_FILE
;
103 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
106 * Initialise $wgLocalFileRepo from backwards-compatible settings
108 if ( !$wgLocalFileRepo ) {
109 if ( isset( $wgFileStore['deleted']['hash'] ) ) {
110 $deletedHashLevel = $wgFileStore['deleted']['hash'];
112 $deletedHashLevel = $wgHashedUploadDirectory ?
3 : 0;
114 $wgLocalFileRepo = array(
115 'class' => 'LocalRepo',
117 'directory' => $wgUploadDirectory,
118 'scriptDirUrl' => $wgScriptPath,
119 'scriptExtension' => $wgScriptExtension,
120 'url' => $wgUploadBaseUrl ?
$wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
121 'hashLevels' => $wgHashedUploadDirectory ?
2 : 0,
122 'thumbScriptUrl' => $wgThumbnailScriptPath,
123 'transformVia404' => !$wgGenerateThumbnailOnParse,
124 'deletedDir' => $wgDeletedDirectory,
125 'deletedHashLevels' => $deletedHashLevel
129 * Initialise shared repo from backwards-compatible settings
131 if ( $wgUseSharedUploads ) {
132 if ( $wgSharedUploadDBname ) {
133 $wgForeignFileRepos[] = array(
134 'class' => 'ForeignDBRepo',
136 'directory' => $wgSharedUploadDirectory,
137 'url' => $wgSharedUploadPath,
138 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
139 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
140 'transformVia404' => !$wgGenerateThumbnailOnParse,
141 'dbType' => $wgDBtype,
142 'dbServer' => $wgDBserver,
143 'dbUser' => $wgDBuser,
144 'dbPassword' => $wgDBpassword,
145 'dbName' => $wgSharedUploadDBname,
146 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG
: 0 ) | DBO_DEFAULT
,
147 'tablePrefix' => $wgSharedUploadDBprefix,
148 'hasSharedCache' => $wgCacheSharedUploads,
149 'descBaseUrl' => $wgRepositoryBaseUrl,
150 'fetchDescription' => $wgFetchCommonsDescriptions,
153 $wgForeignFileRepos[] = array(
156 'directory' => $wgSharedUploadDirectory,
157 'url' => $wgSharedUploadPath,
158 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
159 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
160 'transformVia404' => !$wgGenerateThumbnailOnParse,
161 'descBaseUrl' => $wgRepositoryBaseUrl,
162 'fetchDescription' => $wgFetchCommonsDescriptions,
166 if ( $wgUseInstantCommons ) {
167 $wgForeignFileRepos[] = array(
168 'class' => 'ForeignAPIRepo',
169 'name' => 'wikimediacommons',
170 'apibase' => 'http://commons.wikimedia.org/w/api.php',
172 'fetchDescription' => true,
173 'descriptionCacheExpiry' => 43200,
174 'apiThumbCacheExpiry' => 86400,
178 if ( $wgRCFilterByAge ) {
179 # # Trim down $wgRCLinkDays so that it only lists links which are valid
180 # # as determined by $wgRCMaxAge.
181 # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
182 sort( $wgRCLinkDays );
183 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++
) {
184 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
185 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i +
1, false );
192 $wgSkipSkins[] = $wgSkipSkin;
195 # Set default shared prefix
196 if ( $wgSharedPrefix === false ) {
197 $wgSharedPrefix = $wgDBprefix;
200 if ( !$wgCookiePrefix ) {
201 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
202 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
203 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
204 $wgCookiePrefix = $wgSharedDB;
205 } elseif ( $wgDBprefix ) {
206 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
208 $wgCookiePrefix = $wgDBname;
211 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
213 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
215 if ( $wgMetaNamespace === false ) {
216 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
220 * Definitions of the NS_ constants are in Defines.php
223 $wgCanonicalNamespaceNames = array(
225 NS_SPECIAL
=> 'Special',
228 NS_USER_TALK
=> 'User_talk',
229 NS_PROJECT
=> 'Project',
230 NS_PROJECT_TALK
=> 'Project_talk',
232 NS_FILE_TALK
=> 'File_talk',
233 NS_MEDIAWIKI
=> 'MediaWiki',
234 NS_MEDIAWIKI_TALK
=> 'MediaWiki_talk',
235 NS_TEMPLATE
=> 'Template',
236 NS_TEMPLATE_TALK
=> 'Template_talk',
238 NS_HELP_TALK
=> 'Help_talk',
239 NS_CATEGORY
=> 'Category',
240 NS_CATEGORY_TALK
=> 'Category_talk',
244 if( is_array( $wgExtraNamespaces ) ) {
245 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames +
$wgExtraNamespaces;
248 # These are now the same, always
249 # To determine the user language, use $wgLang->getCode()
250 $wgContLanguageCode = $wgLanguageCode;
252 # Easy to forget to falsify $wgShowIPinHeader for static caches.
253 # If file cache or squid cache is on, just disable this (DWIMD).
254 if ( $wgUseFileCache ||
$wgUseSquid ) {
255 $wgShowIPinHeader = false;
258 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
259 # in favor of $wgHiddenPrefs, handle b/c here
260 if ( !$wgAllowRealName ) {
261 $wgHiddenPrefs[] = 'realname';
264 if ( !$wgAllowUserSkin ) {
265 $wgHiddenPrefs[] = 'skin';
268 # Doesn't make sense to have if disabled.
269 if ( !$wgEnotifMinorEdits ) {
270 $wgHiddenPrefs[] = 'enotifminoredits';
273 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
274 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
275 if ( $wgMimeType == 'application/xhtml+xml' ) {
276 $wgHtml5Version = 'XHTML+RDFa 1.0';
278 $wgHtml5Version = 'HTML+RDFa 1.0';
282 # Blacklisted file extensions shouldn't appear on the "allowed" list
283 $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist );
285 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
286 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime
( "$IP/LocalSettings.php" ) ) );
289 if ( $wgAjaxUploadDestCheck ) {
290 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
293 if ( $wgNewUserLog ) {
295 $wgLogTypes[] = 'newusers';
296 $wgLogNames['newusers'] = 'newuserlogpage';
297 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
298 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
299 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
300 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
301 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
304 if ( !defined( 'MW_COMPILED' ) ) {
305 if ( !MWInit
::classExists( 'AutoLoader' ) ) {
306 require_once( "$IP/includes/AutoLoader.php" );
309 wfProfileIn( $fname . '-exception' );
310 require_once( "$IP/includes/Exception.php" );
311 wfInstallExceptionHandler();
312 wfProfileOut( $fname . '-exception' );
314 wfProfileIn( $fname . '-includes' );
315 require_once( "$IP/includes/GlobalFunctions.php" );
316 require_once( "$IP/includes/Hooks.php" );
317 require_once( "$IP/includes/ProxyTools.php" );
318 require_once( "$IP/includes/ImageFunctions.php" );
319 wfProfileOut( $fname . '-includes' );
321 wfProfileIn( $fname . '-misc1' );
323 # Raise the memory limit if it's too low
327 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
328 * that happens whenever you use a date function without the timezone being
329 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
331 wfSuppressWarnings();
332 date_default_timezone_set( date_default_timezone_get() );
335 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
336 $wgRequest = new WebRequest
;
338 # Useful debug output
339 global $wgCommandLineMode;
340 if ( $wgCommandLineMode ) {
341 wfDebug( "\n\nStart command line script $self\n" );
343 $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
345 if ( $wgDebugPrintHttpHeaders ) {
346 $debug .= "\nHTTP HEADERS:\n";
348 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
349 $debug .= "$name: $value\n";
352 wfDebug( "$debug\n" );
355 wfProfileOut( $fname . '-misc1' );
356 wfProfileIn( $fname . '-memcached' );
358 $wgMemc = wfGetMainCache();
359 $messageMemc = wfGetMessageCacheStorage();
360 $parserMemc = wfGetParserCacheStorage();
362 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
363 get_class( $messageMemc ) . '[message] ' .
364 get_class( $parserMemc ) . "[parser]\n" );
366 wfProfileOut( $fname . '-memcached' );
368 # # Most of the config is out, some might want to run hooks here.
369 wfRunHooks( 'SetupAfterCache' );
371 wfProfileIn( $fname . '-session' );
373 # If session.auto_start is there, we can't touch session name
374 if ( !wfIniGetBool( 'session.auto_start' ) ) {
375 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
378 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
379 if ( $wgRequest->checkSessionCookie() ||
isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
380 wfIncrStats( 'request_with_session' );
382 $wgSessionStarted = true;
384 wfIncrStats( 'request_without_session' );
385 $wgSessionStarted = false;
389 wfProfileOut( $fname . '-session' );
390 wfProfileIn( $fname . '-globals' );
392 $wgContLang = new StubContLang
;
394 // Now that variant lists may be available...
395 $wgRequest->interpolateTitle();
396 $wgUser = RequestContext
::getMain()->user
; # BackCompat
401 $wgLang = new StubUserLang
;
406 $wgOut = RequestContext
::getMain()->output
; # BackCompat
411 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
413 if ( !is_object( $wgAuth ) ) {
414 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
415 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
418 # Placeholders in case of DB error
422 $wgDeferredUpdateList = array();
424 wfProfileOut( $fname . '-globals' );
425 wfProfileIn( $fname . '-extensions' );
427 # Skin setup functions
428 # Entries can be added to this variable during the inclusion
429 # of the extension file. Skins can then perform any necessary initialisation.
430 foreach ( $wgSkinExtensionFunctions as $func ) {
431 call_user_func( $func );
434 # Extension setup functions for extensions other than skins
435 # Entries should be added to this variable during the inclusion
436 # of the extension file. This allows the extension to perform
437 # any necessary initialisation in the fully initialised environment
438 foreach ( $wgExtensionFunctions as $func ) {
439 # Allow closures in PHP 5.3+
440 if ( is_object( $func ) && $func instanceof Closure
) {
441 $profName = $fname . '-extensions-closure';
442 } elseif ( is_array( $func ) ) {
443 if ( is_object( $func[0] ) )
444 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
446 $profName = $fname . '-extensions-' . implode( '::', $func );
448 $profName = $fname . '-extensions-' . strval( $func );
451 wfProfileIn( $profName );
452 call_user_func( $func );
453 wfProfileOut( $profName );
456 require_once( MWInit
::compiledPath( 'includes/normal/UtfNormalDefines.php' ) );
459 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
460 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
461 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
462 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
464 wfDebug( "Fully initialised\n" );
465 $wgFullyInitialised = true;
466 wfProfileOut( $fname . '-extensions' );
467 wfProfileOut( $fname );