Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
LanguageLinksHandler | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
onLanguageLinks | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace InterwikiSorting; |
4 | |
5 | use MediaWiki\Config\Config; |
6 | use MediaWiki\Output\Hook\LanguageLinksHook; |
7 | use MediaWiki\Title\Title; |
8 | |
9 | /** |
10 | * @license GPL-2.0-or-later |
11 | */ |
12 | class LanguageLinksHandler implements LanguageLinksHook { |
13 | |
14 | /** |
15 | * @var InterwikiSorter |
16 | */ |
17 | private $interwikiSorter; |
18 | |
19 | /** |
20 | * @param Config $config |
21 | */ |
22 | public function __construct( |
23 | Config $config |
24 | ) { |
25 | $this->interwikiSorter = new InterwikiSorter( |
26 | $config->get( 'InterwikiSortingSort' ), |
27 | $config->get( 'InterwikiSortingInterwikiSortOrders' ), |
28 | $config->get( 'InterwikiSortingSortPrepend' ) |
29 | ); |
30 | } |
31 | |
32 | /** |
33 | * Sort Interwiki links according to predefined config settings |
34 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/LanguageLinks |
35 | * |
36 | * @param Title $title |
37 | * @param string[] &$languageLinks |
38 | * @param array &$linkFlags |
39 | * @return void |
40 | */ |
41 | public function onLanguageLinks( $title, &$languageLinks, &$linkFlags ): void { |
42 | // this hook tries to access repo SiteLinkTable |
43 | // it interferes with any test that parses something, like a page or a message |
44 | if ( defined( 'MW_PHPUNIT_TEST' ) ) { |
45 | return; |
46 | } |
47 | |
48 | $languageLinks = $this->interwikiSorter->sortLinks( $languageLinks ); |
49 | } |
50 | |
51 | } |