Commit 0662bd67 authored by Petr Škoda's avatar Petr Škoda
Browse files

MDL-29996 remove deprecated stuff from filter code

parent fba0abdc
......@@ -35,7 +35,7 @@
require_once($CFG->libdir . '/adminlib.php');
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
$filterpath = optional_param('filterpath', '', PARAM_PATH);
$filterpath = optional_param('filterpath', '', PARAM_SAFEDIR);
require_login();
$systemcontext = context_system::instance();
......@@ -84,39 +84,22 @@
case 'down':
if (isset($filters[$filterpath])) {
$oldpos = $filters[$filterpath]->sortorder;
if ($oldpos <= count($filters)) {
filter_set_global_state($filterpath, $filters[$filterpath]->active, $oldpos + 1);
}
filter_set_global_state($filterpath, $filters[$filterpath]->active, 1);
}
break;
case 'up':
if (isset($filters[$filterpath])) {
$oldpos = $filters[$filterpath]->sortorder;
if ($oldpos >= 1) {
filter_set_global_state($filterpath, $filters[$filterpath]->active, $oldpos - 1);
}
filter_set_global_state($filterpath, $filters[$filterpath]->active, -1);
}
break;
case 'delete':
if (!empty($filternames[$filterpath])) {
$filtername = $filternames[$filterpath];
} else {
$filtername = $filterpath;
}
if (substr($filterpath, 0, 4) == 'mod/') {
$mod = basename($filterpath);
$a = new stdClass;
$a->filter = $filtername;
$a->module = get_string('modulename', $mod);
print_error('cannotdeletemodfilter', 'admin', $returnurl, $a);
}
// If not yet confirmed, display a confirmation message.
if (!optional_param('confirm', '', PARAM_BOOL)) {
$filtername = filter_get_name($filterpath);
$title = get_string('deletefilterareyousure', 'admin', $filtername);
echo $OUTPUT->header();
echo $OUTPUT->heading($title);
......@@ -129,7 +112,7 @@
}
// Do the deletion.
$title = get_string('deletingfilter', 'admin', $filtername);
$title = get_string('deletingfilter', 'admin', $filterpath);
echo $OUTPUT->header();
echo $OUTPUT->heading($title);
......@@ -137,8 +120,8 @@
filter_delete_all_for_filter($filterpath);
$a = new stdClass;
$a->filter = $filtername;
$a->directory = $filterpath;
$a->filter = $filterpath;
$a->directory = "$CFG->dirroot/filter/$filterpath";
echo $OUTPUT->box(get_string('deletefilterfiles', 'admin', $a), 'generalbox', 'notice');
echo $OUTPUT->continue_button($returnurl);
echo $OUTPUT->footer();
......@@ -241,7 +224,7 @@ function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings)
}
// Disable/off/on
$select = new single_select(filters_action_url($filter, 'setstate'), 'newstate', $activechoices, $filterinfo->active, null, 'active' . basename($filter));
$select = new single_select(filters_action_url($filter, 'setstate'), 'newstate', $activechoices, $filterinfo->active, null, 'active' . $filter);
$select->set_label(get_string('isactive', 'filters'), array('class' => 'accesshide'));
$row[] = $OUTPUT->render($select);
......@@ -263,25 +246,20 @@ function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings)
$row[] = $updown;
// Apply to strings.
$select = new single_select(filters_action_url($filter, 'setapplyto'), 'stringstoo', $applytochoices, $applytostrings, null, 'applyto' . basename($filter));
$select = new single_select(filters_action_url($filter, 'setapplyto'), 'stringstoo', $applytochoices, $applytostrings, null, 'applyto' . $filter);
$select->set_label(get_string('applyto', 'filters'), array('class' => 'accesshide'));
$select->disabled = $filterinfo->active == TEXTFILTER_DISABLED;
$row[] = $OUTPUT->render($select);
// Settings link, if required
if (filter_has_global_settings($filter)) {
$row[] = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=filtersetting' .
str_replace('/', '',$filter) . '">' . get_string('settings') . '</a>';
$row[] = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=filtersetting' . $filter . '">' . get_string('settings') . '</a>';
} else {
$row[] = '';
}
// Delete
if (substr($filter, 0, 4) != 'mod/') {
$row[] = '<a href="' . filters_action_url($filter, 'delete') . '">' . get_string('delete') . '</a>';
} else {
$row[] = '';
}
return $row;
}
......@@ -1817,6 +1817,14 @@ class restore_filters_structure_step extends restore_structure_step {
$data = (object)$data;
if (strpos($data->filter, 'filter/') === 0) {
$data->filter = substr($data->filter, 7);
} else if (strpos($data->filter, '/') !== false) {
// Unsupported old filter.
return;
}
if (!filter_is_enabled($data->filter)) { // Not installed or not enabled, nothing to do
return;
}
......@@ -1827,6 +1835,14 @@ class restore_filters_structure_step extends restore_structure_step {
$data = (object)$data;
if (strpos($data->filter, 'filter/') === 0) {
$data->filter = substr($data->filter, 7);
} else if (strpos($data->filter, '/') !== false) {
// Unsupported old filter.
return;
}
if (!filter_is_enabled($data->filter)) { // Not installed or not enabled, nothing to do
return;
}
......
......@@ -26,6 +26,6 @@ function xmldb_filter_activitynames_install() {
global $CFG;
require_once("$CFG->libdir/filterlib.php");
filter_set_global_state('filter/activitynames', TEXTFILTER_ON);
filter_set_global_state('activitynames', TEXTFILTER_ON);
}
......@@ -7,7 +7,7 @@
require_once("../../config.php");
if (!filter_is_enabled('filter/algebra')) {
if (!filter_is_enabled('algebra')) {
print_error('filternotenabled');
}
......
......@@ -9,7 +9,7 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
require_once('../../config.php');
if (!filter_is_enabled('filter/algebra')) {
if (!filter_is_enabled('algebra')) {
print_error('filternotenabled');
}
......
......@@ -27,7 +27,7 @@ require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->libdir . '/adminlib.php');
$contextid = required_param('contextid',PARAM_INT);
$forfilter = optional_param('filter', '', PARAM_SAFEPATH);
$forfilter = optional_param('filter', '', PARAM_SAFEDIR);
list($context, $course, $cm) = get_context_info_array($contextid);
......@@ -82,8 +82,8 @@ if ($forfilter) {
print_error('filterdoesnothavelocalconfig', 'error', $forfilter);
}
require_once($CFG->dirroot . '/filter/local_settings_form.php');
require_once($CFG->dirroot . '/' . $forfilter . '/filterlocalsettings.php');
$formname = basename($forfilter) . '_filter_local_settings_form';
require_once($CFG->dirroot . '/filter/' . $forfilter . '/filterlocalsettings.php');
$formname = $forfilter . '_filter_local_settings_form';
$settingsform = new $formname($CFG->wwwroot . '/filter/manage.php', $forfilter, $context);
if ($settingsform->is_cancelled()) {
redirect($baseurl);
......@@ -96,7 +96,7 @@ if ($forfilter) {
/// Process any form submission.
if ($forfilter == '' && optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
foreach ($availablefilters as $filter => $filterinfo) {
$newstate = optional_param(str_replace('/', '_', $filter), false, PARAM_INT);
$newstate = optional_param($filter, false, PARAM_INT);
if ($newstate !== false && $newstate != $filterinfo->localstate) {
filter_set_local_state($filter, $context->id, $newstate);
}
......@@ -181,9 +181,8 @@ if (empty($availablefilters)) {
} else {
$activechoices[TEXTFILTER_INHERIT] = $strdefaultoff;
}
$filtername = str_replace('/', '_', $filter);
$select = html_writer::label($filterinfo->localstate, 'menu'. $filtername, false, array('class' => 'accesshide'));
$select .= html_writer::select($activechoices, $filtername, $filterinfo->localstate, false);
$select = html_writer::label($filterinfo->localstate, 'menu'. $filter, false, array('class' => 'accesshide'));
$select .= html_writer::select($activechoices, $filter, $filterinfo->localstate, false);
$row[] = $select;
// Settings link, if required
......
......@@ -27,6 +27,6 @@ function xmldb_filter_mediaplugin_install() {
global $CFG;
require_once("$CFG->libdir/filterlib.php");
filter_set_global_state('filter/mediaplugin', TEXTFILTER_ON);
filter_set_global_state('mediaplugin', TEXTFILTER_ON);
}
......@@ -29,7 +29,7 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
require('../../config.php');
if (!filter_is_enabled('filter/tex') and !filter_is_enabled('filter/algebra')) {
if (!filter_is_enabled('tex') and !filter_is_enabled('algebra')) {
print_error('filternotenabled');
}
......
......@@ -9,7 +9,7 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
require_once('../../config.php');
if (!filter_is_enabled('filter/tex')) {
if (!filter_is_enabled('tex')) {
print_error('filternotenabled');
}
......
......@@ -28,7 +28,7 @@
require_once("../../config.php");
if (!filter_is_enabled('filter/tex')) {
if (!filter_is_enabled('tex')) {
print_error('filternotenabled');
}
......
This file describes API changes in core filter API and plugins,
information provided here is intended especially for developers.
=== 2.5 ===
* legacy_filter emulation was removed
* support for 'mod/*' filters was removed
* use short filter name instead of old path, ex.: 'filter/tex' ---> 'tex'
in all filter API functions and methods
=== 2.3 ===
* new setup() method added to moodle_text_filter, invoked before
......
......@@ -6092,8 +6092,7 @@ class admin_page_managefilters extends admin_externalpage {
$found = true;
break;
}
list($type, $filter) = explode('/', $path);
if (strpos($filter, $query) !== false) {
if (strpos($path, $query) !== false) {
$found = true;
break;
}
......
......@@ -456,7 +456,7 @@
<TABLE NAME="filter_active" COMMENT="Stores information about which filters are active in which contexts. Also the filter sort order. See get_active_filters in lib/filterlib.php for how this data is used." PREVIOUS="course_format_options" NEXT="filter_config">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="filter"/>
<FIELD NAME="filter" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="The filter internal name, like 'filter/tex' or 'mod/glossary'." PREVIOUS="id" NEXT="contextid"/>
<FIELD NAME="filter" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="The filter internal name, like 'tex'." PREVIOUS="id" NEXT="contextid"/>
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="References context.id." PREVIOUS="filter" NEXT="active"/>
<FIELD NAME="active" TYPE="int" LENGTH="4" NOTNULL="true" SEQUENCE="false" COMMENT="Whether this filter is active in this context. +1 = On, -1 = Off, no row with this contextid = inherit. As a special case, when contextid points to the system context, -9999 means this filter is completely disabled." PREVIOUS="contextid" NEXT="sortorder"/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Only relevant if contextid points to the system context. In other cases this field should contain 0. The order in which the filters should be applied." PREVIOUS="active"/>
......@@ -472,7 +472,7 @@
<TABLE NAME="filter_config" COMMENT="Stores per-context configuration settings for filters which have them." PREVIOUS="filter_active" NEXT="event">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="filter"/>
<FIELD NAME="filter" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="The filter internal name, like 'filter/tex' or 'mod/glossary'." PREVIOUS="id" NEXT="contextid"/>
<FIELD NAME="filter" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="The filter internal name, like 'tex'." PREVIOUS="id" NEXT="contextid"/>
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="References context.id." PREVIOUS="filter" NEXT="name"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The config variable name." PREVIOUS="contextid" NEXT="value"/>
<FIELD NAME="value" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The correspoding config variable value." PREVIOUS="name"/>
......
......@@ -1524,5 +1524,46 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2012120300.04);
}
if ($oldversion < 2012120300.07) {
// Purge removed module filters and all their settings.
$tables = array('filter_active', 'filter_config');
foreach ($tables as $table) {
$DB->delete_records_select($table, "filter LIKE 'mod/%'");
$filters = $DB->get_records_sql("SELECT DISTINCT filter FROM {{$table}} WHERE filter LIKE 'filter/%'");
foreach ($filters as $filter) {
$DB->set_field($table, 'filter', substr($filter->filter, 7), array('filter'=>$filter->filter));
}
}
$configs = array('stringfilters', 'filterall');
foreach ($configs as $config) {
if ($filters = get_config(null, $config)) {
$filters = explode(',', $filters);
$newfilters = array();
foreach($filters as $filter) {
if (strpos($filter, '/') === false) {
$newfilters[] = $filter;
} else if (strpos($filter, 'filter/') === 0) {
$newfilters[] = substr($filter, 7);
}
}
$filters = implode(',', $newfilters);
set_config($config, $filters);
}
}
unset($tables);
unset($table);
unset($configs);
unset($newfilters);
unset($filters);
unset($filter);
// Main savepoint reached.
upgrade_main_savepoint(true, 2012120300.07);
}
return true;
}
......@@ -33,7 +33,7 @@ class tinymce_dragmath extends editor_tinymce_plugin {
if ($this->get_config('requiretex', 1)) {
// If TeX filter is disabled, do not add button.
$filters = filter_get_active_in_context($context);
if (!array_key_exists('filter/tex', $filters)) {
if (!array_key_exists('tex', $filters)) {
return;
}
}
......
......@@ -34,7 +34,7 @@ class tinymce_moodleemoticon extends editor_tinymce_plugin {
if ($this->get_config('requireemoticon', 1)) {
// If emoticon filter is disabled, do not add button.
$filters = filter_get_active_in_context($context);
if (!array_key_exists('filter/emoticon', $filters)) {
if (!array_key_exists('emoticon', $filters)) {
return;
}
}
......
......@@ -2,6 +2,11 @@ This files describes API changes in /lib/editor/tinymce/* - TinyMCE editor,
information provided here is intended especially for developers.
=== 2.5 ===
* update filter related code to use short filter names instead
of original paths, ex.: 'filter/tex' ---> 'tex'
=== 2.4 ===
new features:
......
......@@ -2715,7 +2715,7 @@ function file_modify_html_header($text) {
}*/
$ufo = '';
if (filter_is_enabled('filter/mediaplugin')) {
if (filter_is_enabled('mediaplugin')) {
// this script is needed by most media filter plugins.
$attributes = array('type'=>'text/javascript', 'src'=>$CFG->httpswwwroot . '/lib/ufo.js');
$ufo = html_writer::tag('script', '', $attributes) . "\n";
......
This diff is collapsed.
......@@ -2654,12 +2654,12 @@ class plugininfo_filter extends plugininfo_base {
// get the list of filters from both /filter and /mod location
$installed = filter_get_all_installed();
foreach ($installed as $filterlegacyname => $displayname) {
foreach ($installed as $name => $displayname) {
$plugin = new $typeclass();
$plugin->type = $type;
$plugin->typerootdir = $typerootdir;
$plugin->name = self::normalize_legacy_name($filterlegacyname);
$plugin->rootdir = $CFG->dirroot . '/' . $filterlegacyname;
$plugin->name = $name;
$plugin->rootdir = "$CFG->dirroot/filter/$name";
$plugin->displayname = $displayname;
$plugin->load_disk_version();
......@@ -2676,9 +2676,9 @@ class plugininfo_filter extends plugininfo_base {
// if we're upgrading from 1.9, the table does not exist yet
// if it does, make sure that all installed filters are registered
$needsreload = false;
foreach (array_keys($installed) as $filterlegacyname) {
if (!isset($globalstates[self::normalize_legacy_name($filterlegacyname)])) {
filter_set_global_state($filterlegacyname, TEXTFILTER_DISABLED);
foreach (array_keys($installed) as $name) {
if (!isset($globalstates[$name])) {
filter_set_global_state($name, TEXTFILTER_DISABLED);
$needsreload = true;
}
}
......@@ -2695,8 +2695,8 @@ class plugininfo_filter extends plugininfo_base {
$plugin->type = $type;
$plugin->typerootdir = $typerootdir;
$plugin->name = $name;
$plugin->rootdir = $CFG->dirroot . '/' . $info->legacyname;
$plugin->displayname = $info->legacyname;
$plugin->rootdir = "$CFG->dirroot/filter/$name";
$plugin->displayname = $name;
$plugin->load_db_version();
......@@ -2721,11 +2721,6 @@ class plugininfo_filter extends plugininfo_base {
* @see load_version_php()
*/
protected function load_version_php() {
if (strpos($this->name, 'mod_') === 0) {
// filters bundled with modules do not have a version.php and so
// do not provide their own versioning information.
return new stdClass();
}
return parent::load_version_php();
}
......@@ -2733,8 +2728,7 @@ class plugininfo_filter extends plugininfo_base {
$globalstates = self::get_global_states();
foreach ($globalstates as $filterlegacyname => $info) {
$name = self::normalize_legacy_name($filterlegacyname);
foreach ($globalstates as $name => $info) {
if ($name === $this->name) {
if ($info->active == TEXTFILTER_DISABLED) {
return false;
......@@ -2753,8 +2747,7 @@ class plugininfo_filter extends plugininfo_base {
if (!isset($globalstates[$this->name])) {
return parent::get_settings_section_name();
}
$legacyname = $globalstates[$this->name]->legacyname;
return 'filtersetting' . str_replace('/', '', $legacyname);
return 'filtersetting' . $this->name;
}
public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
......@@ -2776,33 +2769,7 @@ class plugininfo_filter extends plugininfo_base {
}
public function get_uninstall_url() {
if (strpos($this->name, 'mod_') === 0) {
return null;
} else {
$globalstates = self::get_global_states();
$legacyname = $globalstates[$this->name]->legacyname;
return new moodle_url('/admin/filters.php', array('sesskey' => sesskey(), 'filterpath' => $legacyname, 'action' => 'delete'));
}
}
/**
* Convert legacy filter names like 'filter/foo' or 'mod/bar' into frankenstyle
*
* @param string $legacyfiltername legacy filter name
* @return string frankenstyle-like name
*/
protected static function normalize_legacy_name($legacyfiltername) {
$name = str_replace('/', '_', $legacyfiltername);
if (strpos($name, 'filter_') === 0) {
$name = substr($name, 7);
if (empty($name)) {
throw new coding_exception('Unable to determine filter name: ' . $legacyfiltername);
}
}
return $name;
return new moodle_url('/admin/filters.php', array('sesskey' => sesskey(), 'filterpath' => $this->name, 'action' => 'delete'));
}
/**
......@@ -2826,10 +2793,8 @@ class plugininfo_filter extends plugininfo_base {
$globalstatescache = array();
} else {
foreach (filter_get_global_states() as $legacyname => $info) {
$name = self::normalize_legacy_name($legacyname);
foreach (filter_get_global_states() as $name => $info) {
$filterinfo = new stdClass();
$filterinfo->legacyname = $legacyname;
$filterinfo->active = $info->active;
$filterinfo->sortorder = $info->sortorder;
$globalstatescache[$name] = $filterinfo;
......
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