Allow interlanguage link prefixes that are not language codes
authorThis, that and the other <at.light@live.com.au>
Fri, 20 Jun 2014 01:29:05 +0000 (11:29 +1000)
committerThis, that and the other <at.light@live.com.au>
Fri, 20 Jun 2014 01:29:05 +0000 (11:29 +1000)
$wgExtraInterlanguageLinkPrefixes holds a list of interwiki prefixes to be
treated as language codes if $wgInterwikiMagic is true.

To set the display text for the interlanguage links generated by this
code, you need to create MediaWiki:Interlanguage-link-foo, where "foo" is
the interwiki prefix.  To provide a friendly site name for the link title
text, use MediaWiki:Interlanguage-link-sitename-foo.  On the WMF cluster,
these messages could be set using the WikimediaMessages extension.

Information about extra language links (in the site language only) is
provided via the API in meta=siteinfo&prop=interwikimap.

Bug: 32189
Change-Id: I3d04760e2d9fb3320bb71e3d5ad115eed54a899c

RELEASE-NOTES-1.24
includes/DefaultSettings.php
includes/SkinTemplate.php
includes/api/ApiQuerySiteinfo.php
includes/parser/Parser.php
languages/i18n/en.json
languages/i18n/qqq.json

index 72edd76..4a15e19 100644 (file)
@@ -21,6 +21,10 @@ production.
 * $wgDBClusterTimeout has been removed.
 * $wgProxyKey has been removed. It is no longer used by MediaWiki core.
   Ensure $wgSecretKey is set in LocalSettings.php.
+* $wgExtraInterlanguageLinkPrefixes is a new configuration variable that
+  contains an array of interwiki prefixes that should be treated as language
+  prefixes (i.e. turned into interlanguage links when $wgInterwikiMagic is set
+  to true).
 
 === New features in 1.24 ===
 * Added a new hook, "WhatLinksHereProps", to allow extensions to annotate
index 31ce080..02d1c5a 100644 (file)
@@ -2504,6 +2504,21 @@ $wgInterwikiMagic = true;
  */
 $wgHideInterlanguageLinks = false;
 
+/**
+ * List of additional interwiki prefixes that should be treated as
+ * interlanguage links (i.e. placed in the sidebar).
+ * Notes:
+ * - This will not do anything unless the prefixes are defined in the interwiki
+ *   map.
+ * - The display text for these custom interlanguage links will be fetched from
+ *   the system message "interlanguage-link-xyz" where xyz is the prefix in
+ *   this array.
+ * - A friendly name for each site, used for tooltip text, may optionally be
+ *   placed in the system message "interlanguage-link-sitename-xyz" where xyz is
+ *   the prefix in this array.
+ */
+$wgExtraInterlanguageLinkPrefixes = array();
+
 /**
  * List of language names or overrides for default names in Names.php
  */
index 86bd979..1f78ee5 100644 (file)
@@ -140,8 +140,16 @@ class SkinTemplate extends Skin {
                                $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
 
                                if ( strval( $ilLangName ) === '' ) {
-                                       $ilLangName = $languageLinkText;
+                                       $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
+                                       if ( !$ilDisplayTextMsg->isDisabled() ) {
+                                               // Use custom MW message for the display text
+                                               $ilLangName = $ilDisplayTextMsg->text();
+                                       } else {
+                                               // Last resort: fallback to the language link target
+                                               $ilLangName = $languageLinkText;
+                                       }
                                } else {
+                                       // Use the language autonym as display text
                                        $ilLangName = $this->formatLanguageName( $ilLangName );
                                }
 
@@ -153,7 +161,29 @@ class SkinTemplate extends Skin {
                                );
 
                                $languageLinkTitleText = $languageLinkTitle->getText();
-                               if ( $languageLinkTitleText === '' ) {
+                               if ( $ilLangLocalName === '' ) {
+                                       $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
+                                       if ( !$ilFriendlySiteName->isDisabled() ) {
+                                               if ( $languageLinkTitleText === '' ) {
+                                                       $ilTitle = wfMessage(
+                                                               'interlanguage-link-title-nonlangonly',
+                                                               $ilFriendlySiteName->text()
+                                                       )->text();
+                                               } else {
+                                                       $ilTitle = wfMessage(
+                                                               'interlanguage-link-title-nonlang',
+                                                               $languageLinkTitleText,
+                                                               $ilFriendlySiteName->text()
+                                                       )->text();
+                                               }
+                                       } else {
+                                               // we have nothing friendly to put in the title, so fall back to
+                                               // displaying the interlanguage link itself in the title text
+                                               // (similar to what is done in page content)
+                                               $ilTitle = $languageLinkTitle->getInterwiki() .
+                                                       ":$languageLinkTitleText";
+                                       }
+                               } elseif ( $languageLinkTitleText === '' ) {
                                        $ilTitle = wfMessage(
                                                'interlanguage-link-title-langonly',
                                                $ilLangLocalName
index bb83110..48a4ef4 100644 (file)
@@ -384,6 +384,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $langNames = Language::fetchLanguageNames( $langCode );
 
                $getPrefixes = Interwiki::getAllPrefixes( $local );
+               $extraLangPrefixes = $this->getConfig()->get( 'ExtraInterlanguageLinkPrefixes' );
                $data = array();
 
                foreach ( $getPrefixes as $row ) {
@@ -396,9 +397,24 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        if ( $row['iw_trans'] == '1' ) {
                                $val['trans'] = '';
                        }
+
                        if ( isset( $langNames[$prefix] ) ) {
                                $val['language'] = $langNames[$prefix];
                        }
+                       if ( in_array( $prefix, $extraLangPrefixes ) ) {
+                               $val['extralanglink'] = '';
+
+                               $linktext = wfMessage( "interlanguage-link-$prefix" );
+                               if ( !$linktext->isDisabled() ) {
+                                       $val['linktext'] = $linktext->text();
+                               }
+
+                               $sitename = wfMessage( "interlanguage-link-sitename-$prefix" );
+                               if ( !$sitename->isDisabled() ) {
+                                       $val['sitename'] = $sitename->text();
+                               }
+                       }
+
                        $val['url'] = wfExpandUrl( $row['iw_url'], PROTO_CURRENT );
                        if (substr( $row['iw_url'], 0, 2) == '//') {
                                $val['protorel'] = '';
@@ -743,6 +759,15 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        }
 
        public function getCacheMode( $params ) {
+               // Messages for $wgExtraInterlanguageLinkPrefixes depend on user language
+               if (
+                       count( $this->getConfig()->get( 'ExtraInterlanguageLinkPrefixes' ) ) &&
+                       !is_null( $params['prop'] ) &&
+                       in_array( 'interwikimap', $params['prop'] )
+               ) {
+                       return 'anon-public-user-private';
+               }
+
                return 'public';
        }
 
index 66cfd55..9d63a26 100644 (file)
@@ -1876,6 +1876,7 @@ class Parser {
         * @private
         */
        function replaceInternalLinks2( &$s ) {
+               global $wgExtraInterlanguageLinkPrefixes;
                wfProfileIn( __METHOD__ );
 
                wfProfileIn( __METHOD__ . '-setup' );
@@ -2096,11 +2097,12 @@ class Parser {
                        if ( $noforce ) {
                                # Interwikis
                                wfProfileIn( __METHOD__ . "-interwiki" );
-                               if ( $iw && $this->mOptions->getInterwikiMagic()
-                                       && $nottalk && Language::fetchLanguageName( $iw, null, 'mw' )
+                               if (
+                                       $iw && $this->mOptions->getInterwikiMagic() && $nottalk && (
+                                               Language::fetchLanguageName( $iw, null, 'mw' ) ||
+                                               in_array( $iw, $wgExtraInterlanguageLinkPrefixes )
+                                       )
                                ) {
-                                       // XXX: the above check prevents links to sites with identifiers that are not language codes
-
                                        # Bug 24502: filter duplicates
                                        if ( !isset( $this->mLangLinkLanguages[$iw] ) ) {
                                                $this->mLangLinkLanguages[$iw] = true;
index 14b6b66..71c64d5 100644 (file)
        "tooltip-summary": "Enter a short summary",
        "interlanguage-link-title": "$1 – $2",
        "interlanguage-link-title-langonly": "$1",
+       "interlanguage-link-title-nonlang": "$1 – $2",
+       "interlanguage-link-title-nonlangonly": "$1",
        "common.css": "/* CSS placed here will be applied to all skins */",
        "monobook.css": "/* CSS placed here will affect users of the MonoBook skin */",
        "vector.css": "/* CSS placed here will affect users of the Vector skin */",
index 2a46ed4..f1a23ab 100644 (file)
        "tooltip-summary": "Used as tooltip for Summary input box in Editor page.\n\nSee also:\n* {{msg-mw|Summary}}\n* {{msg-mw|Accesskey-summary}}\n* {{msg-mw|Tooltip-summary}}",
        "interlanguage-link-title": "{{Optional}}\nFormat of a sidebar interwiki link tooltip. Parameters:\n* $1 - page name in the target wiki\n* $2 - target wiki language autonym",
        "interlanguage-link-title-langonly": "{{ignored}}Interlanguage link title. Parameters: $1 replaced with a language name.",
+       "interlanguage-link-title-nonlang": "{{Optional}}\nFormat of a tooltip for a sidebar interwiki link that points to a specific project. Parameters:\n* $1 - page name in the target wiki\n* $2 - name of the target wiki (probably not a language name)",
+       "interlanguage-link-title-nonlangonly": "{{ignored}}Interlanguage link title. Parameters: $1 replaced with name of the target wiki (probably not a language name).",
        "common.css": "{{optional}}\nCSS applied to all users.",
        "monobook.css": "{{optional}}\nCSS applied to users using Monobook skin.",
        "vector.css": "{{optional}}",