MDL-76867 core_admin: Migrate editors admin ui to plugin management

This commit is contained in:
Andrew Nicols
2023-03-14 08:44:15 +08:00
parent 9f1c596dbd
commit f54cc61e4b
6 changed files with 228 additions and 231 deletions
-178
View File
@@ -7239,184 +7239,6 @@ class admin_setting_manageauths extends admin_setting {
}
}
/**
* Special class for authentication administration.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_manageeditors extends admin_setting {
/**
* Calls parent::__construct with specific arguments
*/
public function __construct() {
$this->nosave = true;
parent::__construct('editorsui', get_string('editorsettings', 'editor'), '', '');
}
/**
* Always returns true, does nothing
*
* @return true
*/
public function get_setting() {
return true;
}
/**
* Always returns true, does nothing
*
* @return true
*/
public function get_defaultsetting() {
return true;
}
/**
* Always returns '', does not write anything
*
* @return string Always returns ''
*/
public function write_setting($data) {
// do not write any setting
return '';
}
/**
* Checks if $query is one of the available editors
*
* @param string $query The string to search for
* @return bool Returns true if found, false if not
*/
public function is_related($query) {
if (parent::is_related($query)) {
return true;
}
$editors_available = editors_get_available();
foreach ($editors_available as $editor=>$editorstr) {
if (strpos($editor, $query) !== false) {
return true;
}
if (strpos(core_text::strtolower($editorstr), $query) !== false) {
return true;
}
}
return false;
}
/**
* Builds the XHTML to display the control
*
* @param string $data Unused
* @param string $query
* @return string
*/
public function output_html($data, $query='') {
global $CFG, $OUTPUT;
// display strings
$txt = get_strings(array('administration', 'settings', 'edit', 'name', 'enable', 'disable',
'up', 'down', 'none'));
$struninstall = get_string('uninstallplugin', 'core_admin');
$txt->updown = "$txt->up/$txt->down";
$editors_available = editors_get_available();
$active_editors = explode(',', $CFG->texteditors);
$active_editors = array_reverse($active_editors);
foreach ($active_editors as $key=>$editor) {
if (empty($editors_available[$editor])) {
unset($active_editors[$key]);
} else {
$name = $editors_available[$editor];
unset($editors_available[$editor]);
$editors_available[$editor] = $name;
}
}
if (empty($active_editors)) {
//$active_editors = array('textarea');
}
$editors_available = array_reverse($editors_available, true);
$return = $OUTPUT->heading(get_string('acteditorshhdr', 'editor'), 3, 'main', true);
$return .= $OUTPUT->box_start('generalbox editorsui');
$table = new html_table();
$table->head = array($txt->name, $txt->enable, $txt->updown, $txt->settings, $struninstall);
$table->colclasses = array('leftalign', 'centeralign', 'centeralign', 'centeralign', 'centeralign');
$table->id = 'editormanagement';
$table->attributes['class'] = 'admintable generaltable';
$table->data = array();
// iterate through auth plugins and add to the display table
$updowncount = 1;
$editorcount = count($active_editors);
$url = "editors.php?sesskey=" . sesskey();
foreach ($editors_available as $editor => $name) {
// hide/show link
$class = '';
if (in_array($editor, $active_editors)) {
$hideshow = "<a href=\"$url&amp;action=disable&amp;editor=$editor\">";
$hideshow .= $OUTPUT->pix_icon('t/hide', get_string('disable')) . '</a>';
$enabled = true;
$displayname = $name;
}
else {
$hideshow = "<a href=\"$url&amp;action=enable&amp;editor=$editor\">";
$hideshow .= $OUTPUT->pix_icon('t/show', get_string('enable')) . '</a>';
$enabled = false;
$displayname = $name;
$class = 'dimmed_text';
}
// up/down link (only if auth is enabled)
$updown = '';
if ($enabled) {
if ($updowncount > 1) {
$updown .= "<a href=\"$url&amp;action=up&amp;editor=$editor\">";
$updown .= $OUTPUT->pix_icon('t/up', get_string('moveup')) . '</a>&nbsp;';
}
else {
$updown .= $OUTPUT->spacer() . '&nbsp;';
}
if ($updowncount < $editorcount) {
$updown .= "<a href=\"$url&amp;action=down&amp;editor=$editor\">";
$updown .= $OUTPUT->pix_icon('t/down', get_string('movedown')) . '</a>&nbsp;';
}
else {
$updown .= $OUTPUT->spacer() . '&nbsp;';
}
++ $updowncount;
}
// settings link
if (file_exists($CFG->dirroot.'/lib/editor/'.$editor.'/settings.php')) {
$eurl = new moodle_url('/admin/settings.php', array('section'=>'editorsettings'.$editor));
$settings = "<a href='$eurl'>{$txt->settings}</a>";
} else {
$settings = '';
}
$uninstall = '';
if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('editor_'.$editor, 'manage')) {
$uninstall = html_writer::link($uninstallurl, $struninstall);
}
// Add a row to the table.
$row = new html_table_row(array($displayname, $hideshow, $updown, $settings, $uninstall));
if ($class) {
$row->attributes['class'] = $class;
}
$table->data[] = $row;
}
$return .= html_writer::table($table);
$return .= get_string('configeditorplugins', 'editor').'<br />'.get_string('tablenosave', 'admin');
$return .= $OUTPUT->box_end();
return highlight($query, $return);
}
}
/**
* Special class for antiviruses administration.
*