MDL-65809 upgrade: remove filter_mathjaxloader_upgrade_xxx
These functions were used only by deleted upgrade steps
so it's safe to proceed with straight deletion, considering
them internal. Deletion has been documented in corresponding
upgrade.txt files:
- filter_mathjaxloader_upgrade_cdn_cloudflare()
- filter_mathjaxloader_upgrade_mathjaxconfig_equal()
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Random functions for mathjax upgrades.
|
||||
*
|
||||
* @package filter_mathjaxloader
|
||||
* @copyright 2017 Damyon Wiese ([email protected])
|
||||
* @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));
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user