Hoo man has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/314283 )
Change subject: Remove sorting of interwiki links
......................................................................
Remove sorting of interwiki links
This is now provided by the InterwikiSorting extension
Depends-On: Iffdb846e3c86c1a585a60eb14a3f4aead59c0706
Change-Id: I221802a136de5e5bb576d9ab00fb1b64eda53965
---
M client/WikibaseClient.php
M client/config/WikibaseClient.default.php
D client/includes/Hooks/InterwikiSortingHookHandlers.php
D client/includes/InterwikiSorter.php
D client/tests/phpunit/includes/Hooks/InterwikiSortingHookHandlersTest.php
M client/tests/phpunit/includes/Hooks/SidebarHookHandlersTest.php
D client/tests/phpunit/includes/InterwikiSorterTest.php
M docs/options.wiki
8 files changed, 0 insertions(+), 764 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index 9f107ad..c10a7f9 100644
--- a/client/WikibaseClient.php
+++ b/client/WikibaseClient.php
@@ -71,7 +71,6 @@
global $wgAPIListModules, $wgAPIMetaModules, $wgAPIPropModules,
$wgSpecialPages;
global $wgResourceModules, $wgWBClientSettings, $wgRecentChangesFlags,
$wgMessagesDirs;
global $wgJobClasses, $wgTrackingCategories, $wgWBClientDataTypes;
- global $wgWikibaseInterwikiSorting;
$wgExtensionCredits['wikibase'][] = array(
'path' => __DIR__,
@@ -110,9 +109,6 @@
$wgHooks['OutputPageParserOutput'][] =
'\Wikibase\Client\Hooks\SidebarHookHandlers::onOutputPageParserOutput';
$wgHooks['SkinTemplateGetLanguageLink'][] =
'\Wikibase\Client\Hooks\SidebarHookHandlers::onSkinTemplateGetLanguageLink';
$wgHooks['ContentAlterParserOutput'][] =
'\Wikibase\Client\Hooks\ParserOutputUpdateHookHandlers::onContentAlterParserOutput';
- if ( !isset( $wgWikibaseInterwikiSorting ) ||
$wgWikibaseInterwikiSorting ) {
- $wgHooks['ContentAlterParserOutput'][] =
'\Wikibase\Client\Hooks\InterwikiSortingHookHandlers::onContentAlterParserOutput';
- }
$wgHooks['SidebarBeforeOutput'][] =
'\Wikibase\Client\Hooks\SidebarHookHandlers::onSidebarBeforeOutput';
$wgHooks['ParserFirstCallInit'][] =
'\Wikibase\ClientHooks::onParserFirstCallInit';
diff --git a/client/config/WikibaseClient.default.php
b/client/config/WikibaseClient.default.php
index 5c8bae5..efb7fc0 100644
--- a/client/config/WikibaseClient.default.php
+++ b/client/config/WikibaseClient.default.php
@@ -19,8 +19,6 @@
$defaults = [
'namespaces' => [], // by default, include all namespaces;
deprecated as of 0.4
'excludeNamespaces' => [],
- 'sort' => 'code',
- 'sortPrepend' => [],
// @todo would be great to just get this from the sites stuff
// but we will need to make sure the caching works good enough
'siteLocalID' => $wgLanguageCode,
@@ -87,128 +85,6 @@
// This is both a repo and client setting, and should be set to
the same value in
// repo and clients for multiwiki setups.
'sharedCacheType' => $GLOBALS['wgMainCacheType'],
-
- /**
- * @todo this is a bit wikimedia-specific and need to find a
better place for this stuff,
- * such as mediawiki-config, mediawiki messages for custom
orders, or somewhere.
- *
- * alphabetic and alphabetic revised come from:
- *
http://meta.wikimedia.org/w/index.php?title=MediaWiki:Interwiki_config-sorting_order-native-languagename
- *
http://meta.wikimedia.org/w/index.php?title=MediaWiki:Interwiki_config-sorting_order-native-languagename-firstword
(revised)
- * and from pywikipedia for alphabetic_sr
- */
- 'interwikiSortOrders' => [
- 'alphabetic' => [
- 'ace', 'kbd', 'ady', 'af', 'ak', 'als', 'am',
'ang', 'ab', 'ar', 'an', 'arc',
- 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av',
'ay', 'az', 'azb', 'bm', 'bn', 'bjn',
- 'zh-min-nan', 'nan', 'map-bms', 'ba', 'be',
'be-x-old', 'bh', 'bcl', 'bi',
- 'bg', 'bar', 'bo', 'bs', 'br', 'bxr', 'ca',
'cv', 'ceb', 'cs', 'ch',
- 'cbk-zam', 'ny', 'sn', 'tum', 'cho', 'co',
'cy', 'da', 'dk', 'pdc', 'de',
- 'dv', 'nv', 'dsb', 'dz', 'mh', 'et', 'el',
'eml', 'en', 'myv', 'es', 'eo',
- 'ext', 'eu', 'ee', 'fa', 'hif', 'fo', 'fr',
'fy', 'ff', 'fur', 'ga', 'gv',
- 'gag', 'gd', 'gl', 'gan', 'ki', 'glk', 'gu',
'got', 'gom', 'hak', 'xal', 'ko',
- 'ha', 'haw', 'hy', 'hi', 'ho', 'hsb', 'hr',
'io', 'ig', 'ilo', 'bpy', 'id', 'ia',
- 'ie', 'iu', 'ik', 'os', 'xh', 'zu', 'is', 'it',
'he', 'jv', 'kl', 'kn', 'kr',
- 'pam', 'krc', 'ka', 'ks', 'csb', 'kk', 'kw',
'rw', 'rn', 'sw', 'kv', 'kg',
- 'ht', 'ku', 'kj', 'ky', 'mrj', 'lad', 'lbe',
'lez', 'lo', 'lrc', 'ltg', 'la',
- 'lv', 'lb', 'lt', 'lij', 'li', 'ln', 'olo',
'jbo', 'lg', 'lmo', 'hu', 'mai', 'mk',
- 'mg', 'ml', 'mt', 'mi', 'mr', 'xmf', 'arz',
'mzn', 'ms', 'min', 'cdo', 'mwl',
- 'mdf', 'mo', 'mn', 'mus', 'my', 'nah', 'na',
'fj', 'nl', 'nds-nl', 'cr', 'ne',
- 'new', 'ja', 'nap', 'ce', 'frr', 'pih', 'no',
'nb', 'nn', 'nrm', 'nov', 'ii', 'oc',
- 'mhr', 'or', 'om', 'ng', 'hz', 'uz', 'pa',
'pi', 'pfl', 'pag', 'pnb', 'pap', 'ps',
- 'jam', 'koi', 'km', 'pcd', 'pms', 'tpi', 'nds',
'pl', 'tokipona', 'tp', 'pnt', 'pt',
- 'aa', 'kaa', 'crh', 'ty', 'ksh', 'ro', 'rmy',
'rm', 'qu', 'rue', 'ru', 'sah',
- 'se', 'sm', 'sa', 'sg', 'sc', 'sco', 'stq',
'st', 'nso', 'tn', 'sq', 'scn',
- 'si', 'simple', 'sd', 'ss', 'sk', 'sl', 'cu',
'szl', 'so', 'ckb', 'srn', 'sr',
- 'sh', 'su', 'fi', 'sv', 'tl', 'ta', 'shi',
'kab', 'roa-tara', 'tt', 'te', 'tet',
- 'th', 'ti', 'tg', 'to', 'chr', 'chy', 've',
'tcy', 'tr', 'tk', 'tw', 'tyv', 'udm', 'bug',
- 'uk', 'ur', 'ug', 'za', 'vec', 'vep', 'vi',
'vo', 'fiu-vro', 'wa', 'zh-classical',
- 'vls', 'war', 'wo', 'wuu', 'ts', 'yi', 'yo',
'zh-yue', 'diq', 'zea', 'bat-smg',
- 'zh', 'zh-tw', 'zh-cn'
- ],
- 'alphabetic_revised' => [
- 'ace', 'ady', 'kbd', 'af', 'ak', 'als', 'am',
'ang', 'ab', 'ar', 'an', 'arc', 'roa-rup',
- 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az',
'azb', 'bjn', 'id', 'ms', 'bm', 'bn',
- 'zh-min-nan', 'nan', 'map-bms', 'jv', 'su',
'ba', 'min', 'be', 'be-x-old', 'bh',
- 'bcl', 'bi', 'bar', 'bo', 'bs', 'br', 'bug',
'bg', 'bxr', 'ca', 'ceb', 'cv', 'cs',
- 'ch', 'cbk-zam', 'ny', 'sn', 'tum', 'cho',
'co', 'cy', 'da', 'dk', 'pdc', 'de',
- 'dv', 'nv', 'dsb', 'na', 'dz', 'mh', 'et',
'el', 'eml', 'en', 'myv', 'es', 'eo',
- 'ext', 'eu', 'ee', 'fa', 'hif', 'fo', 'fr',
'fy', 'ff', 'fur', 'ga', 'gv', 'sm',
- 'gag', 'gd', 'gl', 'gan', 'ki', 'glk', 'gu',
'got', 'gom', 'hak', 'xal', 'ko',
- 'ha', 'haw', 'hy', 'hi', 'ho', 'hsb', 'hr',
'io', 'ig', 'ilo', 'bpy', 'ia', 'ie',
- 'iu', 'ik', 'os', 'xh', 'zu', 'is', 'it', 'he',
'kl', 'kn', 'kr', 'pam', 'ka',
- 'ks', 'csb', 'kk', 'kw', 'rw', 'ky', 'rn',
'mrj', 'sw', 'kv', 'kg', 'ht', 'ku',
- 'kj', 'lad', 'lbe', 'lez', 'lo', 'la', 'lrc',
'ltg', 'lv', 'to', 'lb', 'lt', 'lij',
- 'li', 'ln', 'olo', 'jbo', 'lg', 'lmo', 'hu',
'mai', 'mk', 'mg', 'ml', 'krc', 'mt',
- 'mi', 'mr', 'xmf', 'arz', 'mzn', 'cdo', 'mwl',
'koi', 'mdf', 'mo', 'mn', 'mus', 'my',
- 'nah', 'fj', 'nl', 'nds-nl', 'cr', 'ne',
'new', 'ja', 'nap', 'ce', 'frr', 'pih', 'no',
- 'nb', 'nn', 'nrm', 'nov', 'ii', 'oc', 'mhr',
'or', 'om', 'ng', 'hz', 'uz', 'pa',
- 'pi', 'pfl', 'pag', 'pnb', 'pap', 'ps', 'jam',
'km', 'pcd', 'pms', 'nds', 'pl', 'pnt',
- 'pt', 'aa', 'kaa', 'crh', 'ty', 'ksh', 'ro',
'rmy', 'rm', 'qu', 'ru', 'rue', 'sah',
- 'se', 'sa', 'sg', 'sc', 'sco', 'stq', 'st',
'nso', 'tn', 'sq', 'scn', 'si',
- 'simple', 'sd', 'ss', 'sk', 'sl', 'cu', 'szl',
'so', 'ckb', 'srn', 'sr', 'sh',
- 'fi', 'sv', 'tl', 'ta', 'shi', 'kab',
'roa-tara', 'tt', 'te', 'tet', 'th', 'vi',
- 'ti', 'tg', 'tpi', 'tokipona', 'tp', 'chr',
'chy', 've', 'tcy', 'tr', 'tk', 'tw',
- 'tyv', 'udm', 'uk', 'ur', 'ug', 'za', 'vec',
'vep', 'vo', 'fiu-vro', 'wa',
- 'zh-classical', 'vls', 'war', 'wo', 'wuu',
'ts', 'yi', 'yo', 'zh-yue', 'diq',
- 'zea', 'bat-smg', 'zh', 'zh-tw', 'zh-cn'
- ],
- 'alphabetic_sr' => [
- 'ace', 'ady', 'kbd', 'af', 'ak', 'als', 'am',
'ang', 'ab', 'ar', 'an', 'arc',
- 'roa-rup', 'frp', 'arz', 'as', 'ast', 'gn',
'av', 'ay', 'az', 'azb', 'bjn', 'id',
- 'ms', 'bg', 'bm', 'zh-min-nan', 'nan',
'map-bms', 'jv', 'su', 'ba', 'be',
- 'be-x-old', 'bh', 'bcl', 'bi', 'bn', 'bo',
'bar', 'bs', 'bpy', 'br', 'bug',
- 'bxr', 'ca', 'ceb', 'ch', 'cbk-zam', 'sn',
'tum', 'ny', 'cho', 'chr', 'co',
- 'cy', 'cv', 'cs', 'da', 'dk', 'pdc', 'de',
'nv', 'dsb', 'na', 'dv', 'dz',
- 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es',
'eo', 'ext', 'eu', 'ee', 'fa',
- 'hif', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga',
'gv', 'sm', 'gag', 'gd', 'gl',
- 'gan', 'ki', 'glk', 'got', 'gom', 'gu', 'ha',
'hak', 'xal', 'haw', 'he',
- 'hi', 'ho', 'hsb', 'hr', 'hy', 'io', 'ig',
'ii', 'ilo', 'ia', 'ie', 'iu',
- 'ik', 'os', 'xh', 'zu', 'is', 'it', 'ja', 'ka',
'kl', 'kr', 'pam', 'krc',
- 'csb', 'kk', 'kw', 'rw', 'ky', 'mrj', 'rn',
'sw', 'km', 'kn', 'ko', 'kv',
- 'kg', 'ht', 'ks', 'ku', 'kj', 'lad', 'lbe',
'la', 'lrc', 'ltg', 'lv', 'to',
- 'lb', 'lez', 'lt', 'lij', 'li', 'ln', 'olo',
'lo', 'jbo', 'lg', 'lmo', 'hu', 'mai',
- 'mk', 'mg', 'mt', 'mi', 'min', 'cdo', 'mwl',
'ml', 'mdf', 'mo', 'mn', 'mr', 'mus',
- 'my', 'mzn', 'nah', 'fj', 'ne', 'nl', 'nds-nl',
'cr', 'new', 'nap', 'ce',
- 'frr', 'pih', 'no', 'nb', 'nn', 'nrm', 'nov',
'oc', 'mhr', 'or', 'om', 'ng',
- 'hz', 'uz', 'pa', 'pfl', 'pag', 'pap', 'koi',
'pi', 'pcd', 'pms', 'nds',
- 'pnb', 'pl', 'pt', 'pnt', 'ps', 'jam', 'aa',
'kaa', 'crh', 'ty', 'ksh', 'ro', 'rmy',
- 'rm', 'qu', 'ru', 'rue', 'sa', 'sah', 'se',
'sg', 'sc', 'sco', 'sd', 'stq',
- 'st', 'nso', 'tn', 'sq', 'si', 'scn', 'simple',
'ss', 'sk', 'sl', 'cu', 'szl',
- 'so', 'ckb', 'srn', 'sr', 'sh', 'fi', 'sv',
'ta', 'shi', 'tl', 'kab',
- 'roa-tara', 'tt', 'te', 'tet', 'th', 'ti',
'vi', 'tg', 'tokipona', 'tp',
- 'tpi', 'chy', 've', 'tcy', 'tr', 'tk', 'tw',
'tyv', 'udm', 'uk', 'ur', 'ug', 'za', 'vec',
- 'vep', 'vo', 'fiu-vro', 'wa', 'vls', 'war',
'wo', 'wuu', 'ts', 'xmf', 'yi',
- 'yo', 'diq', 'zea', 'zh', 'zh-tw', 'zh-cn',
'zh-classical', 'zh-yue', 'bat-smg'
- ],
- 'alphabetic_fy' => [
- 'aa', 'ab', 'ace', 'ady', 'af', 'ay', 'ak',
'als', 'am', 'an', 'ang', 'ar', 'arc',
- 'arz', 'as', 'ast', 'av', 'az', 'azb', 'ba',
'bar', 'bat-smg', 'bcl', 'be', 'be-x-old',
- 'bg', 'bh', 'bi', 'bjn', 'bm', 'bn', 'bo',
'bpy', 'br', 'bs', 'bug', 'bxr',
- 'ca', 'cbk-zam', 'cdo', 'ce', 'ceb', 'ch',
'chy', 'cho', 'chr', 'cy', 'ckb',
- 'co', 'cr', 'crh', 'cs', 'csb', 'cu', 'cv',
'da', 'de', 'diq', 'dk', 'dsb', 'dv',
- 'dz', 'ee', 'el', 'eml', 'en', 'eo', 'es',
'et', 'eu', 'ext', 'fa', 'ff', 'fi',
- 'fy', 'fiu-vro', 'fj', 'fo', 'fr', 'frp',
'frr', 'fur', 'ga', 'gag', 'gan', 'gd',
- 'gl', 'glk', 'gn', 'got', 'gom', 'gu', 'gv',
'ha', 'hak', 'haw', 'he', 'hi', 'hy',
- 'hif', 'ho', 'hr', 'hsb', 'ht', 'hu', 'hz',
'ia', 'id', 'ie', 'ig', 'ii', 'yi',
- 'ik', 'ilo', 'io', 'yo', 'is', 'it', 'iu',
'ja', 'jam', 'jbo', 'jv', 'ka', 'kaa', 'kab',
- 'kbd', 'kg', 'ki', 'ky', 'kj', 'kk', 'kl',
'km', 'kn', 'ko', 'koi', 'kr', 'krc',
- 'ks', 'ksh', 'ku', 'kv', 'kw', 'la', 'lad',
'lb', 'lbe', 'lez', 'lg', 'li', 'lij',
- 'lmo', 'ln', 'lo', 'lrc', 'lt', 'ltg', 'lv',
'mai', 'map-bms', 'mdf', 'mg', 'mh',
- 'mhr', 'mi', 'my', 'min', 'myv', 'mk', 'ml',
'mn', 'mo', 'mr', 'mrj', 'ms', 'mt',
- 'mus', 'mwl', 'mzn', 'na', 'nah', 'nan', 'nap',
'nds', 'nds-nl', 'ne', 'new', 'ng',
- 'ny', 'nl', 'nn', 'no', 'nov', 'nrm', 'nso',
'nv', 'oc', 'olo', 'om', 'or', 'os', 'pa',
- 'pag', 'pam', 'pap', 'pcd', 'pdc', 'pfl', 'pi',
'pih', 'pl', 'pms', 'pnb', 'pnt',
- 'ps', 'pt', 'qu', 'rm', 'rmy', 'rn', 'ro',
'roa-rup', 'roa-tara', 'ru', 'rue',
- 'rw', 'sa', 'sah', 'sc', 'scn', 'sco', 'sd',
'se', 'sg', 'sh', 'shi', 'si', 'simple',
- 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr',
'srn', 'ss', 'st', 'stq', 'su', 'sv',
- 'sw', 'szl', 'ta', 'tcy', 'te', 'tet', 'tg',
'th', 'ti', 'ty', 'tk', 'tl', 'tn', 'to',
- 'tokipona', 'tp', 'tpi', 'tr', 'ts', 'tt',
'tum', 'tw', 'tyv', 'udm', 'ug', 'uk', 'ur',
- 'uz', 've', 'vec', 'vep', 'vi', 'vls', 'vo',
'wa', 'war', 'wo', 'wuu', 'xal',
- 'xh', 'xmf', 'za', 'zea', 'zh', 'zh-classical',
'zh-cn', 'zh-yue', 'zh-min-nan',
- 'zh-tw', 'zu'
- ],
- ],
'repositoryServiceWiringFiles' => [ __DIR__ .
'/../includes/Store/RepositoryServiceWiring.php' ],
'dispatchingServiceWiringFiles' => [ __DIR__ .
'/../includes/DispatchingServiceWiring.php' ],
diff --git a/client/includes/Hooks/InterwikiSortingHookHandlers.php
b/client/includes/Hooks/InterwikiSortingHookHandlers.php
deleted file mode 100644
index e73efd9..0000000
--- a/client/includes/Hooks/InterwikiSortingHookHandlers.php
+++ /dev/null
@@ -1,165 +0,0 @@
-<?php
-
-namespace Wikibase\Client\Hooks;
-
-use Config;
-use Content;
-use MediaWiki\MediaWikiServices;
-use ParserOutput;
-use Title;
-use Wikibase\Client\WikibaseClient;
-use Wikibase\InterwikiSorter;
-use Wikibase\NamespaceChecker;
-use Wikibase\NoLangLinkHandler;
-use Wikibase\SettingsArray;
-
-/**
- * @license GPL-2.0+
- */
-class InterwikiSortingHookHandlers {
-
- /**
- * @var InterwikiSorter
- */
- private $interwikiSorter;
-
- /**
- * @var NamespaceChecker
- */
- private $namespaceChecker;
-
- /**
- * @return self
- */
- public static function newFromGlobalState() {
- $wikibaseClient = WikibaseClient::getDefaultInstance();
- $namespaceChecker = $wikibaseClient->getNamespaceChecker();
-
- $config = MediaWikiServices::getInstance()->getMainConfig();
-
- if (
- $config->has( 'InterwikiSortingSort' ) &&
- $config->has( 'InterwikiSortingInterwikiSortOrders' ) &&
- $config->has( 'InterwikiSortingSortPrepend' )
- ) {
- return self::newFromInterwikiSortingConfig( $config,
$namespaceChecker );
- }
-
- $settings = $wikibaseClient->getSettings();
-
- return self::newFromWikibaseConfig( $settings,
$namespaceChecker );
- }
-
- /**
- * @param Config $config
- * @param NamespaceChecker $namespaceChecker
- *
- * @return self
- */
- public static function newFromInterwikiSortingConfig(
- Config $config,
- NamespaceChecker $namespaceChecker
- ) {
- $interwikiSorter = new InterwikiSorter(
- $config->get( 'InterwikiSortingSort' ),
- $config->get( 'InterwikiSortingInterwikiSortOrders' ),
- $config->get( 'InterwikiSortingSortPrepend' )
- );
-
- return new self(
- $interwikiSorter,
- $namespaceChecker
- );
- }
-
- /**
- * @param SettingsArray $settings
- * @param NamespaceChecker $namespaceChecker
- *
- * @return self
- */
- public static function newFromWikibaseConfig(
- SettingsArray $settings,
- NamespaceChecker $namespaceChecker
- ) {
- $interwikiSorter = new InterwikiSorter(
- $settings->getSetting( 'sort' ),
- $settings->getSetting( 'interwikiSortOrders' ),
- $settings->getSetting( 'sortPrepend' )
- );
-
- return new self(
- $interwikiSorter,
- $namespaceChecker
- );
- }
-
- /**
- * Static handler for the ContentAlterParserOutput hook.
- *
- * @param Content $content
- * @param Title $title
- * @param ParserOutput $parserOutput
- *
- * @return bool
- */
- public static function onContentAlterParserOutput(
- Content $content,
- Title $title,
- ParserOutput $parserOutput
- ) {
- $handler = self::newFromGlobalState();
- $handler->doContentAlterParserOutput( $title, $parserOutput );
-
- return true;
- }
-
- /**
- * @param InterwikiSorter $sorter
- * @param NamespaceChecker $namespaceChecker
- */
- public function __construct(
- InterwikiSorter $sorter,
- NamespaceChecker $namespaceChecker
- ) {
- $this->interwikiSorter = $sorter;
- $this->namespaceChecker = $namespaceChecker;
- }
-
- /**
- * Hook runs after internal parsing
- * @see
https://www.mediawiki.org/wiki/Manual:Hooks/ContentAlterParserOutput
- *
- * @param Title $title
- * @param ParserOutput $parserOutput
- *
- * @return void
- */
- public function doContentAlterParserOutput( Title $title, ParserOutput
$parserOutput ) {
- if ( !$this->namespaceChecker->isWikibaseEnabled(
$title->getNamespace() ) ) {
- return;
- }
-
- if ( !$this->hasNoExternalLangLinks( $parserOutput ) ) {
- $interwikiLinks = $parserOutput->getLanguageLinks();
- $sortedLinks = $this->interwikiSorter->sortLinks(
$interwikiLinks );
- $parserOutput->setLanguageLinks( $sortedLinks );
- }
- }
-
- /**
- * @param ParserOutput $parserOutput
- *
- * @return bool
- */
- private function hasNoExternalLangLinks( ParserOutput $parserOutput ) {
- $noExternalLangLinks =
NoLangLinkHandler::getNoExternalLangLinks( $parserOutput );
-
- if ( in_array( '*', $noExternalLangLinks ) ) {
- return true;
- }
-
- return false;
- }
-
-}
diff --git a/client/includes/InterwikiSorter.php
b/client/includes/InterwikiSorter.php
deleted file mode 100644
index 22a5c38..0000000
--- a/client/includes/InterwikiSorter.php
+++ /dev/null
@@ -1,140 +0,0 @@
-<?php
-
-namespace Wikibase;
-
-/**
- * Language sorting utility functions.
- *
- * @license GPL-2.0+
- * @author Nikola Smolenski <[email protected]>
- * @author Katie Filbert < [email protected] >
- * @author Thiemo Mättig
- */
-class InterwikiSorter {
-
- /**
- * @see Documentation of "sort" and "interwikiSortOrders" options in
docs/options.wiki.
- */
- const SORT_CODE = 'code';
-
- /**
- * @var array[]
- */
- private $sortOrders;
-
- /**
- * @var string
- */
- private $sort;
-
- /**
- * @var string[]
- */
- private $sortPrepend;
-
- /**
- * @var int[]|null
- */
- private $sortOrder = null;
-
- /**
- * @param string $sort
- * @param array[] $sortOrders
- * @param string[] $sortPrepend
- */
- public function __construct( $sort, array $sortOrders = array(), array
$sortPrepend = array() ) {
- $this->sort = $sort;
- $this->sortOrders = $sortOrders;
- $this->sortPrepend = $sortPrepend;
- }
-
- /**
- * Sort an array of links in-place
- * @version Copied from InterlanguageExtension rev 114818
- *
- * @param string[] $links
- *
- * @return string[]
- */
- public function sortLinks( array $links ) {
- if ( $this->sortOrder === null ) {
- $this->sortOrder = $this->buildSortOrder( $this->sort,
$this->sortOrders );
- }
-
- // Prepare the array for sorting.
- foreach ( $links as $k => $langLink ) {
- $links[$k] = explode( ':', $langLink, 2 );
- }
-
- usort( $links, array( $this, 'compareLinks' ) );
-
- // Restore the sorted array.
- foreach ( $links as $k => $langLink ) {
- $links[$k] = implode( ':', $langLink );
- }
-
- return $links;
- }
-
- /**
- * usort() callback function, compares the links on the basis of
$sortOrder
- *
- * @param string[] $a
- * @param string[] $b
- *
- * @return int
- */
- private function compareLinks( array $a, array $b ) {
- $a = $a[0];
- $b = $b[0];
-
- if ( $a === $b ) {
- return 0;
- }
-
- $aIndex = array_key_exists( $a, $this->sortOrder ) ?
$this->sortOrder[$a] : null;
- $bIndex = array_key_exists( $b, $this->sortOrder ) ?
$this->sortOrder[$b] : null;
-
- if ( $aIndex === $bIndex ) {
- // If we encounter multiple unknown languages, which
may happen if the sort table is not
- // updated, we list them alphabetically.
- return strcmp( $a, $b );
- } elseif ( $aIndex === null ) {
- // Unknown languages must go under the known languages.
- return 1;
- } elseif ( $bIndex === null ) {
- return -1;
- } else {
- return $aIndex - $bIndex;
- }
- }
-
- /**
- * Build sort order to be used by compareLinks().
- *
- * @param string $sort
- * @param array[] $sortOrders
- *
- * @return int[]
- */
- private function buildSortOrder( $sort, array $sortOrders ) {
- if ( $sort === self::SORT_CODE ) {
- // The concept of known/unknown languages is irrelevant
in strict code order.
- $sortOrder = array();
- } elseif ( !array_key_exists( $sort, $sortOrders ) ) {
- // Something went wrong, but we can use default "code"
order.
- wfDebugLog( __CLASS__, __FUNCTION__
- . ': Invalid or unknown sort order specified
for interwiki links.' );
- $sortOrder = array();
- } else {
- $sortOrder = $sortOrders[$sort];
- }
-
- if ( $this->sortPrepend !== array() ) {
- $sortOrder = array_unique( array_merge(
$this->sortPrepend, $sortOrder ) );
- }
-
- return array_flip( $sortOrder );
- }
-
-}
diff --git
a/client/tests/phpunit/includes/Hooks/InterwikiSortingHookHandlersTest.php
b/client/tests/phpunit/includes/Hooks/InterwikiSortingHookHandlersTest.php
deleted file mode 100644
index 27055c5..0000000
--- a/client/tests/phpunit/includes/Hooks/InterwikiSortingHookHandlersTest.php
+++ /dev/null
@@ -1,180 +0,0 @@
-<?php
-
-namespace Wikibase\Client\Tests\Hooks;
-
-use Config;
-use ContentHandler;
-use HashConfig;
-use MediaWikiTestCase;
-use ParserOutput;
-use Title;
-use Wikibase\Client\Hooks\InterwikiSortingHookHandlers;
-use Wikibase\InterwikiSorter;
-use Wikibase\NamespaceChecker;
-use Wikibase\NoLangLinkHandler;
-use Wikibase\SettingsArray;
-
-/**
- * @covers Wikibase\Client\Hooks\InterwikiSortingHookHandlers
- *
- * @group WikibaseClient
- * @group Wikibase
- * @group WikibaseHooks
- *
- * @license GPL-2.0+
- * @author Katie Filbert < [email protected] >
- */
-class InterwikiSortingHookHandlersTest extends MediaWikiTestCase {
-
- public function testNewFromGlobalState() {
- $hookHandlers =
InterwikiSortingHookHandlers::newFromGlobalState();
-
- $this->assertInstanceOf( InterwikiSortingHookHandlers::class,
$hookHandlers );
- }
-
- public function testNewFromInterwikiSortingConfig() {
- $config = $this->getConfig();
- $hookHandlers =
InterwikiSortingHookHandlers::newFromInterwikiSortingConfig(
- $config,
- $this->getNamespaceChecker( true )
- );
-
- $this->assertInstanceOf( InterwikiSortingHookHandlers::class,
$hookHandlers );
- }
-
- public function testNewFromWikibaseConfig() {
- $settings = new SettingsArray( [
- 'sort' => 'code',
- 'sortPrepend' => [],
- 'interwikiSortOrders' => [
- 'alphabetic' => [
- 'ar', 'de', 'en', 'sv', 'zh'
- ]
- ]
- ] );
-
- $hookHandlers =
InterwikiSortingHookHandlers::newFromWikibaseConfig(
- $settings,
- $this->getNamespaceChecker( false )
- );
-
- $this->assertInstanceOf( InterwikiSortingHookHandlers::class,
$hookHandlers );
- }
-
- public function testOnContentAlterParserOutput() {
- $parserOutput = new ParserOutput();
- $title = Title::makeTitle( NS_HELP, 'InterwikiSortTestPage' );
- $content = ContentHandler::makeContent( 'sorted kittens',
$title );
-
- InterwikiSortingHookHandlers::onContentAlterParserOutput(
- $content,
- $title,
- $parserOutput
- );
-
- // sanity check
- $this->assertInstanceOf( 'ParserOutput', $parserOutput );
- }
-
- /**
- * @dataProvider doContentAlterParserOutputProvider
- */
- public function testDoContentAlterParserOutput(
- $expected,
- $parserOutput,
- $wikibaseEnabledForNamespace,
- $msg
- ) {
- $config = $this->getConfig();
-
- $interwikiSorter = new InterwikiSorter(
- $config->get( 'InterwikiSortingSort' ),
- $config->get( 'InterwikiSortingInterwikiSortOrders' ),
- $config->get( 'InterwikiSortingSortPrepend' )
- );
-
- $interwikiSortingHookHandlers = new
InterwikiSortingHookHandlers(
- $interwikiSorter,
- $this->getNamespaceChecker(
$wikibaseEnabledForNamespace )
- );
-
- $title = Title::makeTitle( NS_HELP, 'InterwikiSortTestPage' );
-
- $interwikiSortingHookHandlers->doContentAlterParserOutput(
$title, $parserOutput );
- $languageLinks = $parserOutput->getLanguageLinks();
-
- $this->assertSame( $expected, $languageLinks, $msg );
- }
-
- public function doContentAlterParserOutputProvider() {
- return [
- [
- [ 'fr:Chat', 'de:Katzen', 'en:Cat', 'es:Gato' ],
- $this->getParserOutput( [ 'es:Gato', 'en:Cat',
'fr:Chat', 'de:Katzen' ], false ),
- true,
- 'external links'
- ],
- [
- [ 'es:Gato', 'de:Katzen' ],
- $this->getParserOutput( [ 'es:Gato',
'de:Katzen' ], true ),
- true,
- 'noexternallanglinks'
- ],
- [
- [ 'es:Gato', 'en:Cat', 'fr:Chat', 'de:Katzen' ],
- $this->getParserOutput( [ 'es:Gato', 'en:Cat',
'fr:Chat', 'de:Katzen' ], false ),
- false,
- 'wikibase not enabled for namespace'
- ]
-
- ];
- }
-
- /**
- * @param string[] $languageLinks
- * @param bool $noExternalLangLinks
- *
- * @return ParserOutput
- */
- private function getParserOutput( array $languageLinks,
$noExternalLangLinks ) {
- $parserOutput = new ParserOutput();
- $parserOutput->setLanguageLinks( $languageLinks );
-
- if ( $noExternalLangLinks === true ) {
- NoLangLinkHandler::setNoExternalLangLinks(
$parserOutput, [ '*' ] );
- }
-
- return $parserOutput;
- }
-
- /**
- * @return Config
- */
- private function getConfig() {
- $settings = [
- 'InterwikiSortingSort' => InterwikiSorter::SORT_CODE,
- 'InterwikiSortingInterwikiSortOrders' => [
- 'alphabetic' => [ 'ar', 'de', 'en', 'es', 'fr' ]
- ],
- 'InterwikiSortingSortPrepend' => [ 'fr' ],
- ];
-
- return new HashConfig( $settings );
- }
-
- /**
- * @return NamespaceChecker
- */
- private function getNamespaceChecker( $wikibaseEnabledForNamespace ) {
- $namespaceChecker = $this->getMockBuilder(
'Wikibase\NamespaceChecker' )
- ->disableOriginalConstructor()
- ->getMock();
-
- $namespaceChecker->expects( $this->any() )
- ->method( 'isWikibaseEnabled' )
- ->will( $this->returnValue(
$wikibaseEnabledForNamespace ) );
-
- return $namespaceChecker;
- }
-
-}
diff --git a/client/tests/phpunit/includes/Hooks/SidebarHookHandlersTest.php
b/client/tests/phpunit/includes/Hooks/SidebarHookHandlersTest.php
index ec4482a..b2ca548 100644
--- a/client/tests/phpunit/includes/Hooks/SidebarHookHandlersTest.php
+++ b/client/tests/phpunit/includes/Hooks/SidebarHookHandlersTest.php
@@ -65,11 +65,6 @@
*/
private function newSettings( array $settings ) {
$defaults = array(
- 'sort' => 'code',
- 'sortPrepend' => array(),
- 'interwikiSortOrders' => array( 'alphabetic' => array(
- 'ar', 'de', 'en', 'sv', 'zh'
- ) ),
'siteGlobalID' => 'enwiki',
'languageLinkSiteGroup' => 'wikipedia',
'namespaces' => array( NS_MAIN, NS_CATEGORY ),
diff --git a/client/tests/phpunit/includes/InterwikiSorterTest.php
b/client/tests/phpunit/includes/InterwikiSorterTest.php
deleted file mode 100644
index 795731f..0000000
--- a/client/tests/phpunit/includes/InterwikiSorterTest.php
+++ /dev/null
@@ -1,137 +0,0 @@
-<?php
-
-namespace Wikibase\Client\Tests;
-
-use Wikibase\InterwikiSorter;
-
-/**
- * @covers Wikibase\InterwikiSorter
- *
- * @group WikibaseClient
- * @group Wikibase
- *
- * @license GPL-2.0+
- * @author Katie Filbert < [email protected] >
- */
-class InterwikiSorterTest extends \PHPUnit_Framework_TestCase {
-
- public function sortOrdersProvider() {
- return array(
- 'alphabetic' => array( 'ar', 'de', 'en', 'fr', 'ks',
'rn', 'ky', 'hu', 'ja', 'pt' ),
- 'alphabetic_revised' => array( 'ar', 'de', 'en', 'fr',
'ks', 'ky', 'rn', 'hu', 'ja', 'pt' ),
- 'alphabetic_sr' => array( 'ar', 'de', 'en', 'fr', 'ky',
'rn', 'ks', 'ja', 'hu', 'pt' ),
- 'mycustomorder' => array( 'de', 'ja', 'pt', 'hu', 'en'
),
- );
- }
-
- public function constructorProvider() {
- $sortOrders = $this->sortOrdersProvider();
- return array(
- array( 'code', $sortOrders, array() ),
- array( 'code', $sortOrders, array( 'en' ) )
- );
- }
-
- /**
- * @dataProvider constructorProvider
- */
- public function testConstructor( $sort, $sortOrders, $sortPrepend ) {
- $interwikiSorter = new InterwikiSorter( $sort, $sortOrders,
$sortPrepend );
- $this->assertInstanceOf( InterwikiSorter::class,
$interwikiSorter );
- }
-
- public function sortLinksProvider() {
- $sortOrders = $this->sortOrdersProvider();
- $links = array( 'fr', 'ky', 'hu', 'ar', 'ks', 'ja', 'de', 'en',
'pt', 'rn' );
-
- return array(
- array(
- $links, 'code', $sortOrders, array(),
- array( 'ar', 'de', 'en', 'fr', 'hu', 'ja',
'ks', 'ky', 'pt', 'rn' )
- ),
- array(
- $links, 'code', $sortOrders, array( 'en' ),
- array( 'en', 'ar', 'de', 'fr', 'hu', 'ja',
'ks', 'ky', 'pt', 'rn' )
- ),
- array(
- $links, 'alphabetic', $sortOrders, array(),
- $sortOrders['alphabetic']
- ),
- array(
- $links, 'alphabetic', $sortOrders, array( 'en',
'ja' ),
- array( 'en', 'ja', 'ar', 'de','fr', 'ks', 'rn',
'ky', 'hu', 'pt' )
- ),
- array(
- $links, 'alphabetic_revised', $sortOrders,
array(),
- $sortOrders['alphabetic_revised']
- ),
- array(
- $links, 'alphabetic_revised', $sortOrders,
array( 'hu' ),
- array( 'hu', 'ar', 'de', 'en', 'fr', 'ks',
'ky', 'rn', 'ja', 'pt' )
- ),
- array(
- array( 'ja', 'de', 'pt', 'en', 'hu' ),
'mycustomorder', $sortOrders, array(),
- $sortOrders['mycustomorder']
- ),
- array(
- array( 'x2', 'x1', 'x3' ),
- 'alphabetic',
- array( 'alphabetic' => array() ),
- array(),
- array( 'x1', 'x2', 'x3' )
- ),
- array(
- array( 'x2', 'x1', 'en', 'de', 'a2', 'a1' ),
- 'alphabetic',
- $sortOrders,
- array(),
- array( 'de', 'en', 'a1', 'a2', 'x1', 'x2' )
- ),
- array(
- array( 'f', 'd', 'b', 'a', 'c', 'e' ),
- 'alphabetic',
- array( 'alphabetic' => array( 'c', 'a' ) ),
- array( 'e' ),
- array( 'e', 'c', 'a', 'b', 'd', 'f' )
- ),
- 'Strict code order' => array(
- array( 'f', 'd', 'b', 'a', 'c', 'e' ),
- 'code',
- array( 'alphabetic' => array( 'c', 'a' ) ), //
this should be ignored
- array( 'e' ), // prepend
- array( 'e', 'a', 'b', 'c', 'd', 'f' )
- ),
- 'Code w/o alphabetic' => array(
- array( 'c', 'b', 'a' ),
- 'code',
- array(),
- array(),
- array( 'a', 'b', 'c' )
- ),
- array(
- array( 'a', 'b', 'k', 'x' ),
- 'alphabetic',
- array( 'alphabetic' => array( 'x', 'k', 'a' ) ),
- array(),
- array( 'x', 'k', 'a', 'b' )
- ),
- 'Fall back to code order' => array(
- array( 'b', 'a' ),
- 'invalid',
- array(),
- array(),
- array( 'a', 'b' )
- )
- );
- }
-
- /**
- * @dataProvider sortLinksProvider
- */
- public function testSortLinks( array $links, $sort, array $sortOrders,
$sortPrepend, $expected ) {
- $interwikiSorter = new InterwikiSorter( $sort, $sortOrders,
$sortPrepend );
- $sortedLinks = $interwikiSorter->sortLinks( $links );
- $this->assertEquals( $expected, $sortedLinks );
- }
-
-}
diff --git a/docs/options.wiki b/docs/options.wiki
index cd5e5be..5aa29a4 100644
--- a/docs/options.wiki
+++ b/docs/options.wiki
@@ -67,15 +67,6 @@
:'''Note:''' This may be removed once we can get this information from the
sites table.
;repoArticlePath: The repository's article path. Default is $wgArticlePath,
assuming that the repo's article path is the same as this wiki's script path.
:'''Note:''' This may be removed once we can get this information from the
sites table.
-;sort: How to sort language links in the side bar. Possible values:
-:;<code>'code'</code>: By language code
-:;<code>'alphabetic'</code>: [[meta:Interwiki_sorting_order|By language name]]
(<code>meta-native-languagename</code>)
-:;<code>'alphabetic_revised'</code>: [[meta:Interwiki_sorting_order|By
language name (alternative)]] (<code>meta-native-languagename-firstword</code>)
-:;<code>'none'</code>: Don't sort. Basically, the order of the links is not
guaranteed. '''Deprecated''' and dysfunctional.
-: Default is <code>'code'</code>.
-;sortPrepend: List of language codes to put on top of the language links in
the side bar. Default: <code>array()</code>.
-:'''Note''': this may change to use global wiki IDs instead of language codes
in the future.
-;interwikiSortOrders: Array of arrays of language codes, specifying custom
sort orders for interwiki links; default options provided include
<code>'code'</code>, <code>'alphabetic'</code>,
<code>'alphabetic_revised'</code>, <code>'alphabetic_sr'</code>, and
<code>'alphabetic_fy'</code>.
;siteGlobalID: This site's global ID (e.g. <code>'itwiki'</code>), as used in
the sites table. Default: <code>$wgDBname</code>.
;siteLocalID: This site's local ID resp. language code (e.g.
<code>'it'</code>). Default: <code>$wgLanguageCode</code>.
:'''Note:''' This setting will be removed once we can take this information
from the sites table.
--
To view, visit https://gerrit.wikimedia.org/r/314283
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I221802a136de5e5bb576d9ab00fb1b64eda53965
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits