Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/235211
Change subject: Remove requirement that an "alphabetic" sort order must be defined ...................................................................... Remove requirement that an "alphabetic" sort order must be defined This came up while working on T103044. Bug: T111023 Change-Id: I827e8e0d0291354902e4c3cf694a9dab3db80c89 --- M client/includes/InterwikiSorter.php M client/tests/phpunit/includes/InterwikiSorterTest.php 2 files changed, 21 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/11/235211/1 diff --git a/client/includes/InterwikiSorter.php b/client/includes/InterwikiSorter.php index b70c9b7..c49badb 100644 --- a/client/includes/InterwikiSorter.php +++ b/client/includes/InterwikiSorter.php @@ -2,8 +2,6 @@ namespace Wikibase; -use InvalidArgumentException; - /** * Language sorting utility functions. * @@ -42,16 +40,8 @@ * @param string $sort * @param array[] $sortOrders * @param string[] $sortPrepend - * - * @throws InvalidArgumentException */ - public function __construct( $sort, array $sortOrders, array $sortPrepend ) { - if ( !array_key_exists( 'alphabetic', $sortOrders ) ) { - throw new InvalidArgumentException( - 'alphabetic interwiki sorting order is missing from Wikibase Client settings.' - ); - } - + public function __construct( $sort, array $sortOrders = array(), array $sortPrepend = array() ) { $this->sort = $sort; $this->sortOrders = $sortOrders; $this->sortPrepend = $sortPrepend; @@ -129,22 +119,16 @@ * @return int[] */ private function buildSortOrder( $sort, array $sortOrders ) { - $sortOrder = $sortOrders['alphabetic']; - - if ( $sort === 'alphabetic' ) { - // do nothing - } elseif ( $sort === 'code' ) { + if ( $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 order + trigger_error( __CLASS__ + . ' : invalid or unknown sort order specified for interwiki links.', E_USER_WARNING ); + $sortOrder = array(); } else { - if ( array_key_exists( $sort, $sortOrders ) ) { - $sortOrder = $sortOrders[$sort]; - } else { - // something went wrong but we can use default order - trigger_error( __CLASS__ - . ' : invalid or unknown sort order specified for interwiki links.', E_USER_WARNING ); - sort( $sortOrder ); - } + $sortOrder = $sortOrders[$sort]; } if ( $this->sortPrepend !== array() ) { diff --git a/client/tests/phpunit/includes/InterwikiSorterTest.php b/client/tests/phpunit/includes/InterwikiSorterTest.php index e0d8243..9eeaccf 100644 --- a/client/tests/phpunit/includes/InterwikiSorterTest.php +++ b/client/tests/phpunit/includes/InterwikiSorterTest.php @@ -101,6 +101,13 @@ 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', @@ -120,4 +127,10 @@ $this->assertEquals( $expected, $sortedLinks ); } + public function testGivenInvalidSort_sortLinksTriggersError() { + $interwikiSorter = new InterwikiSorter( 'invalid' ); + $this->setExpectedException( 'PHPUnit_Framework_Error_Warning' ); + $interwikiSorter->sortLinks( array() ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/235211 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I827e8e0d0291354902e4c3cf694a9dab3db80c89 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits