Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
TooltipGenerator | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
generateTooltips | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace AdvancedSearch; |
4 | |
5 | use MessageLocalizer; |
6 | |
7 | /** |
8 | * Generate HTML tooltips from messages |
9 | * |
10 | * This is a workaround for the deficiencies of mw.message( 'keyname' ).parse() which does not |
11 | * support HTML except italic and bold and does not convert wiki text. |
12 | * |
13 | * See https://phabricator.wikimedia.org/T27349 |
14 | * |
15 | * @license GPL-2.0-or-later |
16 | */ |
17 | class TooltipGenerator { |
18 | |
19 | private const MESSAGE_KEYS = [ |
20 | 'advancedsearch-help-plain', |
21 | 'advancedsearch-help-phrase', |
22 | 'advancedsearch-help-or', |
23 | 'advancedsearch-help-not', |
24 | 'advancedsearch-help-deepcategory', |
25 | 'advancedsearch-help-hastemplate', |
26 | 'advancedsearch-help-inlanguage', |
27 | 'advancedsearch-help-intitle', |
28 | 'advancedsearch-help-subpageof', |
29 | 'advancedsearch-help-filetype', |
30 | 'advancedsearch-help-filew', |
31 | 'advancedsearch-help-fileh', |
32 | 'advancedsearch-help-sort' |
33 | ]; |
34 | |
35 | private MessageLocalizer $messageLocalizer; |
36 | |
37 | public function __construct( MessageLocalizer $messageLocalizer ) { |
38 | $this->messageLocalizer = $messageLocalizer; |
39 | } |
40 | |
41 | /** |
42 | * @return string[] |
43 | */ |
44 | public function generateTooltips(): array { |
45 | $tooltips = []; |
46 | |
47 | foreach ( self::MESSAGE_KEYS as $key ) { |
48 | $msg = $this->messageLocalizer->msg( $key ); |
49 | if ( !$msg->isDisabled() ) { |
50 | $tooltips[$key] = $msg->parse(); |
51 | } |
52 | } |
53 | |
54 | return $tooltips; |
55 | } |
56 | |
57 | } |