From: tjhunt Date: Mon, 13 Apr 2009 07:15:50 +0000 (+0000) Subject: filters: MDL-7336 separate out manage filters and common filter settings X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dcdf3b2918e0c9c368c746a0a89faaa2b25c9d1f;p=moodle.git filters: MDL-7336 separate out manage filters and common filter settings --- diff --git a/admin/filters.php b/admin/filters.php index 7bab93c050..d5d35fe664 100644 --- a/admin/filters.php +++ b/admin/filters.php @@ -32,6 +32,7 @@ *//** */ require_once(dirname(__FILE__) . '/../config.php'); + require_once($CFG->libdir . '/adminlib.php'); $action = optional_param('action', '', PARAM_ACTION); $filterpath = optional_param('filterpath', '', PARAM_PATH); @@ -40,11 +41,8 @@ $systemcontext = get_context_instance(CONTEXT_SYSTEM); require_capability('moodle/site:config', $systemcontext); - $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=managefilters"; - - if (!confirm_sesskey()) { - redirect($returnurl); - } + $returnurl = "$CFG->wwwroot/$CFG->admin/filters.php"; + admin_externalpage_setup('managefilters'); $filters = filter_get_global_states(); @@ -55,8 +53,16 @@ unset($newfilters[$filter]); } - if (!isset($filters[$filterpath]) && !isset($newfilters[$filterpath])) { - throw new moodle_exception('filternotinstalled', 'error', $returnurl, $filterpath); +/// Process actions ============================================================ + + if ($action) { + if (!isset($filters[$filterpath]) && !isset($newfilters[$filterpath])) { + throw new moodle_exception('filternotinstalled', 'error', $returnurl, $filterpath); + } + + if (!confirm_sesskey()) { + redirect($returnurl); + } } switch ($action) { @@ -112,18 +118,18 @@ // If not yet confirmed, display a confirmation message. if (!optional_param('confirm', '', PARAM_BOOL)) { $title = get_string('deletefilterareyousure', 'admin', $filtername); - print_header($title, $title); + admin_externalpage_print_header(); print_heading($title); notice_yesno(get_string('deletefilterareyousuremessage', 'admin', $filtername), $CFG->wwwroot . '/' . $CFG->admin . '/filters.php?action=delete&filterpath=' . $filterpath . '&confirm=1&sesskey=' . sesskey(), - "$CFG->wwwroot/$CFG->admin/settings.php", NULL, array('section' => 'managefilters'), 'post', 'get'); - print_footer('empty'); + $returnurl, NULL, NULL, 'post', 'get'); + admin_externalpage_print_footer(); exit; } // Do the deletion. $title = get_string('deletingfilter', 'admin', $filtername); - print_header($title, $title); + admin_externalpage_print_header(); print_heading($title); // Delete all data for this plugin. @@ -134,7 +140,7 @@ $a->directory = $filterpath; print_box(get_string('deletefilterfiles', 'admin', $a), 'generalbox', 'notice'); print_continue($returnurl); - print_footer('empty'); + admin_externalpage_print_footer(); exit; } @@ -144,5 +150,139 @@ } // Reset caches and return - reset_text_filters_cache(); - redirect($returnurl); + if ($action) { + reset_text_filters_cache(); + redirect($returnurl); + } + +/// End of process actions ===================================================== + +/// Print the page heading. + admin_externalpage_print_header(); + print_heading(get_string('manageqtypes', 'admin')); + + $activechoices = array( + TEXTFILTER_DISABLED => get_string('disabled', 'filters'), + TEXTFILTER_OFF => get_string('offbutavailable', 'filters'), + TEXTFILTER_ON => get_string('on', 'filters'), + ); + $applytochoices = array( + 0 => get_string('content', 'filters'), + 1 => get_string('contentandheadings', 'filters'), + ); + + $filters = filter_get_global_states(); + + // In case any new filters have been installed, but not put in the table yet. + $filternames = filter_get_all_installed(); + $newfilters = $filternames; + foreach ($filters as $filter => $notused) { + unset($newfilters[$filter]); + } + $stringfilters = filter_get_string_filters(); + + $table = new object(); + $table->head = array(get_string('filter'), get_string('isactive', 'filters'), + get_string('order'), get_string('applyto', 'filters'), get_string('settings'), get_string('delete')); + $table->align = array('left', 'left', 'center', 'left', 'left'); + $table->width = '100%'; + $table->data = array(); + + $lastactive = null; + foreach ($filters as $filter => $filterinfo) { + if ($filterinfo->active != TEXTFILTER_DISABLED) { + $lastactive = $filter; + } + } + + // iterate through filters adding to display table + $firstrow = true; + foreach ($filters as $filter => $filterinfo) { + $applytostrings = isset($stringfilters[$filter]) && $filterinfo->active != TEXTFILTER_DISABLED; + $row = get_table_row($filterinfo, $firstrow, $filter == $lastactive, $applytostrings); + $table->data[] = $row; + if ($filterinfo->active == TEXTFILTER_DISABLED) { + $table->rowclass[] = 'dimmed_text'; + } else { + $table->rowclass[] = ''; + } + $firstrow = false; + } + foreach ($newfilters as $filter => $filtername) { + $filterinfo = new stdClass; + $filterinfo->filter = $filter; + $filterinfo->active = TEXTFILTER_DISABLED; + $row = get_table_row($filterinfo, false, false, false); + $table->data[] = $row; + $table->rowclass[] = 'dimmed_text'; + } + + print_table($table); + echo '

' . get_string('filterallwarning', 'filters') . '

'; + admin_externalpage_print_footer(); + +/// Display helper functions =================================================== + +function action_url($filterpath, $action) { + global $returnurl; + return $returnurl . '?sesskey=' . sesskey() . '&filterpath=' . + urlencode($filterpath) . '&action=' . $action; +} + +function action_icon($url, $icon, $straction) { + global $CFG; + return '' . + '' . $straction . ' '; +} + +function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings) { + global $CFG, $activechoices, $applytochoices, $filternames; + $row = array(); + $filter = $filterinfo->filter; + + // Filter name + if (!empty($filternames[$filter])) { + $row[] = $filternames[$filter]; + } else { + $row[] = '' . get_string('filemissing', '', $filter) . ''; + } + + // Disable/off/on + $row[] = popup_form(action_url($filter, 'setstate') . '&newstate=', $activechoices, + 'active' . basename($filter), $filterinfo->active, '', '', '', true, 'self', '', NULL, get_string('save', 'admin')); + + // Re-order + $updown = ''; + $spacer = ' '; + if ($filterinfo->active != TEXTFILTER_DISABLED) { + if (!$isfirstrow) { + $updown .= action_icon(action_url($filter, 'up'), 'up', get_string('up')); + } else { + $updown .= $spacer; + } + if (!$islastactive) { + $updown .= action_icon(action_url($filter, 'down'), 'down', get_string('down')); + } else { + $updown .= $spacer; + } + } + $row[] = $updown; + + // Apply to strings. + $row[] = popup_form(action_url($filter, 'setapplyto') . '&stringstoo=', $applytochoices, + 'applyto' . basename($filter), $applytostrings, '', '', '', true, 'self', '', NULL, get_string('save', 'admin'), + $filterinfo->active == TEXTFILTER_DISABLED); + + // Settings link, if required + $settings = ''; + if (filter_has_global_settings($filter)) { + $settings = '' . get_string('settings') . ''; + } + $row[] = $settings; + + // Delete + $row[] = '' . get_string('delete') . ''; + + return $row; +} diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 9a82a275c0..a8474ed1f7 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -74,8 +74,11 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) $ADMIN->add('modules', new admin_category('filtersettings', get_string('managefilters'))); + + $ADMIN->add('filtersettings', new admin_page_managefilters()); + // "filtersettings" settingpage - $temp = new admin_settingpage('managefilters', get_string('filtersettings', 'admin')); + $temp = new admin_settingpage('commonfiltersettings', get_string('commonfiltersettings', 'admin')); if ($ADMIN->fulltree) { $cachetimes = array( 604800 => get_string('numdays','',7), @@ -101,8 +104,6 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) 0 => get_string('no') ); $items = array(); - $items[] = new admin_setting_managefilters(); - $items[] = new admin_setting_heading('managefilterscommonheading', get_string('commonsettings', 'admin'), ''); $items[] = new admin_setting_configselect('cachetext', get_string('cachetext', 'admin'), get_string('configcachetext', 'admin'), 60, $cachetimes); $items[] = new admin_setting_configselect('filteruploadedfiles', get_string('filteruploadedfiles', 'admin'), get_string('configfilteruploadedfiles', 'admin'), 0, array('0' => get_string('none'), '1' => get_string('allfiles'), '2' => get_string('htmlfilesonly'))); diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 86c18d23c8..d441f63e0d 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -58,6 +58,7 @@ $string['checkboxno'] = 'No'; $string['choosefiletoedit'] = 'Choose file to edit'; $string['clamfailureonupload'] = 'On clam AV failure'; $string['cleanup'] = 'Cleanup'; +$string['commonfiltersettings'] = 'Common filter settings'; $string['commonsettings'] = 'Common settings'; $string['componentinstalled'] = 'Component Installed'; $string['computedfromlogs'] = 'Computed from logs since $a.'; @@ -734,6 +735,7 @@ $string['roleswithexceptions'] = '$a->roles, with $a->exceptions'; $string['rowpreviewnum'] = 'Preview rows'; $string['rssglobaldisabled'] = 'Disabled at server level'; $string['runclamavonupload'] = 'Use clam AV on uploaded files'; +$string['save'] = 'Save'; $string['savechanges'] = 'Save Changes'; $string['search'] = 'Search'; $string['searchresults'] = 'Search Results'; diff --git a/lib/adminlib.php b/lib/adminlib.php index a5b3d6b1a4..b3cc778fac 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3697,179 +3697,41 @@ class admin_setting_manageauths extends admin_setting { /** * Special class for filter administration. */ -class admin_setting_managefilters extends admin_setting { +class admin_page_managefilters extends admin_externalpage { public function __construct() { - parent::__construct('filtersui', get_string('filtersettings', 'admin'), '', ''); - } - - public function get_setting() { - return true; - } - - public function get_defaultsetting() { - return true; - } - - public function write_setting($data) { - // do not write any settings. Instead all our UI submits to admin/filters.php - // which makes and changes, then redirects back. - return ''; + global $CFG; + parent::__construct('managefilters', get_string('filtersettings', 'admin'), "$CFG->wwwroot/$CFG->admin/filters.php"); } - public function is_related($query) { - if (parent::is_related($query)) { - return true; + public function search($query) { + global $CFG; + if ($result = parent::search($query)) { + return $result; } + $found = false; $filternames = filter_get_all_installed(); $textlib = textlib_get_instance(); foreach ($filternames as $path => $strfiltername) { if (strpos($textlib->strtolower($strfiltername), $query) !== false) { - return true; + $found = true; + break; } list($type, $filter) = explode('/', $path); if (strpos($filter, $query) !== false) { - return true; + $found = true; + break; } } - return false; - } - - protected function action_url($filterpath, $action) { - global $CFG; - return $CFG->wwwroot . '/' . $CFG->admin . '/filters.php?sesskey=' . sesskey() . - '&filterpath=' . urlencode($filterpath) . '&action=' . $action; - } - - protected function action_icon($url, $icon, $straction) { - global $CFG; - return '' . - '' . $straction . ' '; - } - - protected function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings) { - global $CFG; - $row = array(); - $filter = $filterinfo->filter; - // Filter name - if (!empty($this->filternames[$filter])) { - $row[] = $this->filternames[$filter]; + if ($found) { + $result = new stdClass; + $result->page = $this; + $result->settings = array(); + return array($this->name => $result); } else { - $row[] = '' . get_string('filemissing', '', $filter) . ''; - } - - // Disable/off/on - $row[] = popup_form($this->action_url($filter, 'setstate') . '&newstate=', $this->activechoices, - 'active' . basename($filter), $filterinfo->active, '', '', '', true, 'self', '', NULL, get_string('save')); - - // Re-order - $updown = ''; - $spacer = ' '; - if ($filterinfo->active != TEXTFILTER_DISABLED) { - if (!$isfirstrow) { - $updown .= $this->action_icon($this->action_url($filter, 'up'), 'up', $this->strup); - } else { - $updown .= $spacer; - } - if (!$islastactive) { - $updown .= $this->action_icon($this->action_url($filter, 'down'), 'down', $this->strdown); - } else { - $updown .= $spacer; - } - } - $row[] = $updown; - - // Apply to strings. - $row[] = popup_form($this->action_url($filter, 'setapplyto') . '&stringstoo=', $this->applytochoices, - 'applyto' . basename($filter), $applytostrings, '', '', '', true, 'self', '', NULL, get_string('save'), - $filterinfo->active == TEXTFILTER_DISABLED); - - // Settings link, if required - $settings = ''; - if (filter_has_global_settings($filter)) { - $settings = '' . $this->strsettings . ''; - } - $row[] = $settings; - - // Delete - $row[] = '' . $this->strdelete . ''; - - return $row; - } - - public function output_html($data, $query='') { - global $CFG; - - $this->activechoices = array( - TEXTFILTER_DISABLED => get_string('disabled', 'filters'), - TEXTFILTER_OFF => get_string('offbutavailable', 'filters'), - TEXTFILTER_ON => get_string('on', 'filters'), - ); - $this->applytochoices = array( - 0 => get_string('content', 'filters'), - 1 => get_string('contentandheadings', 'filters'), - ); - $this->strup = get_string('up'); - $this->strdown = get_string('down'); - $this->strsettings = get_string('settings'); - $this->strdelete = get_string('delete'); - - $filters = filter_get_global_states(); - - // In case any new filters have been installed, but not put in the table yet. - $this->filternames = filter_get_all_installed(); - $newfilters = $this->filternames; - foreach ($filters as $filter => $notused) { - unset($newfilters[$filter]); - } - $stringfilters = filter_get_string_filters(); - - $return = print_heading(get_string('actfilterhdr', 'filters'), '', 3, 'main', true); - $return .= print_box_start('generalbox filtersui', '', true); - - $table = new object(); - $table->head = array(get_string('filter'), get_string('isactive', 'filters'), - get_string('order'), get_string('applyto', 'filters'), $this->strsettings, $this->strdelete); - $table->align = array('left', 'left', 'center', 'left', 'left'); - $table->width = '100%'; - $table->data = array(); - - $lastactive = null; - foreach ($filters as $filter => $filterinfo) { - if ($filterinfo->active != TEXTFILTER_DISABLED) { - $lastactive = $filter; - } - } - - // iterate through filters adding to display table - $firstrow = true; - foreach ($filters as $filter => $filterinfo) { - $applytostrings = isset($stringfilters[$filter]) && $filterinfo->active != TEXTFILTER_DISABLED; - $row = $this->get_table_row($filterinfo, $firstrow, $filter == $lastactive, $applytostrings); - $table->data[] = $row; - if ($filterinfo->active == TEXTFILTER_DISABLED) { - $table->rowclass[] = 'dimmed_text'; - } else { - $table->rowclass[] = ''; - } - $firstrow = false; - } - foreach ($newfilters as $filter => $filtername) { - $filterinfo = new stdClass; - $filterinfo->filter = $filter; - $filterinfo->active = TEXTFILTER_DISABLED; - $row = $this->get_table_row($filterinfo, false, false, false); - $table->data[] = $row; - $table->rowclass[] = 'dimmed_text'; + return array(); } - - $return .= print_table($table, true); - $return .= '

' . get_string('tablenosave', 'filters') . '

'; - $return .= '

' . get_string('filterallwarning', 'filters') . '

'; - $return .= print_box_end(true); - return highlight($query, $return); } }