]> git.mjollnir.org Git - moodle.git/commitdiff
filters: MDL-7336 separate out manage filters and common filter settings
authortjhunt <tjhunt>
Mon, 13 Apr 2009 07:15:50 +0000 (07:15 +0000)
committertjhunt <tjhunt>
Mon, 13 Apr 2009 07:15:50 +0000 (07:15 +0000)
admin/filters.php
admin/settings/plugins.php
lang/en_utf8/admin.php
lib/adminlib.php

index 7bab93c050841366628b6464a224e792f0debd83..d5d35fe6649fd1f704ae53a0e77b56a8a03a511b 100644 (file)
@@ -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);
     $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();
 
         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) {
         // 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&amp;filterpath=' . $filterpath . '&amp;confirm=1&amp;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.
         $a->directory = $filterpath;
         print_box(get_string('deletefilterfiles', 'admin', $a), 'generalbox', 'notice');
         print_continue($returnurl);
-        print_footer('empty');
+        admin_externalpage_print_footer();
         exit;
     }
 
     }
 
     // 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 '<p class="filtersettingnote">' . get_string('filterallwarning', 'filters') . '</p>';
+    admin_externalpage_print_footer();
+
+/// Display helper functions ===================================================
+
+function action_url($filterpath, $action) {
+    global $returnurl;
+    return $returnurl . '?sesskey=' . sesskey() . '&amp;filterpath=' .
+            urlencode($filterpath) . '&amp;action=' . $action;
+}
+
+function action_icon($url, $icon, $straction) {
+    global $CFG;
+    return '<a href="' . $url . '" title="' . $straction . '">' .
+            '<img src="' . $CFG->pixpath . '/t/' . $icon . '.gif" alt="' . $straction . '" /></a> ';
+}
+
+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[] = '<span class="error">' . get_string('filemissing', '', $filter) . '</span>';
+    }
+
+    // Disable/off/on
+    $row[] = popup_form(action_url($filter, 'setstate') . '&amp;newstate=', $activechoices,
+            'active' . basename($filter), $filterinfo->active, '', '', '', true, 'self', '', NULL, get_string('save', 'admin'));
+
+    // Re-order
+    $updown = '';
+    $spacer = '<img src="' . $CFG->pixpath . '/spacer.gif" class="iconsmall" alt="" /> ';
+    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') . '&amp;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 = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=filtersetting' .
+                str_replace('/', '',$filter) . '">' . get_string('settings') . '</a>';
+    }
+    $row[] = $settings;
+
+    // Delete
+    $row[] = '<a href="' . action_url($filter, 'delete') . '">' . get_string('delete') . '</a>';
+
+    return $row;
+}
index 9a82a275c01be9a60eaec5faad6ed91d47b8494d..a8474ed1f766dd41390bcd002aeaa1cd7a2f35e0 100644 (file)
@@ -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')));
index 86c18d23c81129fb4dee37c8d8dd3a0006276cd4..d441f63e0d1cf93ae91069a01a87bcf19a6a3189 100644 (file)
@@ -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';
index a5b3d6b1a42f0f1ff4581b6966b43f025ff14cc4..b3cc778fac70c7d683b953b0ebf64ac843d01ea0 100644 (file)
@@ -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() .
-                '&amp;filterpath=' . urlencode($filterpath) . '&amp;action=' . $action;
-    }
-
-    protected function action_icon($url, $icon, $straction) {
-        global $CFG;
-        return '<a href="' . $url . '" title="' . $straction . '">' .
-                '<img src="' . $CFG->pixpath . '/t/' . $icon . '.gif" alt="' . $straction . '" /></a> ';
-    }
-
-    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[] = '<span class="error">' . get_string('filemissing', '', $filter) . '</span>';
-        }
-
-        // Disable/off/on
-        $row[] = popup_form($this->action_url($filter, 'setstate') . '&amp;newstate=', $this->activechoices,
-                'active' . basename($filter), $filterinfo->active, '', '', '', true, 'self', '', NULL, get_string('save'));
-
-        // Re-order
-        $updown = '';
-        $spacer = '<img src="' . $CFG->pixpath . '/spacer.gif" class="iconsmall" alt="" /> ';
-        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') . '&amp;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 = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=filtersetting' .
-                    str_replace('/', '',$filter) . '">' . $this->strsettings . '</a>';
-        }
-        $row[] = $settings;
-
-        // Delete
-        $row[] = '<a href="' . $this->action_url($filter, 'delete') . '">' . $this->strdelete . '</a>';
-
-        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 .= '<p class="filtersettingnote">' . get_string('tablenosave', 'filters') . '</p>';
-        $return .= '<p class="filtersettingnote">' . get_string('filterallwarning', 'filters') . '</p>';
-        $return .= print_box_end(true);
-        return highlight($query, $return);
     }
 }