From 7665f7d7674dbdf785c71ddafce0721a2e130cf3 Mon Sep 17 00:00:00 2001 From: "This, that and the other" Date: Fri, 20 Jun 2014 11:29:05 +1000 Subject: [PATCH] Allow interlanguage link prefixes that are not language codes $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 | 4 ++++ includes/DefaultSettings.php | 15 ++++++++++++++ includes/SkinTemplate.php | 34 +++++++++++++++++++++++++++++-- includes/api/ApiQuerySiteinfo.php | 25 +++++++++++++++++++++++ includes/parser/Parser.php | 10 +++++---- languages/i18n/en.json | 2 ++ languages/i18n/qqq.json | 2 ++ 7 files changed, 86 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 72edd7665d..4a15e19484 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -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 diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 31ce08079c..02d1c5a246 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 */ diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 86bd9797a9..1f78ee5e56 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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 diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index bb83110151..48a4ef4852 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -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'; } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 66cfd550bf..9d63a265dd 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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; diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 14b6b66da3..71c64d5696 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -2471,6 +2471,8 @@ "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 */", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 2a46ed41e8..f1a23ab074 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2633,6 +2633,8 @@ "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}}", -- 2.20.1