Skip to content

Commit

Permalink
MDL-36194 add support for editor uninstallation
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Nov 7, 2012
1 parent 20aea2e commit 4f66c75
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
52 changes: 49 additions & 3 deletions admin/editors.php
Expand Up @@ -8,14 +8,18 @@
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');

$action = required_param('action', PARAM_ALPHANUMEXT);
$editor = required_param('editor', PARAM_PLUGIN);
$confirm = optional_param('confirm', 0, PARAM_BOOL);

$PAGE->set_url('/admin/editors.php', array('action'=>$action, 'editor'=>$editor));
$PAGE->set_context(context_system::instance());

require_login();
require_capability('moodle/site:config', context_system::instance());

$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageeditors";

$action = optional_param('action', '', PARAM_ALPHANUMEXT);
$editor = optional_param('editor', '', PARAM_PLUGIN);

// get currently installed and enabled auth plugins
$available_editors = editors_get_available();
if (!empty($editor) and empty($available_editors[$editor])) {
Expand Down Expand Up @@ -78,6 +82,48 @@
}
}
break;

case 'uninstall':
if ($editor === 'textarea') {
redirect($returnurl);
}
if (get_string_manager()->string_exists('pluginname', 'editor_'.$editor)) {
$strplugin = get_string('pluginname', 'editor_'.$editor);
} else {
$strplugin = $editor;
}

echo $PAGE->set_title($strplugin);
echo $OUTPUT->header();

if (!$confirm) {
echo $OUTPUT->heading(get_string('editors', 'core_editor'));

$deleteurl = new moodle_url('/admin/editors.php', array('action'=>'uninstall', 'editor'=>$editor, 'sesskey'=>sesskey(), 'confirm'=>1));

echo $OUTPUT->confirm(get_string('editordeleteconfirm', 'core_editor', $strplugin),
$deleteurl, $returnurl);
echo $OUTPUT->footer();
die();

} else {
// Remove from enabled list.
$key = array_search($editor, $active_editors);
unset($active_editors[$key]);
set_config('texteditors', implode(',', $active_editors));

// Delete everything!!
uninstall_plugin('editor', $editor);

$a = new stdClass();
$a->name = $strplugin;
$a->directory = "$CFG->dirroot/lib/editor/$editor";
echo $OUTPUT->notification(get_string('plugindeletefiles', '', $a), 'notifysuccess');
echo $OUTPUT->continue_button($returnurl);
echo $OUTPUT->footer();
die();
}

default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions lang/en/editor.php
Expand Up @@ -52,6 +52,7 @@
$string['cut'] = 'Cut selection';
$string['cutpastemozilla'] = 'Unfortunately, you cannot currently use normal keyboard shortcuts (or even the Paste button) for pasting text into this online editor. This is because of a security feature that is built into some versions of Mozilla and Firefox browsers.<br /><br />There are three known workarounds you can try: <br /> (1) Instead of CTRL-v, use SHIFT-Insert <br /> (2) Use the Edit->Paste menu in your browser <br /> (3) Change the preferences in your browser by editing the user.js file. <br /><br />Click the OK button below for more help, or Cancel to return to the editor';
$string['delete'] = 'Delete';
$string['editordeleteconfirm'] = 'You are about to completely delete the editor plugin \'{$a}\'. This will completely delete everything in the database associated with this plugin. Are you SURE you want to continue?';
$string['editors'] = 'Text editors';
$string['editorsettings'] = 'Manage editors';
$string['enterurlfirst'] = 'You have to enter an URL first';
Expand Down
15 changes: 12 additions & 3 deletions lib/adminlib.php
Expand Up @@ -5706,6 +5706,8 @@ public function output_html($data, $query='') {
// display strings
$txt = get_strings(array('administration', 'settings', 'edit', 'name', 'enable', 'disable',
'up', 'down', 'none'));
$struninstall = get_string('uninstallplugin', 'admin');

$txt->updown = "$txt->up/$txt->down";

$editors_available = editors_get_available();
Expand All @@ -5729,8 +5731,8 @@ public function output_html($data, $query='') {
$return .= $OUTPUT->box_start('generalbox editorsui');

$table = new html_table();
$table->head = array($txt->name, $txt->enable, $txt->updown, $txt->settings);
$table->align = array('left', 'center', 'center', 'center');
$table->head = array($txt->name, $txt->enable, $txt->updown, $txt->settings, $struninstall);
$table->align = array('left', 'center', 'center', 'center', 'center');
$table->width = '90%';
$table->data = array();

Expand Down Expand Up @@ -5783,8 +5785,15 @@ public function output_html($data, $query='') {
$settings = '';
}

if ($editor === 'textarea') {
$uninstall = '';
} else {
$uurl = new moodle_url('/admin/editors.php', array('action'=>'uninstall', 'editor'=>$editor, 'sesskey'=>sesskey()));
$uninstall = html_writer::link($uurl, $struninstall);
}

// add a row to the table
$table->data[] =array($displayname, $hideshow, $updown, $settings);
$table->data[] =array($displayname, $hideshow, $updown, $settings, $uninstall);
}
$return .= html_writer::table($table);
$return .= get_string('configeditorplugins', 'editor').'<br />'.get_string('tablenosave', 'admin');
Expand Down

0 comments on commit 4f66c75

Please sign in to comment.