Skip to content

Commit

Permalink
MDL-29996 remove deprecated stuff from filter code
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Dec 30, 2012
1 parent fba0abd commit 0662bd6
Show file tree
Hide file tree
Showing 24 changed files with 470 additions and 491 deletions.
46 changes: 12 additions & 34 deletions admin/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -129,16 +112,16 @@
}

// Do the deletion.
$title = get_string('deletingfilter', 'admin', $filtername);
$title = get_string('deletingfilter', 'admin', $filterpath);
echo $OUTPUT->header();
echo $OUTPUT->heading($title);

// Delete all data for this plugin.
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();
Expand Down Expand Up @@ -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);

Expand All @@ -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[] = '';
}
$row[] = '<a href="' . filters_action_url($filter, 'delete') . '">' . get_string('delete') . '</a>';

return $row;
}
16 changes: 16 additions & 0 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,14 @@ public function process_active($data) {

$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;
}
Expand All @@ -1827,6 +1835,14 @@ public function process_config($data) {

$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;
}
Expand Down
2 changes: 1 addition & 1 deletion filter/activitynames/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

2 changes: 1 addition & 1 deletion filter/algebra/algebradebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

require_once("../../config.php");

if (!filter_is_enabled('filter/algebra')) {
if (!filter_is_enabled('algebra')) {
print_error('filternotenabled');
}

Expand Down
2 changes: 1 addition & 1 deletion filter/algebra/pix.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

require_once('../../config.php');

if (!filter_is_enabled('filter/algebra')) {
if (!filter_is_enabled('algebra')) {
print_error('filternotenabled');
}

Expand Down
13 changes: 6 additions & 7 deletions filter/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
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);

Expand Down Expand Up @@ -82,8 +82,8 @@
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);
Expand All @@ -96,7 +96,7 @@
/// 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);
}
Expand Down Expand Up @@ -181,9 +181,8 @@
} 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
Expand Down
2 changes: 1 addition & 1 deletion filter/mediaplugin/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

2 changes: 1 addition & 1 deletion filter/tex/displaytex.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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');
}

Expand Down
2 changes: 1 addition & 1 deletion filter/tex/pix.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

require_once('../../config.php');

if (!filter_is_enabled('filter/tex')) {
if (!filter_is_enabled('tex')) {
print_error('filternotenabled');
}

Expand Down
2 changes: 1 addition & 1 deletion filter/tex/texdebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

require_once("../../config.php");

if (!filter_is_enabled('filter/tex')) {
if (!filter_is_enabled('tex')) {
print_error('filternotenabled');
}

Expand Down
7 changes: 7 additions & 0 deletions filter/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
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
Expand Down
3 changes: 1 addition & 2 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6092,8 +6092,7 @@ public function search($query) {
$found = true;
break;
}
list($type, $filter) = explode('/', $path);
if (strpos($filter, $query) !== false) {
if (strpos($path, $query) !== false) {
$found = true;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand All @@ -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"/>
Expand Down
41 changes: 41 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion lib/editor/tinymce/plugins/dragmath/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function update_init_params(array &$params, context $context,
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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/editor/tinymce/plugins/moodleemoticon/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function update_init_params(array &$params, context $context,
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;
}
}
Expand Down
5 changes: 5 additions & 0 deletions lib/editor/tinymce/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lib/filelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading

0 comments on commit 0662bd6

Please sign in to comment.