Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TooltipGenerator
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 generateTooltips
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace AdvancedSearch;
4
5use 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 */
17class 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-incategory',
25        'advancedsearch-help-deepcategory',
26        'advancedsearch-help-hastemplate',
27        'advancedsearch-help-inlanguage',
28        'advancedsearch-help-intitle',
29        'advancedsearch-help-subpageof',
30        'advancedsearch-help-filetype',
31        'advancedsearch-help-filew',
32        'advancedsearch-help-fileh',
33        'advancedsearch-help-sort'
34    ];
35
36    public function __construct( private readonly MessageLocalizer $messageLocalizer ) {
37    }
38
39    /**
40     * @return string[]
41     */
42    public function generateTooltips(): array {
43        $tooltips = [];
44
45        foreach ( self::MESSAGE_KEYS as $key ) {
46            $msg = $this->messageLocalizer->msg( $key );
47            if ( !$msg->isDisabled() ) {
48                $tooltips[$key] = $msg->parse();
49            }
50        }
51
52        return $tooltips;
53    }
54
55}