| 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 |
|
| 16 |
private $mathConfig; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function __construct( |
| 22 |
MathConfig $mathConfig |
| 23 |
) { |
| 24 |
$this->mathConfig = $mathConfig; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
public function onUserGetDefaultOptions( &$defaultOptions ) { |
| 29 |
|
| 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 |
|
| 43 |
public function onGetPreferences( $user, &$preferences ) { |
| 44 |
$preferences['math'] = [ |
| 45 |
'type' => 'radio', |
| 46 |
'options-messages' => array_flip( $this->mathConfig->getValidRenderingModeKeys() ), |
| 47 |
'label' => ' ', |
| 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 |
} |