Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
68.18% |
15 / 22 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
PreferencesHooksHandler | |
68.18% |
15 / 22 |
|
66.67% |
2 / 3 |
4.52 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
onUserGetDefaultOptions | |
22.22% |
2 / 9 |
|
0.00% |
0 / 1 |
3.88 | |||
onGetPreferences | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Math\HookHandlers; |
4 | |
5 | use MediaWiki\Extension\Math\MathConfig; |
6 | use MediaWiki\Logger\LoggerFactory; |
7 | use MediaWiki\Preferences\Hook\GetPreferencesHook; |
8 | use MediaWiki\User\Hook\UserGetDefaultOptionsHook; |
9 | |
10 | class PreferencesHooksHandler implements |
11 | UserGetDefaultOptionsHook, |
12 | GetPreferencesHook |
13 | { |
14 | |
15 | /** @var MathConfig */ |
16 | private $mathConfig; |
17 | |
18 | /** |
19 | * @param MathConfig $mathConfig |
20 | */ |
21 | public function __construct( |
22 | MathConfig $mathConfig |
23 | ) { |
24 | $this->mathConfig = $mathConfig; |
25 | } |
26 | |
27 | public function onUserGetDefaultOptions( &$defaultOptions ) { |
28 | // Normalize the default use option in case it's not a valid rendering mode. BUG 64844 |
29 | $mode = $defaultOptions['math'] = MathConfig::normalizeRenderingMode( $defaultOptions['math'] ); |
30 | if ( !$this->mathConfig->isValidRenderingMode( $mode ) ) { |
31 | $validModes = $this->mathConfig->getValidRenderingModes(); |
32 | LoggerFactory::getInstance( 'Math' ) |
33 | ->error( "Misconfiguration: wgDefaultUserOptions['math'] is not an enabled mode", [ |
34 | 'valid_modes' => $validModes, |
35 | 'configured_default' => $mode, |
36 | ] ); |
37 | $defaultOptions['math'] = $validModes[0]; |
38 | } |
39 | } |
40 | |
41 | public function onGetPreferences( $user, &$preferences ) { |
42 | $preferences['math'] = [ |
43 | 'type' => 'radio', |
44 | 'options-messages' => array_flip( $this->mathConfig->getValidRenderingModeKeys() ), |
45 | 'label' => ' ', |
46 | 'section' => 'rendering/math', |
47 | ]; |
48 | |
49 | $preferences['math-popups'] = [ |
50 | 'type' => 'toggle', |
51 | 'label-message' => 'popups-settings-option-math-tooltip', |
52 | 'section' => 'rendering/math', |
53 | 'help-message' => 'popups-settings-option-math-tooltip-description' |
54 | ]; |
55 | } |
56 | } |