Debian Codegraph @

extensions/Math/src/HookHandlers/PreferencesHooksHandler.php

raw symbols SCIP
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 /** @inheritDoc */
28 public function onUserGetDefaultOptions( &$defaultOptions ) {
29 // Normalize the default use option in case it's not a valid rendering mode. BUG 64844
30 $mode = $defaultOptions['math'] = MathConfig::normalizeRenderingMode( $defaultOptions['math'] );
31 if ( !$this->mathConfig->isValidRenderingMode( $mode ) ) {
32 $validModes = $this->mathConfig->getValidRenderingModes();
33 LoggerFactory::getInstance( 'Math' )
34 ->error( "Misconfiguration: wgDefaultUserOptions['math'] is not an enabled mode", [
35 'valid_modes' => $validModes,
36 'configured_default' => $mode,
37 ] );
38 $defaultOptions['math'] = $validModes[0];
39 }
40 }
41
42 /** @inheritDoc */
43 public function onGetPreferences( $user, &$preferences ) {
44 $preferences['math'] = [
45 'type' => 'radio',
46 'options-messages' => array_flip( $this->mathConfig->getValidRenderingModeKeys() ),
47 'label' => '&#160;',
48 'section' => 'rendering/math',
49 ];
50
51 $preferences['math-popups'] = [
52 'type' => 'toggle',
53 'label-message' => 'popups-settings-option-math-tooltip',
54 'section' => 'rendering/math',
55 'help-message' => 'popups-settings-option-math-tooltip-description'
56 ];
57 }
58 }