Commit 32576936 authored by Sara Arjona's avatar Sara Arjona
Browse files

MDL-72347 filter: Remove censor filter

Word censorship filter is not widely used these days so it has been
removed from Moodle core.
parent 1a9bee69
//////////////////////////
// //
// Censorship Filter //
// //
//////////////////////////
This is a very simple Text Filter that searches text
being output to the screen, replacing "bad" words
with other words.
To customise the word list, use the censor settings page
in the filters administration page.
If no customised list has been provided, a default list
specified in the current language pack will be used. Note that
the custom list is an alternative to the default list not
an addition to it.
<?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_censor.
*
* @package filter_censor
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace filter_censor\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for filter_censor 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';
}
}
<?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/>.
/**
* Censorship filtering
*
* This very simple example of a Text Filter will parse
* printed text, blacking out words perceived to be bad
*
* @package filter
* @subpackage censor
* @copyright 2004 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
//////////////////////////////////////////////////////////////
// Censorship filtering
//
// This very simple example of a Text Filter will parse
// printed text, blacking out words perceived to be bad
//
// The list of words is in the lang/xx/moodle.php
//
//////////////////////////////////////////////////////////////
class filter_censor extends moodle_text_filter {
private function _canseecensor() {
return is_siteadmin(); //TODO: add proper access control
}
function hash(){
$cap = "mod/filter:censor";
if (is_siteadmin()) { //TODO: add proper access control
$cap = "mod/filter:seecensor";
}
return $cap;
}
function filter($text, array $options = array()){
static $words;
global $CFG;
if (!isset($CFG->filter_censor_badwords)) {
set_config( 'filter_censor_badwords','' );
}
if (empty($words)) {
$words = array();
if (empty($CFG->filter_censor_badwords)) {
$badwords = explode(',',get_string('badwords', 'filter_censor'));
}
else {
$badwords = explode(',', $CFG->filter_censor_badwords);
}
foreach ($badwords as $badword) {
$badword = trim($badword);
if($this->_canseecensor()){
$words[] = new filterobject($badword, '<span class="censoredtexthighlight" title="'.$badword.'">', '</span>',
false, false, $badword);
} else {
$words[] = new filterobject($badword, '<span class="censoredtext" title="'.$badword.'">',
'</span>', false, false, str_pad('',strlen($badword),'*'));
}
}
}
return filter_phrases($text, $words);
}
}
<?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_censor', language 'en', branch 'MOODLE_20_STABLE'
*
* @package filter_censor
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['badwords'] = 'shit,fucked,fucker,fuck,dickhead,dick,cockhead,cock,cunt,asshole,arsehole,prick,bitch,jism,whore,slut,wanker,wank,bastard,dildo,masturbate,orgasm,penis,nigger,pussy,vagina';
$string['filtername'] = 'Word censorship';
$string['privacy:metadata'] = 'The Word censorship plugin does not store any personal data.';
<?php
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configtextarea('filter_censor_badwords', get_string('badwordslist','admin'),
get_string('badwordsconfig', 'admin').'<br />'.get_string('badwordsdefault', 'admin'), ''));
}
<?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 censor
* @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 = 2021052500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2021052500; // Requires this Moodle version.
$plugin->component = 'filter_censor'; // Full name of the plugin (used for diagnostics)
This file describes API changes in core filter API and plugins,
information provided here is intended especially for developers.
=== 4.0 ===
* The Word censorship (filter_censor) filter has been completely removed from core. It has been moved to the plugins database
repository, so it can still be installed as a third-party plugin.
=== 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:
......
......@@ -1725,8 +1725,9 @@ class core_plugin_manager {
'block' => array('course_overview', 'messages', 'community', 'participants'),
'cachestore' => array('memcache'),
'enrol' => array('authorize'),
'portfolio' => array('picasa'),
'filter' => array('censor'),
'media' => array('swf'),
'portfolio' => array('picasa'),
'qformat' => array('webct'),
'message' => array('jabber'),
'quizaccess' => array('safebrowser'),
......@@ -1861,7 +1862,7 @@ class core_plugin_manager {
),
'filter' => array(
'activitynames', 'algebra', 'censor', 'emailprotect',
'activitynames', 'algebra', 'emailprotect',
'emoticon', 'displayh5p', 'mathjaxloader', 'mediaplugin', 'multilang', 'tex', 'tidy',
'urltolink', 'data', 'glossary'
),
......
......@@ -2862,5 +2862,15 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021092400.03);
}
if ($oldversion < 2021100300.01) {
// Remove filter_censor (unless it has manually been added back).
if (!file_exists($CFG->dirroot . '/filter/censor/filter.php')) {
unset_all_config_for_plugin('filter_censor');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2021100300.01);
}
return true;
}
......@@ -76,9 +76,9 @@ class core_weblib_testcase extends advanced_testcase {
$generator = $this->getDataGenerator();
$course = $generator->create_course();
$user = $generator->create_user();
$rawstring = 'Shortname <a href="#">link</a> curseword';
$expectednofilter = strip_links($rawstring);
$expectedfilter = 'Shortname link \*\**';
$rawstring = '<span lang="en" class="multilang">English</span><span lang="ca" class="multilang">Catalan</span>';
$expectednofilter = strip_tags($rawstring);
$expectedfilter = 'English';
$striplinks = true;
$context = context_course::instance($course->id);
$options = [
......@@ -94,22 +94,21 @@ class core_weblib_testcase extends advanced_testcase {
$nofilterresult = format_string($rawstring, $striplinks, $options);
$this->assertEquals($expectednofilter, $nofilterresult);
// Add the censor filter. Make sure it's enabled globally.
// Add the multilang filter. Make sure it's enabled globally.
$CFG->filterall = true;
$CFG->stringfilters = 'censor';
$CFG->filter_censor_badwords = 'curseword';
filter_set_global_state('censor', TEXTFILTER_ON);
filter_set_local_state('censor', $context->id, TEXTFILTER_ON);
$CFG->stringfilters = 'multilang';
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_local_state('multilang', $context->id, TEXTFILTER_ON);
// This time we want to apply the filters.
$options['filter'] = true;
$filterresult = format_string($rawstring, $striplinks, $options);
$this->assertMatchesRegularExpression("/$expectedfilter/", $filterresult);
filter_set_local_state('censor', $context->id, TEXTFILTER_OFF);
filter_set_local_state('multilang', $context->id, TEXTFILTER_OFF);
// Confirm that we get back the cached string. The result should be
// the same as the filtered text above even though we've disabled the
// censor filter in between.
// multilang filter in between.
$cachedresult = format_string($rawstring, $striplinks, $options);
$this->assertMatchesRegularExpression("/$expectedfilter/", $cachedresult);
}
......
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2021100300.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021100300.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20211003)'; // Human-friendly version name
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment