diff --git a/filter/mathjaxloader/db/upgrade.php b/filter/mathjaxloader/db/upgrade.php index c01643f2a54..9b64471bc64 100644 --- a/filter/mathjaxloader/db/upgrade.php +++ b/filter/mathjaxloader/db/upgrade.php @@ -31,129 +31,6 @@ defined('MOODLE_INTERNAL') || die(); function xmldb_filter_mathjaxloader_upgrade($oldversion) { global $CFG; - require_once($CFG->dirroot . '/filter/mathjaxloader/db/upgradelib.php'); - - if ($oldversion < 2017040300) { - - $httpsurl = get_config('filter_mathjaxloader', 'httpsurl'); - $newcdnurl = filter_mathjaxloader_upgrade_cdn_cloudflare($httpsurl, false); - - set_config('httpsurl', $newcdnurl, 'filter_mathjaxloader'); - - $mathjaxconfig = get_config('filter_mathjaxloader', 'mathjaxconfig'); - if (strpos($mathjaxconfig, 'MathJax.Ajax.config.path') === false) { - $newconfig = 'MathJax.Ajax.config.path["Contrib"] = "{wwwroot}/filter/mathjaxloader/contrib";' . "\n"; - $newconfig .= $mathjaxconfig; - - set_config('mathjaxconfig', $newconfig, 'filter_mathjaxloader'); - } - - upgrade_plugin_savepoint(true, 2017040300, 'filter', 'mathjaxloader'); - } - - if ($oldversion < 2017042602) { - - $httpsurl = get_config('filter_mathjaxloader', 'httpsurl'); - if ($httpsurl === "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js") { - set_config('httpsurl', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js', 'filter_mathjaxloader'); - } - - $mathjaxconfig = get_config('filter_mathjaxloader', 'mathjaxconfig'); - - if (strpos($mathjaxconfig, 'MathJax.Ajax.config.path') !== false) { - // Now we need to remove this config again because mathjax 2.7.1 supports the extensions on the CDN. - $configtoremove = 'MathJax.Ajax.config.path["Contrib"] = "{wwwroot}/filter/mathjaxloader/contrib";'; - - $mathjaxconfig = str_replace($configtoremove, '', $mathjaxconfig); - - set_config('mathjaxconfig', $mathjaxconfig, 'filter_mathjaxloader'); - } - - upgrade_plugin_savepoint(true, 2017042602, 'filter', 'mathjaxloader'); - } - - // Automatically generated Moodle v3.3.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2017091900) { - - $httpsurl = get_config('filter_mathjaxloader', 'httpsurl'); - if (empty($httpsurl)) { - // URL is empty, most likely because of bad upgrade path. See MDL-59780. - set_config('httpsurl', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js', 'filter_mathjaxloader'); - } - upgrade_plugin_savepoint(true, 2017091900, 'filter', 'mathjaxloader'); - } - - if ($oldversion < 2017100900) { - // Update the MathJax CDN URL to the new default if the site has been using default value. - $httpsurl = get_config('filter_mathjaxloader', 'httpsurl'); - if ($httpsurl === 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js') { - set_config('httpsurl', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js', 'filter_mathjaxloader'); - } - 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'); - } - - if ($oldversion < 2017102000) { - // Re-add Accessible.js (we should not have removed it). - $previousdefault = ' -MathJax.Hub.Config({ - config: ["default.js", "MMLorHTML.js", "Safe.js"], - errorSettings: { message: ["!"] }, - skipStartupTypeset: true, - messageStyle: "none" -}); -'; - $newdefault = ' -MathJax.Hub.Config({ - config: ["Accessible.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, 2017102000, 'filter', 'mathjaxloader'); - } - - // Automatically generated Moodle v3.4.0 release upgrade line. - // Put any upgrade step following this. - // Automatically generated Moodle v3.5.0 release upgrade line. // Put any upgrade step following this. diff --git a/filter/mathjaxloader/db/upgradelib.php b/filter/mathjaxloader/db/upgradelib.php deleted file mode 100644 index 813075698a8..00000000000 --- a/filter/mathjaxloader/db/upgradelib.php +++ /dev/null @@ -1,95 +0,0 @@ -. - -/** - * Random functions for mathjax upgrades. - * - * @package filter_mathjaxloader - * @copyright 2017 Damyon Wiese (damyon@moodle.com) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * This function takes an existing mathjax url and, if it was using the standard mathjax cdn, - * upgrades it to use the cloudflare matchjax cdn (because the standard one is shutting down). - * @param string $mathjaxurl - The current url. - * @param boolean $httponly - Use http instead of https - really only for 3.1 upgrades. - * @return string The new url. - */ -function filter_mathjaxloader_upgrade_cdn_cloudflare($mathjaxurl, $httponly = false) { - $newcdnurl = $mathjaxurl; - $cdnroot = 'https://cdn.mathjax.org/mathjax/'; - if ($httponly) { - $cdnroot = 'http://cdn.mathjax.org/mathjax/'; - } - $usingcdn = strpos($mathjaxurl, $cdnroot) === 0; - if ($usingcdn) { - $majorversion = substr($mathjaxurl, strlen($cdnroot), 3); - $latestversion = '2.7.0'; - if ($majorversion == '2.6') { - $latestversion = '2.6.1'; - } else if ($majorversion == '2.5') { - $latestversion = '2.5.3'; - } - - $offset = strpos($mathjaxurl, '/', strlen($cdnroot)); - if ($offset === false) { - return $newcdnurl; - } - - $endofurl = substr($mathjaxurl, $offset + 1); - - $newcdnbase = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/'; - if ($httponly) { - $newcdnbase = 'http://cdnjs.cloudflare.com/ajax/libs/mathjax/'; - } - - $newcdnurl = $newcdnbase . $latestversion . '/' . $endofurl; - } - - 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)); -} diff --git a/filter/mathjaxloader/tests/upgradelib_test.php b/filter/mathjaxloader/tests/upgradelib_test.php deleted file mode 100644 index 092f293b858..00000000000 --- a/filter/mathjaxloader/tests/upgradelib_test.php +++ /dev/null @@ -1,124 +0,0 @@ -. - -/** - * Unit test for the upgrade MathJax code. - * - * @package filter_mathjaxloader - * @copyright 2017 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -global $CFG; -require_once($CFG->dirroot . '/filter/mathjaxloader/db/upgradelib.php'); - -/** - * Unit test for the upgrade MathJax code. - * - * Test the functions in upgradelib.php - * - * @copyright 2017 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class filter_mathjax_upgradelib_testcase extends advanced_testcase { - - /** - * 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)); - - $current = 'http://cdn.mathjax.org/mathjax/2.7-latest/MathJax.js?...'; - $expected = 'http://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?...'; - $this->assertEquals($expected, filter_mathjaxloader_upgrade_cdn_cloudflare($current, true)); - - $current = 'http://cdn.mathjax.org/mathjax/2.7-latest/MathJax.js?...'; - $expected = 'http://cdn.mathjax.org/mathjax/2.7-latest/MathJax.js?...'; - $this->assertEquals($expected, filter_mathjaxloader_upgrade_cdn_cloudflare($current, false)); - - $current = 'https://cdn.mathjax.org/mathjax/2.7-latest/MathJax.js?...'; - $expected = 'https://cdn.mathjax.org/mathjax/2.7-latest/MathJax.js?...'; - $this->assertEquals($expected, filter_mathjaxloader_upgrade_cdn_cloudflare($current, true)); - - $current = 'https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?...'; - $expected = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.6.1/MathJax.js?...'; - $this->assertEquals($expected, filter_mathjaxloader_upgrade_cdn_cloudflare($current)); - - $current = 'https://cdn.mathjax.org/mathjax/2.5-latest/MathJax.js?...'; - $expected = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.5.3/MathJax.js?...'; - $this->assertEquals($expected, filter_mathjaxloader_upgrade_cdn_cloudflare($current)); - - // Dont touch non https links. - $current = 'http://cdn.mathjax.org/mathjax/2.5-latest/MathJax.js?...'; - $expected = 'http://cdn.mathjax.org/mathjax/2.5-latest/MathJax.js?...'; - $this->assertEquals($expected, filter_mathjaxloader_upgrade_cdn_cloudflare($current)); - - // Dont touch non local links. - $current = 'https://mylocalmirror/mathjax/2.7-latest/MathJax.js?...'; - $expected = 'https://mylocalmirror/mathjax/2.7-latest/MathJax.js?...'; - $this->assertEquals($expected, filter_mathjaxloader_upgrade_cdn_cloudflare($current)); - - // Try some unexpected things. - $current = ''; - $expected = ''; - $this->assertEquals($expected, filter_mathjaxloader_upgrade_cdn_cloudflare($current)); - - // Try some unexpected things. - $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)); - - // Try some unexpected things. - $current = 'https://cdn.mathjax.org/mathjax/2.7-latest'; - $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)); - } -} - diff --git a/filter/upgrade.txt b/filter/upgrade.txt index 3ccfc6e333f..dfccf3f5f4e 100644 --- a/filter/upgrade.txt +++ b/filter/upgrade.txt @@ -1,6 +1,12 @@ This file describes API changes in core filter API and plugins, information provided here is intended especially for developers. +=== 3.9 === + +* The following functions, previously used (exclusively) by upgrade steps are not available anymore because of the upgrade cleanup performed for this version. See MDL-65809 for more info: + - filter_mathjaxloader_upgrade_cdn_cloudflare() + - filter_mathjaxloader_upgrade_mathjaxconfig_equal() + === 3.6 === * Although there is no API change that require you to update your filter,