From 6cbdf65b4f2ac41fdce956bc271631787dcab15d Mon Sep 17 00:00:00 2001 From: "This, that and the other" Date: Fri, 14 Feb 2014 17:34:35 +1100 Subject: [PATCH] Add $wgLocalInterwikis to handle multiple local prefixes This is akin to $wgSkipSkin/$wgSkipSkins. It is quite plausible for a wiki to have more than one self prefix (e.g. enwiki has w: en: wikipedia: and maybe others). Some recent changes code seems to use $wgLocalInterwiki for quite unclear purposes: - I removed the line using $wgLocalInterwiki from the RecentChange class, as the 'lang' field of $mExtra is not used anywhere in core code. Extensions may use it, but it would seem more appropriate for them to use something like $wgDBname (or indeed to consult $wgLocalInterwikis directly) if they need to identify a particular wiki. - In the IRC formatter, the first prefix in the array is used (if set). Appropriate documentation is added to DefaultSettings.php. Related to bug 954 comment 3. Bug: 954 Bug: 955 Change-Id: I9dbb566385b464402c5e78510b95dd2ffb4d9489 --- RELEASE-NOTES-1.23 | 8 +++++++ includes/DefaultSettings.php | 22 +++++++++++++++---- includes/Setup.php | 4 ++++ includes/Title.php | 22 +++++++++---------- includes/changes/RecentChange.php | 4 +--- .../rcfeed/IRCColourfulRCFeedFormatter.php | 7 +++--- tests/phpunit/includes/TitleTest.php | 2 +- 7 files changed, 47 insertions(+), 22 deletions(-) diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index ad2f747c8c..38302f80eb 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -43,6 +43,11 @@ production. * Removed deprecated $wgDisabledActions as it is hardly used anywhere. * $wgRateLimitLog has been deprecated and replaced by $wgDebugLogGroup['ratelimit']. +* $wgLocalInterwikis is an array containing multiple local interwiki prefixes + (interwiki prefixes that point back to the current wiki). This effectively + allows more than one value of $wgLocalInterwiki to be specified and + understood by the parser. The value of $wgLocalInterwiki is automatically + prepended to the start of this array. === New features in 1.23 === * ResourceLoader can utilize the Web Storage API to cache modules client-side. @@ -284,6 +289,9 @@ changes to languages because of Bugzilla reports. * SpecialRecentChanges no longer includes any functionality for generating feeds - it has been factored out to ApiFeedRecentChanges. Old URLs redirect to new ones. +* RecentChange::mExtra['lang'] is no longer set and should no longer be used. + Extensions should read from other configuration variables, including + $wgLocalInterwikis, to identify the current wiki. ==== Removed classes ==== * FakeMemCachedClient (deprecated in 1.18) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0a238a829f..28f37d25ed 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3491,9 +3491,21 @@ $wgLegalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+"; /** * The interwiki prefix of the current wiki, or false if it doesn't have one. + * + * @deprecated since 1.23; use $wgLocalInterwikis instead */ $wgLocalInterwiki = false; +/** + * Array for multiple $wgLocalInterwiki values, in case there are several + * interwiki prefixes that point to the current wiki. If $wgLocalInterwiki is + * set, its value is prepended to this array, for backwards compatibility. + * + * Note, recent changes feeds use only the first entry in this array (or + * $wgLocalInterwiki, if it is set). See $wgRCFeeds + */ +$wgLocalInterwikis = array(); + /** * Expiry time for cache of interwiki table */ @@ -5578,8 +5590,9 @@ $wgRC2UDPPort = false; $wgRC2UDPPrefix = ''; /** - * If this is set to true, $wgLocalInterwiki will be prepended to links in the - * IRC feed. If this is set to a string, that string will be used as the prefix. + * If this is set to true, the first entry in the $wgLocalInterwikis array (or + * the value of $wgLocalInterwiki, if set) will be prepended to links in the IRC + * feed. If this is set to a string, that string will be used as the prefix. * * @deprecated since 1.22, use $wgRCFeeds */ @@ -5607,11 +5620,12 @@ $wgRC2UDPOmitBots = false; * * 'omit_bots' -- whether the bot edits should be in the feed * The IRC-specific options are: * * 'add_interwiki_prefix' -- whether the titles should be prefixed with - * $wgLocalInterwiki. + * the first entry in the $wgLocalInterwikis array (or the value of + * $wgLocalInterwiki, if set) * The JSON-specific options are: * * 'channel' -- if set, the 'channel' parameter is also set in JSON values. * - * To ensure backwards-compatability, whenever $wgRC2UDPAddress is set, a + * To ensure backwards-compatibility, whenever $wgRC2UDPAddress is set, a * 'default' feed will be created reusing the deprecated $wgRC2UDP* variables. * * @example $wgRCFeeds['example'] = array( diff --git a/includes/Setup.php b/includes/Setup.php index 209edefc28..d7438e5faf 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -265,6 +265,10 @@ if ( $wgSkipSkin ) { $wgSkipSkins[] = $wgSkipSkin; } +if ( $wgLocalInterwiki ) { + array_unshift( $wgLocalInterwikis, $wgLocalInterwiki ); +} + # Set default shared prefix if ( $wgSharedPrefix === false ) { $wgSharedPrefix = $wgDBprefix; diff --git a/includes/Title.php b/includes/Title.php index a705aaa1eb..c85a0068fc 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -3200,7 +3200,7 @@ class Title { * @return Bool true on success */ private function secureAndSplit() { - global $wgContLang, $wgLocalInterwiki; + global $wgContLang, $wgLocalInterwikis; # Initialisation $this->mInterwiki = ''; @@ -3273,17 +3273,17 @@ class Title { $this->mInterwiki = $wgContLang->lc( $p ); # Redundant interwiki prefix to the local wiki - if ( $wgLocalInterwiki !== false - && 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) - ) { - if ( $dbkey == '' ) { - # Can't have an empty self-link - return false; + foreach ( $wgLocalInterwikis as $localIW ) { + if ( 0 == strcasecmp( $this->mInterwiki, $localIW ) ) { + if ( $dbkey == '' ) { + # Can't have an empty self-link + return false; + } + $this->mInterwiki = ''; + $firstPass = false; + # Do another namespace split... + continue 2; } - $this->mInterwiki = ''; - $firstPass = false; - # Do another namespace split... - continue; } # If there's an initial colon after the interwiki, that also diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 01ad72481c..072aa12f1e 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -52,7 +52,6 @@ * mExtra: * prefixedDBkey prefixed db key, used by external app via msg queue * lastTimestamp timestamp of previous entry, used in WHERE clause during update - * lang the interwiki prefix, automatically set in save() * oldSize text size before the change * newSize text size after the change * pageStatus status of the page: created, deleted, moved, restored, changed @@ -231,13 +230,12 @@ class RecentChange { * @param $noudp bool */ public function save( $noudp = false ) { - global $wgLocalInterwiki, $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang; + global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang; $dbw = wfGetDB( DB_MASTER ); if ( !is_array( $this->mExtra ) ) { $this->mExtra = array(); } - $this->mExtra['lang'] = $wgLocalInterwiki; if ( !$wgPutIPinRC ) { $this->mAttribs['rc_ip'] = ''; diff --git a/includes/rcfeed/IRCColourfulRCFeedFormatter.php b/includes/rcfeed/IRCColourfulRCFeedFormatter.php index ddbb548540..22ddfb8279 100644 --- a/includes/rcfeed/IRCColourfulRCFeedFormatter.php +++ b/includes/rcfeed/IRCColourfulRCFeedFormatter.php @@ -30,7 +30,7 @@ class IRCColourfulRCFeedFormatter implements RCFeedFormatter { * @see RCFeedFormatter::getLine */ public function getLine( array $feed, RecentChange $rc, $actionComment ) { - global $wgUseRCPatrol, $wgUseNPPatrol, $wgLocalInterwiki, + global $wgUseRCPatrol, $wgUseNPPatrol, $wgLocalInterwikis, $wgCanonicalServer, $wgScript; $attribs = $rc->getAttributes(); if ( $attribs['rc_type'] == RC_LOG ) { @@ -88,8 +88,9 @@ class IRCColourfulRCFeedFormatter implements RCFeedFormatter { $flag .= ( $attribs['rc_type'] == RC_NEW ? "N" : "" ) . ( $attribs['rc_minor'] ? "M" : "" ) . ( $attribs['rc_bot'] ? "B" : "" ); } - if ( $feed['add_interwiki_prefix'] === true && $wgLocalInterwiki !== false ) { - $prefix = $wgLocalInterwiki; + if ( $feed['add_interwiki_prefix'] === true && $wgLocalInterwikis ) { + // we use the first entry in $wgLocalInterwikis in recent changes feeds + $prefix = $wgLocalInterwikis[0]; } elseif ( $feed['add_interwiki_prefix'] ) { $prefix = $feed['add_interwiki_prefix']; } else { diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 078dfefdf4..1305724246 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -41,7 +41,7 @@ class TitleTest extends MediaWikiTestCase { */ public function testSecureAndSplit() { $this->setMwGlobals( array( - 'wgLocalInterwiki' => 'localtestiw', + 'wgLocalInterwikis' => array( 'localtestiw' ), 'wgHooks' => array( 'InterwikiLoadPrefix' => array( function ( $prefix, &$data ) { -- 2.20.1