From 07bb8ce5b5d5ef5c59fad6176b6c64ec7b66a745 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 6 Dec 2010 15:00:56 +0000 Subject: [PATCH] Remove some of the rubbish that has been accumulating in the default LocalSettings.php for years, especially code as opposed to configuration data: * Don't set $IP. The entry point already sets it, so there's no point. Users can still set it if they can figure out a way to do it without breaking things. * Don't include DefaultSettings.php. Doing that is code, not configuration, and it can easily be done in WebStart/Maintenance. Some non-standard entry points in extensions may be broken by this. That's their fault for being non-standard. Backwards compatibility is preserved thanks to require_once(). * Introduce $wgInvalidateCacheOnLocalSettingsChange, which when set, causes $wgCacheEpoch to be updated in the way that it previously was in the default LocalSettings.php. * Don't set $wgLocalInterwiki to some nonsense value (possibly including spaces and punctuation in the new installer). It should be only for actual interwiki prefixes. Since most wikis don't have them, I set this to false by default and adjusted the referring code to accept this. * Removed the guard for web invocation with $wgCommandLineMode set. This ancient code is redundant with modern protections in doMaintenance.php. * In DefaultSettings.php, fixed fold terminator placement near $wgLoadScript * Add a web entry point guard. That's one piece of code which really is necessary. --- RELEASE-NOTES | 5 ++++ includes/DefaultSettings.php | 26 ++++++++++++++++--- includes/RecentChange.php | 2 +- includes/Setup.php | 3 +++ includes/Title.php | 4 ++- includes/WebStart.php | 5 ++-- includes/installer/LocalSettingsGenerator.php | 22 +++------------- maintenance/doMaintenance.php | 3 +-- 8 files changed, 40 insertions(+), 30 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2ff7a0b280..2fa6d15608 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -91,6 +91,11 @@ LocalSettings.php. The specific bugs are listed below in the general notes. the footers of skins. * $wgFileCacheDepth can be used to set the depth of the subdirectory hierarchy used for the file cache. Default value is 2, which matches former behavior +* It's no longer necessary for LocalSettings.php to include DefaultSettings.php. +* It's no longer necessary to set $wgCacheEpoch to the file modification time + of LocalSettings.php, in LocalSettings.php itself. Instead, this is done + automatically if $wgInvalidateCacheOnLocalSettingsChange is true (which is + the default). === New features in 1.17 === * (bug 10183) Users can now add personal styles and scripts to all skins via diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 33a61017cb..7d3588e667 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -26,7 +26,6 @@ if( !defined( 'MEDIAWIKI' ) ) { die( 1 ); } - # Create a site configuration object. Not used for much in a default install if ( !defined( 'MW_PHP4' ) ) { require_once( "$IP/includes/SiteConfiguration.php" ); @@ -140,7 +139,6 @@ $wgScript = false; * Defaults to "{$wgScriptPath}/redirect{$wgScriptExtension}". */ $wgRedirectScript = false; ///< defaults to -/**@}*/ /** * The URL path to load.php. @@ -149,6 +147,8 @@ $wgRedirectScript = false; ///< defaults to */ $wgLoadScript = false; +/**@}*/ + /************************************************************************//** * @name URLs and file paths * @@ -1665,6 +1665,17 @@ $wgUseETag = false; */ $wgClockSkewFudge = 5; +/** + * Invalidate various caches when LocalSettings.php changes. This is equivalent + * to setting $wgCacheEpoch to the modification time of LocalSettings.php, as + * was previously done in the default LocalSettings.php file. + * + * On high-traffic wikis, this should be set to false, to avoid the need to + * check the file modification time, and to avoid the performance impact of + * unnecessary cache invalidations. + */ +$wgInvalidateCacheOnLocalSettingsChange = true; + /** @} */ # end of cache settings /************************************************************************//** @@ -2486,8 +2497,15 @@ $wgNamespaceAliases = array(); */ $wgLegalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+"; -$wgLocalInterwiki = 'w'; -$wgInterwikiExpiry = 10800; # Expiry time for cache of interwiki table +/** + * The interwiki prefix of the current wiki, or false if it doesn't have one. + */ +$wgLocalInterwiki = false; + +/** + * Expiry time for cache of interwiki table + */ +$wgInterwikiExpiry = 10800; /** Interwiki caching settings. $wgInterwikiCache specifies path to constant database file diff --git a/includes/RecentChange.php b/includes/RecentChange.php index bf8379c4af..803420f62c 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -674,7 +674,7 @@ class RecentChange { $flag .= ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : ""); } - if ( $wgRC2UDPInterwikiPrefix === true ) { + if ( $wgRC2UDPInterwikiPrefix === true && $wgLocalInterwiki !== false ) { $prefix = $wgLocalInterwiki; } elseif ( $wgRC2UDPInterwikiPrefix ) { $prefix = $wgRC2UDPInterwikiPrefix; diff --git a/includes/Setup.php b/includes/Setup.php index b937c0ead8..fbaac94b42 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -289,6 +289,9 @@ if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) { else $wgHtml5Version = 'HTML+RDFa 1.0'; } +if ( $wgInvalidateCacheOnLocalSettingsChange ) { + $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) ); +} wfProfileOut( $fname.'-misc1' ); wfProfileIn( $fname.'-memcached' ); diff --git a/includes/Title.php b/includes/Title.php index 599b808e3b..21028ea777 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2645,7 +2645,9 @@ class Title { $this->mInterwiki = $wgContLang->lc( $p ); # Redundant interwiki prefix to the local wiki - if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) { + if ( $wgLocalInterwiki !== false + && 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) + { if ( $dbkey == '' ) { # Can't have an empty self-link return false; diff --git a/includes/WebStart.php b/includes/WebStart.php index 428b4ffeb7..f05d563066 100644 --- a/includes/WebStart.php +++ b/includes/WebStart.php @@ -91,11 +91,11 @@ if ( !function_exists( 'version_compare' ) # Start the autoloader, so that extensions can derive classes from core files require_once( "$IP/includes/AutoLoader.php" ); +# Load default settings +require_once( "$IP/includes/DefaultSettings.php" ); if ( defined( 'MW_CONFIG_CALLBACK' ) ) { # Use a callback function to configure MediaWiki - require_once( "$IP/includes/DefaultSettings.php" ); - $callback = MW_CONFIG_CALLBACK; # PHP 5.1 doesn't support "class::method" for call_user_func, so split it if ( strpos( $callback, '::' ) !== false ) { @@ -110,7 +110,6 @@ if ( defined( 'MW_CONFIG_CALLBACK' ) ) { # the wiki installer needs to be launched or the generated file moved from # ./config/ to ./ if( !file_exists( MW_CONFIG_FILE ) ) { - require_once( "$IP/includes/DefaultSettings.php" ); # used for printing the version require_once( "$IP/includes/templates/NoLocalSettings.php" ); die(); } diff --git a/includes/installer/LocalSettingsGenerator.php b/includes/installer/LocalSettingsGenerator.php index e3eb957101..b7a8d778df 100644 --- a/includes/installer/LocalSettingsGenerator.php +++ b/includes/installer/LocalSettingsGenerator.php @@ -197,21 +197,11 @@ class LocalSettingsGenerator { # Further documentation for configuration settings may be found at: # http://www.mediawiki.org/wiki/Manual:Configuration_settings -# If you customize your file layout, set \$IP to the directory that contains -# the other MediaWiki files. It will be used as a base to locate files. -if( defined( 'MW_INSTALL_PATH' ) ) { - \$IP = MW_INSTALL_PATH; -} else { - \$IP = dirname( __FILE__ ); +# Protect against web entry +if ( !defined( 'MEDIAWIKI' ) ) { + exit; } -require_once( \"\$IP/includes/DefaultSettings.php\" ); - -if ( \$wgCommandLineMode ) { - if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) { - die( \"This script must be run from the command line\\n\" ); - } -} ## Uncomment this to disable output compression # \$wgDisableOutputCompression = true; @@ -285,8 +275,6 @@ if ( \$wgCommandLineMode ) { ## be publically accessible from the web. #\$wgCacheDirectory = \"\$IP/cache\"; -\$wgLocalInterwiki = strtolower( \$wgSitename ); - # Site language code, should be one of ./languages/Language(.*).php \$wgLanguageCode = \"{$this->values['wgLanguageCode']}\"; @@ -313,10 +301,6 @@ if ( \$wgCommandLineMode ) { # Path to the GNU diff3 utility. Used for conflict resolution. \$wgDiff3 = \"{$this->values['wgDiff3']}\"; -# When you make changes to this configuration file, this will make -# sure that cached pages are cleared. -\$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) ); - # Enabled Extensions. Most extensions are enabled by including the base extension file here # but check specific extension documentation for more details "; diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index 794776decf..292604a6f1 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -61,11 +61,10 @@ if ( file_exists( "$IP/StartProfiler.php" ) ) { // Some other requires require_once( "$IP/includes/AutoLoader.php" ); require_once( "$IP/includes/Defines.php" ); +require_once( "$IP/includes/DefaultSettings.php" ); if ( defined( 'MW_CONFIG_CALLBACK' ) ) { # Use a callback function to configure MediaWiki - require_once( "$IP/includes/DefaultSettings.php" ); - $callback = MW_CONFIG_CALLBACK; # PHP 5.1 doesn't support "class::method" for call_user_func, so split it if ( strpos( $callback, '::' ) !== false ) { -- 2.20.1