Add $wgLocalInterwikis to handle multiple local prefixes
authorThis, that and the other <at.light@live.com.au>
Fri, 14 Feb 2014 06:34:35 +0000 (17:34 +1100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Wed, 12 Mar 2014 12:32:07 +0000 (13:32 +0100)
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
includes/DefaultSettings.php
includes/Setup.php
includes/Title.php
includes/changes/RecentChange.php
includes/rcfeed/IRCColourfulRCFeedFormatter.php
tests/phpunit/includes/TitleTest.php

index ad2f747..38302f8 100644 (file)
@@ -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)
index 0a238a8..28f37d2 100644 (file)
@@ -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(
index 209edef..d7438e5 100644 (file)
@@ -265,6 +265,10 @@ if ( $wgSkipSkin ) {
        $wgSkipSkins[] = $wgSkipSkin;
 }
 
+if ( $wgLocalInterwiki ) {
+       array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
+}
+
 # Set default shared prefix
 if ( $wgSharedPrefix === false ) {
        $wgSharedPrefix = $wgDBprefix;
index a705aaa..c85a006 100644 (file)
@@ -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
index 01ad724..072aa12 100644 (file)
@@ -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'] = '';
index ddbb548..22ddfb8 100644 (file)
@@ -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 {
index 078dfef..1305724 100644 (file)
@@ -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 ) {