MDL-82790 core: Remove filter_tidy

This commit is contained in:
Andrew Nicols 2024-08-20 16:06:30 +08:00
parent 6cd55074c7
commit 9fe7dedb9f
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
12 changed files with 24 additions and 362 deletions

View File

@ -1,46 +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/>.
/**
* Privacy Subsystem implementation for filter_tidy.
*
* @package filter_tidy
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace filter_tidy\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for filter_tidy implementing null_provider.
*
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}

View File

@ -1,70 +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/>.
namespace filter_tidy;
/**
* HTML tidy text filter.
*
* This class looks for text including markup and
* applies tidy's repair function to it.
* Tidy is a HTML clean and
* repair utility, which is currently available for PHP 4.3.x and PHP 5 as a
* PECL extension from http://pecl.php.net/package/tidy, in PHP 5 you need only
* to compile using the --with-tidy option.
* If you don't have the tidy extension installed or don't know, you can enable
* or disable this filter, it just won't have any effect.
* If you want to know what you can set in $tidyoptions and what their default
* values are, see http://php.net/manual/en/function.tidy-get-config.php.
*
* @package filter_tidy
* @subpackage tiny
* @copyright 2004 Hannes Gassert <hannes at mediagonal dot ch>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class text_filter extends \core_filters\text_filter {
#[\Override]
public function filter($text, array $options = []) {
// Configuration for tidy.
// See https://api.html-tidy.org/tidy/quickref_5.0.0.html for details.
$tidyoptions = [
'output-xhtml' => true,
'show-body-only' => true,
'tidy-mark' => false,
'drop-proprietary-attributes' => true,
'drop-empty-paras' => true,
'indent' => true,
'quiet' => true,
];
// Do a quick check using strpos to avoid unnecessary work.
if (strpos($text, '<') === false) {
return $text;
}
// If enabled: run tidy over the entire string.
if (extension_loaded('tidy')) {
$currentlocale = \core\locale::get_locale();
try {
$text = (new \tidy())->repairString($text, $tidyoptions, 'utf8');
} finally {
\core\locale::set_locale(LC_ALL, $currentlocale);
}
}
return $text;
}
}

View File

@ -1,29 +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/>.
/**
* Renamed classes for the filter_tidy plugin.
*
* @package filter_tidy
* @copyright Jun Pataleta <jun@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$renamedclasses = [
'filter_tidy' => \filter_tidy\text_filter::class,
];

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<COMPATIBILITY_MATRIX>
<PLUGIN name="filter_tidy">
<PHP_EXTENSIONS>
<PHP_EXTENSION name="tidy" level="optional">
<FEEDBACK>
<ON_CHECK message="tidyextensionrequired" plugin="filter_tidy" />
</FEEDBACK>
</PHP_EXTENSION>
</PHP_EXTENSIONS>
</PLUGIN>
</COMPATIBILITY_MATRIX>

View File

@ -1,28 +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/>.
/**
* File only retained to prevent fatal errors in code that tries to require/include this.
*
* @todo MDL-82708 delete this file as part of Moodle 6.0 development.
* @deprecated This file is no longer required in Moodle 4.5+.
* @package filter_tidy
* @copyright Hannes Gassert <hannes@mediagonal.ch>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
debugging('This file is no longer required in Moodle 4.5+. Please do not include/require it.', DEBUG_DEVELOPER);

View File

@ -1,28 +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/>.
/**
* Strings for component 'filter_tidy', language 'en', branch 'MOODLE_20_STABLE'
*
* @package filter_tidy
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['filtername'] = 'HTML tidy';
$string['privacy:metadata'] = 'The HTML tidy plugin does not store any personal data.';
$string['tidyextensionrequired'] = 'To use this filter, the \'tidy\' PHP extension must be installed.';

View File

@ -1,105 +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/>.
namespace filter_tidy;
/**
* Tests for HTML tidy.
*
* @package filter_tidy
* @category test
* @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \filter_tidy\text_filter
*/
final class text_filter_test extends \advanced_testcase {
/** @var string Locale */
protected string $locale;
#[\Override]
public function setUp(): void {
parent::setUp();
$this->locale = \core\locale::get_locale();
}
#[\Override]
public function tearDown(): void {
parent::tearDown();
\core\locale::set_locale(LC_ALL, $this->locale);
}
/**
* Test the filter method.
*
* @requires extension tidy
* @dataProvider filter_provider
* @param string $text The text to filter.
* @param string $expected The expected value
*/
public function test_filter(
string $text,
string $expected,
): void {
$filter = new text_filter(\core\context\system::instance(), []);
$this->assertEquals($expected, $filter->filter($text));
$this->assertEquals(
\core\locale::standardise_locale($this->locale),
\core\locale::standardise_locale(\core\locale::get_locale()),
);
}
/**
* Data provider for the filter test.
*
* @return array
*/
public static function filter_provider(): array {
return [
// No HTML tags.
[
'The cat is in the hat',
'The cat is in the hat',
],
// Partial HTML.
[
'<p>The cat is in the hat',
<<<EOF
<p>
The cat is in the hat
</p>
EOF,
],
// Return only the body, repairing the closing tag.
[
<<<EOF
<html>
<head>
<title>test</title>
</head>
<body>
<p>error</i>
</body>
</html>
EOF,
<<<EOF
<p>
error
</p>
EOF,
],
];
}
}

View File

@ -1,30 +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/>.
/**
* Version details
*
* @package filter
* @subpackage tidy
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'filter_tidy'; // Full name of the plugin (used for diagnostics)

View File

@ -1240,5 +1240,15 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2024080500.00);
}
if ($oldversion < 2024082000.00) {
// If filter_tidy is no longer present, remove it.
if (!file_exists($CFG->dirroot . '/filter/tidy/version.php')) {
// Clean config.
unset_all_config_for_plugin('filter_tidy');
}
upgrade_main_savepoint(true, 2024082000.00);
}
return true;
}

View File

@ -230,7 +230,6 @@
"mediaplugin",
"multilang",
"tex",
"tidy",
"urltolink"
],
"format": [
@ -593,7 +592,8 @@
"authorize"
],
"filter": [
"censor"
"censor",
"tidy"
],
"h5plib": [
"v124"

View File

@ -725,24 +725,24 @@ class filterlib_test extends \advanced_testcase {
$this->resetAfterTest();
$this->assertFileExists("$CFG->dirroot/filter/emailprotect"); // Any standard filter.
$this->assertFileExists("$CFG->dirroot/filter/tidy"); // Any standard filter.
$this->assertFileExists("$CFG->dirroot/filter/glossary"); // Any standard filter.
$this->assertFileDoesNotExist("$CFG->dirroot/filter/grgrggr"); // Any non-existent filter.
// Setup fixture.
set_config('filterall', 0);
set_config('stringfilters', '');
// Exercise SUT.
filter_set_applies_to_strings('tidy', true);
filter_set_applies_to_strings('glossary', true);
// Validate.
$this->assertEquals('tidy', $CFG->stringfilters);
$this->assertEquals('glossary', $CFG->stringfilters);
$this->assertEquals(1, $CFG->filterall);
filter_set_applies_to_strings('grgrggr', true);
$this->assertEquals('tidy', $CFG->stringfilters);
$this->assertEquals('glossary', $CFG->stringfilters);
$this->assertEquals(1, $CFG->filterall);
filter_set_applies_to_strings('emailprotect', true);
$this->assertEquals('tidy,emailprotect', $CFG->stringfilters);
$this->assertEquals('glossary,emailprotect', $CFG->stringfilters);
$this->assertEquals(1, $CFG->filterall);
}
@ -750,13 +750,13 @@ class filterlib_test extends \advanced_testcase {
global $CFG;
$this->resetAfterTest();
$this->assertFileExists("$CFG->dirroot/filter/tidy"); // Any standard filter.
$this->assertFileExists("$CFG->dirroot/filter/glossary"); // Any standard filter.
// Setup fixture.
set_config('filterall', 1);
set_config('stringfilters', 'tidy');
set_config('stringfilters', 'glossary');
// Exercise SUT.
filter_set_applies_to_strings('tidy', false);
filter_set_applies_to_strings('glossary', false);
// Validate.
$this->assertEquals('', $CFG->stringfilters);
$this->assertEquals('', $CFG->filterall);
@ -767,14 +767,14 @@ class filterlib_test extends \advanced_testcase {
$this->resetAfterTest();
$this->assertFileExists("$CFG->dirroot/filter/emailprotect"); // Any standard filter.
$this->assertFileExists("$CFG->dirroot/filter/tidy"); // Any standard filter.
$this->assertFileExists("$CFG->dirroot/filter/glossary"); // Any standard filter.
$this->assertFileExists("$CFG->dirroot/filter/multilang"); // Any standard filter.
// Setup fixture.
set_config('filterall', 1);
set_config('stringfilters', 'emailprotect,tidy,multilang');
set_config('stringfilters', 'emailprotect,glossary,multilang');
// Exercise SUT.
filter_set_applies_to_strings('tidy', false);
filter_set_applies_to_strings('glossary', false);
// Validate.
$this->assertEquals('emailprotect,multilang', $CFG->stringfilters);
$this->assertEquals(1, $CFG->filterall);

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2024081600.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2024082000.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.5dev+ (Build: 20240816)'; // Human-friendly version name