Skip to content

Commit

Permalink
Merge branch 'MDL-60209-master-mathjaxlib' of git://github.com/mudrd8…
Browse files Browse the repository at this point in the history
…mz/moodle
  • Loading branch information
stronk7 committed Oct 12, 2017
2 parents dab702d + 9e6df84 commit f088e26
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 3 deletions.
29 changes: 29 additions & 0 deletions filter/mathjaxloader/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,34 @@ function xmldb_filter_mathjaxloader_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2017100900, 'filter', 'mathjaxloader');
}

if ($oldversion < 2017101200) {
// Update default MathJax configuration so that it does not use the Accessible.js config (causes JS errors due to upstream bug).
$previousdefault = '
MathJax.Hub.Config({
config: ["Accessible.js", "Safe.js"],
errorSettings: { message: ["!"] },
skipStartupTypeset: true,
messageStyle: "none"
});
';

$newdefault = '
MathJax.Hub.Config({
config: ["default.js", "MMLorHTML.js", "Safe.js"],
errorSettings: { message: ["!"] },
skipStartupTypeset: true,
messageStyle: "none"
});
';

$mathjaxconfig = get_config('filter_mathjaxloader', 'mathjaxconfig');

if (empty($mathjaxconfig) || filter_mathjaxloader_upgrade_mathjaxconfig_equal($mathjaxconfig, $previousdefault)) {
set_config('mathjaxconfig', $newdefault, 'filter_mathjaxloader');
}

upgrade_plugin_savepoint(true, 2017101200, 'filter', 'mathjaxloader');
}

return true;
}
29 changes: 29 additions & 0 deletions filter/mathjaxloader/db/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,32 @@ function filter_mathjaxloader_upgrade_cdn_cloudflare($mathjaxurl, $httponly = fa

return $newcdnurl;
}

/**
* Compares two values of the 'mathjaxconfig' config option.
*
* This is used during the upgrade to see if the two text values of the 'mathjaxconfig' config option should be
* considered equal of different. The strings are normalized so that EOL characters and whitespace is not significant.
*
* @param string $val1 value
* @param string $val2 value
* @return bool true if the texts should be considered equals, false otherwise
*/
function filter_mathjaxloader_upgrade_mathjaxconfig_equal($val1, $val2) {

$val1lines = preg_split("/[\r\n]/", $val1);
$val2lines = preg_split("/[\r\n]/", $val2);

$val1lines = array_map('trim', $val1lines);
$val2lines = array_map('trim', $val2lines);

$val1lines = array_filter($val1lines, function($value) {
return $value !== '';
});

$val2lines = array_filter($val2lines, function($value) {
return $value !== '';
});

return (implode(' ', $val1lines) === implode(' ', $val2lines));
}
7 changes: 7 additions & 0 deletions filter/mathjaxloader/readme_moodle.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ Upgrading the default MathJax version
previous default.
3. Check and eventually update the list of language mappings in filter.php.
Also see the unit test for the language mappings.

Changes
-------

* The MathJax 2.7.2 seems to have a bug causing the accessibility extensions
fail in web apps using RequireJS (such as Moodle). We had to stop using the
Accessible.js config for that reason. See MDL-60209 for details.
2 changes: 1 addition & 1 deletion filter/mathjaxloader/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

$default = '
MathJax.Hub.Config({
config: ["Accessible.js", "Safe.js"],
config: ["default.js", "MMLorHTML.js", "Safe.js"],
errorSettings: { message: ["!"] },
skipStartupTypeset: true,
messageStyle: "none"
Expand Down
35 changes: 34 additions & 1 deletion filter/mathjaxloader/tests/upgradelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
*/
class filter_mathjax_upgradelib_testcase extends advanced_testcase {

public function test_upgradelib() {
/**
* Tests for {@link filter_mathjaxloader_upgrade_cdn_cloudflare()} function.
*/
public function test_filter_mathjaxloader_upgrade_cdn_cloudflare() {
$current = 'https://cdn.mathjax.org/mathjax/2.7-latest/MathJax.js?...';
$expected = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?...';
$this->assertEquals($expected, filter_mathjaxloader_upgrade_cdn_cloudflare($current));
Expand Down Expand Up @@ -87,5 +90,35 @@ public function test_upgradelib() {
$expected = 'https://cdn.mathjax.org/mathjax/2.7-latest';
$this->assertEquals($expected, filter_mathjaxloader_upgrade_cdn_cloudflare($current));
}

/**
* Tests for {@link filter_mathjaxloader_upgrade_mathjaxconfig_equal()} function.
*/
public function test_filter_mathjaxloader_upgrade_mathjaxconfig_equal() {

$val1 = '';
$val2 = "\n \r \r\n \t ";
$this->assertTrue(filter_mathjaxloader_upgrade_mathjaxconfig_equal($val1, $val2));

$val1 = '0';
$val2 = '';
$this->assertFalse(filter_mathjaxloader_upgrade_mathjaxconfig_equal($val1, $val2));

$val1 = 'Hello Unittest, my old friend '.PHP_EOL."I've come to play with you again \r\n\r\n \t ";
$val2 = ' Hello Unittest, my old friend '."\r\n\r\n"." I've come to play with you again \n\n\n ";
$this->assertTrue(filter_mathjaxloader_upgrade_mathjaxconfig_equal($val1, $val2));

$val1 = "\n".'MathJax.Hub.Config({'."\n".' config: ["Accessible.js", "Safe.js"]'."\n".'});'."\n";
$val2 = 'MathJax.Hub.Config({'."\r".'config: ["Accessible.js", "Safe.js"]'."\r".'});';
$this->assertTrue(filter_mathjaxloader_upgrade_mathjaxconfig_equal($val1, $val2));

$val1 = "\r\n\t".'MathJax.Hub.Config({'."\r\n\t".' config: ["Accessible.js", "Safe.js"]'."\r\n".'}); '."\r\n\r\n";
$val2 = 'MathJax.Hub.Config({'."\n".'config: ["Accessible.js", "Safe.js"]'."\r".'});';
$this->assertTrue(filter_mathjaxloader_upgrade_mathjaxconfig_equal($val1, $val2));

$val2 = 'MathJax.Hub.Config({'."\n".'config: ["Significant.js"]'."\n".'});';
$val2 = 'MathJax.Hub.Config({'."\n".'config: ["Signi ficant.js", "Safe.js"]'."\n".'});';
$this->assertFalse(filter_mathjaxloader_upgrade_mathjaxconfig_equal($val1, $val2));
}
}

2 changes: 1 addition & 1 deletion filter/mathjaxloader/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2017100900;
$plugin->version = 2017101200;
$plugin->requires = 2017050500; // Requires this Moodle version.
$plugin->component= 'filter_mathjaxloader';

0 comments on commit f088e26

Please sign in to comment.