Page MenuHomePhabricator

$wgMathValidModes has no effect in MediaWiki 1.43
Open, Needs TriagePublicBUG REPORT

Description

$wgMathValidModes appears in the documentation for Extension:Math and is shown as still being active as of version 1.43.1. But when I modify $wgMathValidModes in LocalSettings.php (for example $wgMathValidModes = ['native']), there is no effect. Special:MathStatus shows three options: LaTeX source, MathML, Client side MathJax rendering. Special:Preferences Appearance→Math shows the same three options (with MathML being selected by default).

The three options correspond to the setting of "MathValidModes" in extension.json. If I edit extension.json directly, then the change takes effect: removing an element removes the corresponding element from Special:MathStatus and Special:Preferences. (Except for "source", which may be special-cased.)

The Extension:Math source code currently in the REL1_43 branch does not reference $wgMathValidModes in code, only in text files or comments:

mediawiki/extensions/Math$ git log -1 --format=oneline
fdb260a97c06954f065e0ed422f095509eafabb3 (HEAD, origin/REL1_43) Localisation updates from https://translatewiki.net.
mediawiki/extensions/Math$ git grep wgMathValidModes
HISTORY:* $wgMathValidModes is introduced:
HISTORY:* $wgUseLaTeXML becomes unnecessary use $wgMathValidModes[] = 'latexml';
src/MathRenderer.php:    * @param string $newMode element of the array $wgMathValidModes

A relevant recent change seems to be rEMAT363abd4afbe93aa4e85105c4b254063afede36ec, which changed all setMwGlobals( 'wgMathValidModes', ... ) to overrideConfigValue( 'MathValidModes', ... ).

I found T242919 from 2020 which seems to be the same problem, but it was closed on 2024-11-04 without references to any changes.

https://www.mediawiki.org/wiki/Topic:W6b1ivdmdl0mb7ov from 2021 seems to be about something similar in 1.35.1:

$wgMathValidModes does not forbid user or server to use the excluded options. I tested only on Mediawiki 1.35.1. For example, the below LocalSettings.php allows user to use 'source' or 'png':

wfLoadExtension( 'Math' );
$wgMathValidModes[] = 'mathml';
$wgDefaultUserOptions['math'] = 'mathml';

Same here. 1.35.x appears to ignore the settings to the configuration parameter.

I suspect this is generally related to T271001.

I didn't check thoroughly, but the same thing may affect $wgMathUseInternalRestbasePath and other settings.

Steps to replicate the issue:

  • In LocalSettings.php, add:
wfLoadExtension("Math");
$wgMathValidModes = ['source'];
  • Go to Special:MathStatus and Special:Preferences (Appearance tab).

What happens?:

See three options:

  • LaTeX source
  • MathML
  • Client side MathJax rendering

What should have happened instead?:

See one option:

  • LaTeX source

Software version:

ProductVersion
MediaWiki1.43.1
PHP8.2.28 (fpm-fcgi)
ICU72.1
SQLite3.40.1

Event Timeline

I tried to fix that in 2017 https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/334646 . Later, it was suggested to remove that configuration and add a new one instead

https://phabricator.wikimedia.org/T150011#3994023

Today, there is a configuration setting, merge_strategy, that could be used to change the behavior, how settings can be overwritten. For the global variable $wgUserMergeProtectedGroups this was changed, see for example,

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/UserMerge/+/684669/5/extension.json

While this could be changed in a few minutes, the problem is that people who rely on the default merge strategy would see missing rendering modes. So this would be a breaking change, and thus it would need some planning and communication. I don't have the time to care about this communication overhead.

Thus, if you need to change that, your best chance is to do this https://phabricator.wikimedia.org/T142663#7055739

Thanks for the great information! I see now that it is more general than just $wgMathValidModes.

Following your recommendation, I tried this in LocalSettings.php, which worked:

wfLoadExtension("Math");
$wgExtensionFunctions[] = function() {
	global $wgMathValidModes;
	$wgMathValidModes = ['native'];
};

What I said in the description about "source" possibly being special-cased did not apply using this method. With a setting of ["native"], only the native option shows up in Special:MathStatus and Special:Preferences, which is what I expect.