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 ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) {
45 # 'view' is assumed the default action path everywhere in the code
46 # but is rarely filled in $wgActionPaths
47 $wgActionPaths['view'] = $wgArticlePath;
50 if ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) {
51 # 'view' is assumed the default action path everywhere in the code
52 # but is rarely filled in $wgActionPaths
53 $wgActionPaths['view'] = $wgArticlePath ;
56 if ( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
57 if ( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins";
58 if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins";
59 if ( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
61 if ( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
63 if ( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
64 if ( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
66 if ( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
68 if ( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
69 if ( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
70 if ( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
72 if ( isset( $wgFileStore['deleted']['directory'] ) ) {
73 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
76 if ( isset( $wgFooterIcons['copyright'] ) &&
77 isset( $wgFooterIcons['copyright']['copyright'] ) &&
78 $wgFooterIcons['copyright']['copyright'] === array() )
80 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
81 $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
82 } elseif ( $wgRightsIcon ||
$wgRightsText ) {
83 $wgFooterIcons['copyright']['copyright'] = array(
84 'url' => $wgRightsUrl,
85 'src' => $wgRightsIcon,
86 'alt' => $wgRightsText,
89 unset( $wgFooterIcons['copyright']['copyright'] );
93 if ( isset( $wgFooterIcons['poweredby'] ) &&
94 isset( $wgFooterIcons['poweredby']['mediawiki'] ) &&
95 $wgFooterIcons['poweredby']['mediawiki']['src'] === null )
97 $wgFooterIcons['poweredby']['mediawiki']['src'] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
101 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
102 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
104 * Note that this is the definition of editinterface and it can be granted to
105 * all users if desired.
107 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
110 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
111 * and "File_talk". The old names "Image" and "Image_talk" are
112 * retained as aliases for backwards compatibility.
114 $wgNamespaceAliases['Image'] = NS_FILE
;
115 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
118 * Initialise $wgLockManagers to include basic FS version
120 $wgLockManagers[] = array(
121 'name' => 'fsLockManager',
122 'class' => 'FSLockManager',
123 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
125 $wgLockManagers[] = array(
126 'name' => 'nullLockManager',
127 'class' => 'NullLockManager',
131 * Initialise $wgLocalFileRepo from backwards-compatible settings
133 if ( !$wgLocalFileRepo ) {
134 if ( isset( $wgFileStore['deleted']['hash'] ) ) {
135 $deletedHashLevel = $wgFileStore['deleted']['hash'];
137 $deletedHashLevel = $wgHashedUploadDirectory ?
3 : 0;
139 $wgLocalFileRepo = array(
140 'class' => 'LocalRepo',
142 'directory' => $wgUploadDirectory,
143 'scriptDirUrl' => $wgScriptPath,
144 'scriptExtension' => $wgScriptExtension,
145 'url' => $wgUploadBaseUrl ?
$wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
146 'hashLevels' => $wgHashedUploadDirectory ?
2 : 0,
147 'thumbScriptUrl' => $wgThumbnailScriptPath,
148 'transformVia404' => !$wgGenerateThumbnailOnParse,
149 'deletedDir' => $wgDeletedDirectory,
150 'deletedHashLevels' => $deletedHashLevel
154 * Initialise shared repo from backwards-compatible settings
156 if ( $wgUseSharedUploads ) {
157 if ( $wgSharedUploadDBname ) {
158 $wgForeignFileRepos[] = array(
159 'class' => 'ForeignDBRepo',
161 'directory' => $wgSharedUploadDirectory,
162 'url' => $wgSharedUploadPath,
163 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
164 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
165 'transformVia404' => !$wgGenerateThumbnailOnParse,
166 'dbType' => $wgDBtype,
167 'dbServer' => $wgDBserver,
168 'dbUser' => $wgDBuser,
169 'dbPassword' => $wgDBpassword,
170 'dbName' => $wgSharedUploadDBname,
171 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG
: 0 ) | DBO_DEFAULT
,
172 'tablePrefix' => $wgSharedUploadDBprefix,
173 'hasSharedCache' => $wgCacheSharedUploads,
174 'descBaseUrl' => $wgRepositoryBaseUrl,
175 'fetchDescription' => $wgFetchCommonsDescriptions,
178 $wgForeignFileRepos[] = array(
179 'class' => 'FileRepo',
181 'directory' => $wgSharedUploadDirectory,
182 'url' => $wgSharedUploadPath,
183 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
184 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
185 'transformVia404' => !$wgGenerateThumbnailOnParse,
186 'descBaseUrl' => $wgRepositoryBaseUrl,
187 'fetchDescription' => $wgFetchCommonsDescriptions,
191 if ( $wgUseInstantCommons ) {
192 $wgForeignFileRepos[] = array(
193 'class' => 'ForeignAPIRepo',
194 'name' => 'wikimediacommons',
195 'apibase' => 'http://commons.wikimedia.org/w/api.php',
197 'fetchDescription' => true,
198 'descriptionCacheExpiry' => 43200,
199 'apiThumbCacheExpiry' => 86400,
203 * Add on default file backend config for repos to $wgFileBackends
205 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
206 $wgFileBackends[] = wfBackendForLegacyRepoConf( $wgLocalFileRepo );
208 foreach ( $wgForeignFileRepos as &$repo ) {
209 if ( !isset( $repo['backend'] ) ) {
210 $wgFileBackends[] = wfBackendForLegacyRepoConf( $repo );
213 unset( $repo ); // no global pollution; destroy reference
215 * Get file backend configuration for a given repo
216 * configuration that lacks a backend parameter.
217 * Also updates the repo config to use the backend.
219 function wfBackendForLegacyRepoConf( &$info ) {
220 global $wgUploadDirectory;
221 // Local vars that used to be FSRepo members...
222 if ( !isset( $info['directory'] ) && $info['class'] === 'ForeignAPIRepo' ) {
223 $info['directory'] = $wgUploadDirectory; // b/c
225 $directory = $info['directory'];
226 $deletedDir = isset( $info['deletedDir'] )
227 ?
$info['deletedDir']
229 $thumbDir = isset( $info['thumbDir'] )
231 : "{$directory}/thumb";
232 $fileMode = isset( $info['fileMode'] )
236 // Make a backend name (based on repo name)
237 $backendName = $info['name'] . '-backend';
238 // Update repo config to use this backend
239 $info['backend'] = $backendName;
240 // Disable "deleted" zone in repo config if deleted dir not set
241 if ( $deletedDir !== false ) {
242 $info['zones']['deleted'] = array(
243 'container' => 'images-deleted', 'directory' => '' );
245 // Get the FS backend configuration
247 'name' => $backendName,
248 'class' => 'FSFileBackend',
249 'lockManager' => 'fsLockManager',
250 'containerPaths' => array(
251 "images-public" => "{$directory}",
252 "images-temp" => "{$directory}/temp",
253 "images-thumb" => $thumbDir,
254 "images-deleted" => $deletedDir
256 'fileMode' => $fileMode,
260 if ( is_null( $wgEnableAutoRotation ) ) {
261 // Only enable auto-rotation when the bitmap handler can rotate
262 $wgEnableAutoRotation = BitmapHandler
::canRotate();
265 if ( $wgRCFilterByAge ) {
266 # # Trim down $wgRCLinkDays so that it only lists links which are valid
267 # # as determined by $wgRCMaxAge.
268 # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
269 sort( $wgRCLinkDays );
270 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++
) {
271 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
272 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i +
1, false );
279 $wgSkipSkins[] = $wgSkipSkin;
282 # Set default shared prefix
283 if ( $wgSharedPrefix === false ) {
284 $wgSharedPrefix = $wgDBprefix;
287 if ( !$wgCookiePrefix ) {
288 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
289 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
290 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
291 $wgCookiePrefix = $wgSharedDB;
292 } elseif ( $wgDBprefix ) {
293 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
295 $wgCookiePrefix = $wgDBname;
298 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
300 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
302 if ( $wgMetaNamespace === false ) {
303 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
307 * Definitions of the NS_ constants are in Defines.php
310 $wgCanonicalNamespaceNames = array(
312 NS_SPECIAL
=> 'Special',
315 NS_USER_TALK
=> 'User_talk',
316 NS_PROJECT
=> 'Project',
317 NS_PROJECT_TALK
=> 'Project_talk',
319 NS_FILE_TALK
=> 'File_talk',
320 NS_MEDIAWIKI
=> 'MediaWiki',
321 NS_MEDIAWIKI_TALK
=> 'MediaWiki_talk',
322 NS_TEMPLATE
=> 'Template',
323 NS_TEMPLATE_TALK
=> 'Template_talk',
325 NS_HELP_TALK
=> 'Help_talk',
326 NS_CATEGORY
=> 'Category',
327 NS_CATEGORY_TALK
=> 'Category_talk',
331 if( is_array( $wgExtraNamespaces ) ) {
332 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames +
$wgExtraNamespaces;
335 # These are now the same, always
336 # To determine the user language, use $wgLang->getCode()
337 $wgContLanguageCode = $wgLanguageCode;
339 # Easy to forget to falsify $wgShowIPinHeader for static caches.
340 # If file cache or squid cache is on, just disable this (DWIMD).
341 if ( $wgUseFileCache ||
$wgUseSquid ) {
342 $wgShowIPinHeader = false;
345 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
346 # in favor of $wgHiddenPrefs, handle b/c here
347 if ( !$wgAllowRealName ) {
348 $wgHiddenPrefs[] = 'realname';
351 # Doesn't make sense to have if disabled.
352 if ( !$wgEnotifMinorEdits ) {
353 $wgHiddenPrefs[] = 'enotifminoredits';
356 # $wgDisabledActions is deprecated as of 1.18
357 foreach( $wgDisabledActions as $action ){
358 $wgActions[$action] = false;
360 if( !$wgAllowPageInfo ){
361 $wgActions['info'] = false;
364 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
365 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
366 if ( $wgMimeType == 'application/xhtml+xml' ) {
367 $wgHtml5Version = 'XHTML+RDFa 1.0';
369 $wgHtml5Version = 'HTML+RDFa 1.0';
373 # Blacklisted file extensions shouldn't appear on the "allowed" list
374 $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist );
376 if ( $wgArticleCountMethod === null ) {
377 $wgArticleCountMethod = $wgUseCommaCount ?
'comma' : 'link';
380 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
381 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime
( "$IP/LocalSettings.php" ) ) );
384 if ( $wgAjaxUploadDestCheck ) {
385 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
388 if ( $wgNewUserLog ) {
390 $wgLogTypes[] = 'newusers';
391 $wgLogNames['newusers'] = 'newuserlogpage';
392 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
393 # newusers, create, create2, autocreate
394 $wgLogActionsHandlers['newusers/*'] = 'NewUsersLogFormatter';
397 if ( $wgCookieSecure === 'detect' ) {
398 $wgCookieSecure = ( substr( $wgServer, 0, 6 ) === 'https:' );
403 if ( !defined( 'MW_COMPILED' ) ) {
404 if ( !MWInit
::classExists( 'AutoLoader' ) ) {
405 require_once( "$IP/includes/AutoLoader.php" );
408 wfProfileIn( $fname . '-exception' );
409 MWExceptionHandler
::installHandler();
410 wfProfileOut( $fname . '-exception' );
412 wfProfileIn( $fname . '-includes' );
413 require_once( "$IP/includes/normal/UtfNormalUtil.php" );
414 require_once( "$IP/includes/GlobalFunctions.php" );
415 require_once( "$IP/includes/ProxyTools.php" );
416 require_once( "$IP/includes/ImageFunctions.php" );
417 require_once( "$IP/includes/normal/UtfNormalDefines.php" );
418 wfProfileOut( $fname . '-includes' );
421 # Now that GlobalFunctions is loaded, set the default for $wgCanonicalServer
422 if ( $wgCanonicalServer === false ) {
423 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP
);
426 wfProfileIn( $fname . '-misc1' );
428 # Raise the memory limit if it's too low
432 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
433 * that happens whenever you use a date function without the timezone being
434 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
436 if ( is_null( $wgLocaltimezone) ) {
437 wfSuppressWarnings();
438 $wgLocaltimezone = date_default_timezone_get();
442 date_default_timezone_set( $wgLocaltimezone );
443 if( is_null( $wgLocalTZoffset ) ) {
444 $wgLocalTZoffset = date( 'Z' ) / 60;
447 # Useful debug output
448 global $wgCommandLineMode;
449 if ( $wgCommandLineMode ) {
450 $wgRequest = new FauxRequest( array() );
452 wfDebug( "\n\nStart command line script $self\n" );
454 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
455 $wgRequest = new WebRequest
;
457 $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
459 if ( $wgDebugPrintHttpHeaders ) {
460 $debug .= "\nHTTP HEADERS:\n";
462 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
463 $debug .= "$name: $value\n";
466 wfDebug( "$debug\n" );
467 MWDebug
::processRequest( $wgRequest );
470 wfProfileOut( $fname . '-misc1' );
471 wfProfileIn( $fname . '-memcached' );
473 $wgMemc = wfGetMainCache();
474 $messageMemc = wfGetMessageCacheStorage();
475 $parserMemc = wfGetParserCacheStorage();
477 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
478 get_class( $messageMemc ) . '[message] ' .
479 get_class( $parserMemc ) . "[parser]\n" );
481 wfProfileOut( $fname . '-memcached' );
483 # # Most of the config is out, some might want to run hooks here.
484 wfRunHooks( 'SetupAfterCache' );
486 wfProfileIn( $fname . '-session' );
488 # If session.auto_start is there, we can't touch session name
489 if ( !wfIniGetBool( 'session.auto_start' ) ) {
490 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
493 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
494 if ( $wgRequest->checkSessionCookie() ||
isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
495 wfIncrStats( 'request_with_session' );
497 $wgSessionStarted = true;
499 wfIncrStats( 'request_without_session' );
500 $wgSessionStarted = false;
504 wfProfileOut( $fname . '-session' );
505 wfProfileIn( $fname . '-globals' );
507 $wgContLang = Language
::factory( $wgLanguageCode );
508 $wgContLang->initEncoding();
509 $wgContLang->initContLang();
511 // Now that variant lists may be available...
512 $wgRequest->interpolateTitle();
513 $wgUser = RequestContext
::getMain()->getUser(); # BackCompat
518 $wgLang = new StubUserLang
;
523 $wgOut = RequestContext
::getMain()->getOutput(); # BackCompat
528 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
530 if ( !is_object( $wgAuth ) ) {
531 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
532 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
535 # Register file lock managers
536 LockManagerGroup
::singleton()->register( $wgLockManagers );
537 # Register file backends
538 FileBackendGroup
::singleton()->register( $wgFileBackends );
540 # Placeholders in case of DB error
543 $wgDeferredUpdateList = array();
545 // We need to check for safe_mode, because mail() will throw an E_NOTICE
546 // on additional parameters
547 if( !is_null($wgAdditionalMailParams) && wfIniGetBool('safe_mode') ) {
548 $wgAdditionalMailParams = null;
551 wfProfileOut( $fname . '-globals' );
552 wfProfileIn( $fname . '-extensions' );
554 # Extension setup functions for extensions other than skins
555 # Entries should be added to this variable during the inclusion
556 # of the extension file. This allows the extension to perform
557 # any necessary initialisation in the fully initialised environment
558 foreach ( $wgExtensionFunctions as $func ) {
559 # Allow closures in PHP 5.3+
560 if ( is_object( $func ) && $func instanceof Closure
) {
561 $profName = $fname . '-extensions-closure';
562 } elseif ( is_array( $func ) ) {
563 if ( is_object( $func[0] ) )
564 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
566 $profName = $fname . '-extensions-' . implode( '::', $func );
568 $profName = $fname . '-extensions-' . strval( $func );
571 wfProfileIn( $profName );
572 call_user_func( $func );
573 wfProfileOut( $profName );
576 wfDebug( "Fully initialised\n" );
577 $wgFullyInitialised = true;
579 wfProfileOut( $fname . '-extensions' );
580 wfProfileOut( $fname );