3ff6eba5ad3cf11a878e5526c931986ea7e0283e
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 ( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
51 if ( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins";
52 if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins";
53 if ( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
55 if ( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
57 if ( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
58 if ( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
60 if ( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
62 if ( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
63 if ( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
64 if ( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
66 if ( isset( $wgFileStore['deleted']['directory'] ) ) {
67 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
70 if ( isset( $wgFooterIcons['copyright'] ) &&
71 isset( $wgFooterIcons['copyright']['copyright'] ) &&
72 $wgFooterIcons['copyright']['copyright'] === array() )
74 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
75 $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
76 } elseif ( $wgRightsIcon ||
$wgRightsText ) {
77 $wgFooterIcons['copyright']['copyright'] = array(
78 'url' => $wgRightsUrl,
79 'src' => $wgRightsIcon,
80 'alt' => $wgRightsText,
83 unset( $wgFooterIcons['copyright']['copyright'] );
87 if ( isset( $wgFooterIcons['poweredby'] ) &&
88 isset( $wgFooterIcons['poweredby']['mediawiki'] ) &&
89 $wgFooterIcons['poweredby']['mediawiki']['src'] === null )
91 $wgFooterIcons['poweredby']['mediawiki']['src'] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
95 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
96 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
98 * Note that this is the definition of editinterface and it can be granted to
99 * all users if desired.
101 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
104 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
105 * and "File_talk". The old names "Image" and "Image_talk" are
106 * retained as aliases for backwards compatibility.
108 $wgNamespaceAliases['Image'] = NS_FILE
;
109 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
112 * Initialise $wgLocalFileRepo from backwards-compatible settings
114 if ( !$wgLocalFileRepo ) {
115 if ( isset( $wgFileStore['deleted']['hash'] ) ) {
116 $deletedHashLevel = $wgFileStore['deleted']['hash'];
118 $deletedHashLevel = $wgHashedUploadDirectory ?
3 : 0;
120 $wgLocalFileRepo = array(
121 'class' => 'LocalRepo',
123 'directory' => $wgUploadDirectory,
124 'scriptDirUrl' => $wgScriptPath,
125 'scriptExtension' => $wgScriptExtension,
126 'url' => $wgUploadBaseUrl ?
$wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
127 'hashLevels' => $wgHashedUploadDirectory ?
2 : 0,
128 'thumbScriptUrl' => $wgThumbnailScriptPath,
129 'transformVia404' => !$wgGenerateThumbnailOnParse,
130 'deletedDir' => $wgDeletedDirectory,
131 'deletedHashLevels' => $deletedHashLevel
135 * Initialise shared repo from backwards-compatible settings
137 if ( $wgUseSharedUploads ) {
138 if ( $wgSharedUploadDBname ) {
139 $wgForeignFileRepos[] = array(
140 'class' => 'ForeignDBRepo',
142 'directory' => $wgSharedUploadDirectory,
143 'url' => $wgSharedUploadPath,
144 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
145 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
146 'transformVia404' => !$wgGenerateThumbnailOnParse,
147 'dbType' => $wgDBtype,
148 'dbServer' => $wgDBserver,
149 'dbUser' => $wgDBuser,
150 'dbPassword' => $wgDBpassword,
151 'dbName' => $wgSharedUploadDBname,
152 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG
: 0 ) | DBO_DEFAULT
,
153 'tablePrefix' => $wgSharedUploadDBprefix,
154 'hasSharedCache' => $wgCacheSharedUploads,
155 'descBaseUrl' => $wgRepositoryBaseUrl,
156 'fetchDescription' => $wgFetchCommonsDescriptions,
159 $wgForeignFileRepos[] = array(
162 'directory' => $wgSharedUploadDirectory,
163 'url' => $wgSharedUploadPath,
164 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
165 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
166 'transformVia404' => !$wgGenerateThumbnailOnParse,
167 'descBaseUrl' => $wgRepositoryBaseUrl,
168 'fetchDescription' => $wgFetchCommonsDescriptions,
172 if ( $wgUseInstantCommons ) {
173 $wgForeignFileRepos[] = array(
174 'class' => 'ForeignAPIRepo',
175 'name' => 'wikimediacommons',
176 'apibase' => 'http://commons.wikimedia.org/w/api.php',
178 'fetchDescription' => true,
179 'descriptionCacheExpiry' => 43200,
180 'apiThumbCacheExpiry' => 86400,
184 if ( $wgRCFilterByAge ) {
185 # # Trim down $wgRCLinkDays so that it only lists links which are valid
186 # # as determined by $wgRCMaxAge.
187 # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
188 sort( $wgRCLinkDays );
189 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++
) {
190 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
191 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i +
1, false );
198 $wgSkipSkins[] = $wgSkipSkin;
201 # Set default shared prefix
202 if ( $wgSharedPrefix === false ) {
203 $wgSharedPrefix = $wgDBprefix;
206 if ( !$wgCookiePrefix ) {
207 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
208 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
209 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
210 $wgCookiePrefix = $wgSharedDB;
211 } elseif ( $wgDBprefix ) {
212 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
214 $wgCookiePrefix = $wgDBname;
217 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
219 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
221 if ( $wgMetaNamespace === false ) {
222 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
226 * Definitions of the NS_ constants are in Defines.php
229 $wgCanonicalNamespaceNames = array(
231 NS_SPECIAL
=> 'Special',
234 NS_USER_TALK
=> 'User_talk',
235 NS_PROJECT
=> 'Project',
236 NS_PROJECT_TALK
=> 'Project_talk',
238 NS_FILE_TALK
=> 'File_talk',
239 NS_MEDIAWIKI
=> 'MediaWiki',
240 NS_MEDIAWIKI_TALK
=> 'MediaWiki_talk',
241 NS_TEMPLATE
=> 'Template',
242 NS_TEMPLATE_TALK
=> 'Template_talk',
244 NS_HELP_TALK
=> 'Help_talk',
245 NS_CATEGORY
=> 'Category',
246 NS_CATEGORY_TALK
=> 'Category_talk',
250 if( is_array( $wgExtraNamespaces ) ) {
251 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames +
$wgExtraNamespaces;
254 # These are now the same, always
255 # To determine the user language, use $wgLang->getCode()
256 $wgContLanguageCode = $wgLanguageCode;
258 # Easy to forget to falsify $wgShowIPinHeader for static caches.
259 # If file cache or squid cache is on, just disable this (DWIMD).
260 if ( $wgUseFileCache ||
$wgUseSquid ) {
261 $wgShowIPinHeader = false;
264 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
265 # in favor of $wgHiddenPrefs, handle b/c here
266 if ( !$wgAllowRealName ) {
267 $wgHiddenPrefs[] = 'realname';
270 # Doesn't make sense to have if disabled.
271 if ( !$wgEnotifMinorEdits ) {
272 $wgHiddenPrefs[] = 'enotifminoredits';
275 # $wgDisabledActions is deprecated as of 1.18
276 foreach( $wgDisabledActions as $action ){
277 $wgActions[$action] = false;
279 if( !$wgAllowPageInfo ){
280 $wgActions['info'] = false;
283 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
284 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
285 if ( $wgMimeType == 'application/xhtml+xml' ) {
286 $wgHtml5Version = 'XHTML+RDFa 1.0';
288 $wgHtml5Version = 'HTML+RDFa 1.0';
292 # Blacklisted file extensions shouldn't appear on the "allowed" list
293 $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist );
295 if ( $wgArticleCountMethod === null ) {
296 $wgArticleCountMethod = $wgUseCommaCount ?
'comma' : 'link';
299 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
300 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime
( "$IP/LocalSettings.php" ) ) );
303 if ( $wgAjaxUploadDestCheck ) {
304 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
307 if ( $wgNewUserLog ) {
309 $wgLogTypes[] = 'newusers';
310 $wgLogNames['newusers'] = 'newuserlogpage';
311 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
312 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
313 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
314 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
315 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
318 if ( !defined( 'MW_COMPILED' ) ) {
319 if ( !MWInit
::classExists( 'AutoLoader' ) ) {
320 require_once( "$IP/includes/AutoLoader.php" );
323 wfProfileIn( $fname . '-exception' );
324 require_once( "$IP/includes/Exception.php" );
325 wfInstallExceptionHandler();
326 wfProfileOut( $fname . '-exception' );
328 wfProfileIn( $fname . '-includes' );
329 require_once( "$IP/includes/normal/UtfNormalUtil.php" );
330 require_once( "$IP/includes/GlobalFunctions.php" );
331 require_once( "$IP/includes/Hooks.php" );
332 require_once( "$IP/includes/ProxyTools.php" );
333 require_once( "$IP/includes/ImageFunctions.php" );
334 wfProfileOut( $fname . '-includes' );
336 require_once( MWInit
::compiledPath( 'includes/normal/UtfNormalDefines.php' ) );
338 wfProfileIn( $fname . '-misc1' );
340 # Raise the memory limit if it's too low
344 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
345 * that happens whenever you use a date function without the timezone being
346 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
348 if ( is_null( $wgLocaltimezone) ) {
349 wfSuppressWarnings();
350 $wgLocaltimezone = date_default_timezone_get();
354 date_default_timezone_set( $wgLocaltimezone );
355 if( is_null( $wgLocalTZoffset ) ) {
356 $wgLocalTZoffset = date( 'Z' ) / 60;
359 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
360 $wgRequest = new WebRequest
;
362 # Useful debug output
363 global $wgCommandLineMode;
364 if ( $wgCommandLineMode ) {
365 wfDebug( "\n\nStart command line script $self\n" );
367 $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
369 if ( $wgDebugPrintHttpHeaders ) {
370 $debug .= "\nHTTP HEADERS:\n";
372 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
373 $debug .= "$name: $value\n";
376 wfDebug( "$debug\n" );
379 wfProfileOut( $fname . '-misc1' );
380 wfProfileIn( $fname . '-memcached' );
382 $wgMemc = wfGetMainCache();
383 $messageMemc = wfGetMessageCacheStorage();
384 $parserMemc = wfGetParserCacheStorage();
386 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
387 get_class( $messageMemc ) . '[message] ' .
388 get_class( $parserMemc ) . "[parser]\n" );
390 wfProfileOut( $fname . '-memcached' );
392 # # Most of the config is out, some might want to run hooks here.
393 wfRunHooks( 'SetupAfterCache' );
395 wfProfileIn( $fname . '-session' );
397 # If session.auto_start is there, we can't touch session name
398 if ( !wfIniGetBool( 'session.auto_start' ) ) {
399 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
402 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
403 if ( $wgRequest->checkSessionCookie() ||
isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
404 wfIncrStats( 'request_with_session' );
406 $wgSessionStarted = true;
408 wfIncrStats( 'request_without_session' );
409 $wgSessionStarted = false;
413 wfProfileOut( $fname . '-session' );
414 wfProfileIn( $fname . '-globals' );
416 $wgContLang = Language
::factory( $wgLanguageCode );
417 $wgContLang->initEncoding();
418 $wgContLang->initContLang();
420 // Now that variant lists may be available...
421 $wgRequest->interpolateTitle();
422 $wgUser = RequestContext
::getMain()->getUser(); # BackCompat
427 $wgLang = new StubUserLang
;
432 $wgOut = RequestContext
::getMain()->getOutput(); # BackCompat
437 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
439 if ( !is_object( $wgAuth ) ) {
440 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
441 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
444 # Placeholders in case of DB error
448 $wgDeferredUpdateList = array();
450 wfProfileOut( $fname . '-globals' );
451 wfProfileIn( $fname . '-extensions' );
453 # Extension setup functions for extensions other than skins
454 # Entries should be added to this variable during the inclusion
455 # of the extension file. This allows the extension to perform
456 # any necessary initialisation in the fully initialised environment
457 foreach ( $wgExtensionFunctions as $func ) {
458 # Allow closures in PHP 5.3+
459 if ( is_object( $func ) && $func instanceof Closure
) {
460 $profName = $fname . '-extensions-closure';
461 } elseif ( is_array( $func ) ) {
462 if ( is_object( $func[0] ) )
463 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
465 $profName = $fname . '-extensions-' . implode( '::', $func );
467 $profName = $fname . '-extensions-' . strval( $func );
470 wfProfileIn( $profName );
471 call_user_func( $func );
472 wfProfileOut( $profName );
475 wfDebug( "Fully initialised\n" );
476 $wgFullyInitialised = true;
478 wfProfileOut( $fname . '-extensions' );
479 wfProfileOut( $fname );