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 # $wgDisabledActions is deprecated as of 1.18
274 foreach( $wgDisabledActions as $action ){
275 $wgActions[$action] = false;
277 if( !$wgAllowPageInfo ){
278 $wgActions['info'] = false;
281 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
282 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
283 if ( $wgMimeType == 'application/xhtml+xml' ) {
284 $wgHtml5Version = 'XHTML+RDFa 1.0';
286 $wgHtml5Version = 'HTML+RDFa 1.0';
290 # Blacklisted file extensions shouldn't appear on the "allowed" list
291 $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist );
293 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
294 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime
( "$IP/LocalSettings.php" ) ) );
297 if ( $wgAjaxUploadDestCheck ) {
298 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
301 if ( $wgNewUserLog ) {
303 $wgLogTypes[] = 'newusers';
304 $wgLogNames['newusers'] = 'newuserlogpage';
305 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
306 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
307 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
308 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
309 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
312 if ( !defined( 'MW_COMPILED' ) ) {
313 if ( !MWInit
::classExists( 'AutoLoader' ) ) {
314 require_once( "$IP/includes/AutoLoader.php" );
317 wfProfileIn( $fname . '-exception' );
318 require_once( "$IP/includes/Exception.php" );
319 wfInstallExceptionHandler();
320 wfProfileOut( $fname . '-exception' );
322 wfProfileIn( $fname . '-includes' );
323 require_once( "$IP/includes/GlobalFunctions.php" );
324 require_once( "$IP/includes/Hooks.php" );
325 require_once( "$IP/includes/ProxyTools.php" );
326 require_once( "$IP/includes/ImageFunctions.php" );
327 wfProfileOut( $fname . '-includes' );
329 wfProfileIn( $fname . '-misc1' );
331 # Raise the memory limit if it's too low
335 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
336 * that happens whenever you use a date function without the timezone being
337 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
339 wfSuppressWarnings();
340 date_default_timezone_set( date_default_timezone_get() );
343 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
344 $wgRequest = new WebRequest
;
346 # Useful debug output
347 global $wgCommandLineMode;
348 if ( $wgCommandLineMode ) {
349 wfDebug( "\n\nStart command line script $self\n" );
351 $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
353 if ( $wgDebugPrintHttpHeaders ) {
354 $debug .= "\nHTTP HEADERS:\n";
356 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
357 $debug .= "$name: $value\n";
360 wfDebug( "$debug\n" );
363 wfProfileOut( $fname . '-misc1' );
364 wfProfileIn( $fname . '-memcached' );
366 $wgMemc = wfGetMainCache();
367 $messageMemc = wfGetMessageCacheStorage();
368 $parserMemc = wfGetParserCacheStorage();
370 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
371 get_class( $messageMemc ) . '[message] ' .
372 get_class( $parserMemc ) . "[parser]\n" );
374 wfProfileOut( $fname . '-memcached' );
376 # # Most of the config is out, some might want to run hooks here.
377 wfRunHooks( 'SetupAfterCache' );
379 wfProfileIn( $fname . '-session' );
381 # If session.auto_start is there, we can't touch session name
382 if ( !wfIniGetBool( 'session.auto_start' ) ) {
383 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
386 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
387 if ( $wgRequest->checkSessionCookie() ||
isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
388 wfIncrStats( 'request_with_session' );
390 $wgSessionStarted = true;
392 wfIncrStats( 'request_without_session' );
393 $wgSessionStarted = false;
397 wfProfileOut( $fname . '-session' );
398 wfProfileIn( $fname . '-globals' );
400 $wgContLang = Language
::factory( $wgLanguageCode );
401 $wgContLang->initEncoding();
402 $wgContLang->initContLang();
404 // Now that variant lists may be available...
405 $wgRequest->interpolateTitle();
406 $wgUser = RequestContext
::getMain()->getUser(); # BackCompat
411 $wgLang = new StubUserLang
;
416 $wgOut = RequestContext
::getMain()->getOutput(); # BackCompat
421 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
423 if ( !is_object( $wgAuth ) ) {
424 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
425 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
428 # Placeholders in case of DB error
432 $wgDeferredUpdateList = array();
434 wfProfileOut( $fname . '-globals' );
435 wfProfileIn( $fname . '-extensions' );
437 # Extension setup functions for extensions other than skins
438 # Entries should be added to this variable during the inclusion
439 # of the extension file. This allows the extension to perform
440 # any necessary initialisation in the fully initialised environment
441 foreach ( $wgExtensionFunctions as $func ) {
442 # Allow closures in PHP 5.3+
443 if ( is_object( $func ) && $func instanceof Closure
) {
444 $profName = $fname . '-extensions-closure';
445 } elseif ( is_array( $func ) ) {
446 if ( is_object( $func[0] ) )
447 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
449 $profName = $fname . '-extensions-' . implode( '::', $func );
451 $profName = $fname . '-extensions-' . strval( $func );
454 wfProfileIn( $profName );
455 call_user_func( $func );
456 wfProfileOut( $profName );
460 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
461 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
462 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
463 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
465 wfDebug( "Fully initialised\n" );
466 $wgFullyInitialised = true;
467 wfProfileOut( $fname . '-extensions' );
469 require_once( MWInit
::compiledPath( 'includes/normal/UtfNormalDefines.php' ) );
471 wfProfileOut( $fname );