Commit bc4cc476 authored by Francois Marier's avatar Francois Marier Committed by Gerrit Code Review
Browse files

Merge "Replace links with forms for enabling/disabling plugins (bug #714967)"

parents bb0f7101 d4be7807
......@@ -40,11 +40,6 @@ define('SECTION_PLUGINNAME', $pluginname);
define('SECTION_PAGE', 'pluginconfig');
safe_require($plugintype, $pluginname);
if ($sesskey = param_alphanum('sesskey', '')) {
if ($sesskey != $USER->get('sesskey')) {
throw new UserException('Invalid sesskey');
}
}
$enable = param_integer('enable', 0);
$disable = param_integer('disable', 0);
......@@ -53,23 +48,8 @@ if ($disable && !call_static_method(generate_class_name($plugintype, $pluginname
}
if ($enable || $disable) {
if ($plugintype == 'blocktype') {
if (strpos($pluginname, '/') !== false) {
list($artefact, $pluginname) = split('/', $pluginname);
// Don't enable blocktypes unless the artefact plugin that provides them is also enabled
if ($enable && !get_field('artefact_installed', 'active', 'name', $artefact)) {
$SESSION->add_error_msg(get_string('pluginnotenabled', 'mahara', $artefact));
redirect('/admin/extensions/plugins.php');
}
}
}
else if ($plugintype == 'artefact' && $disable) {
// Disable all the artefact's blocktypes too
set_field('blocktype_installed', 'active', 0, 'artefactplugin', $pluginname);
}
set_field($plugintype . '_installed', 'active', $enable, 'name', $pluginname);
$SESSION->add_ok_msg(get_string('plugin' . (($enable) ? 'enabled' : 'disabled')));
redirect('/admin/extensions/plugins.php');
require_once(get_config('libroot') . 'upgrade.php');
activate_plugin_form($plugintype, get_record($plugintype . '_installed', 'name', $pluginname));
}
if ($plugintype == 'artefact') {
......
......@@ -66,6 +66,9 @@ foreach (array_keys($plugins) as $plugin) {
'active' => $i->active,
'disableable' => call_static_method(generate_class_name($plugin, $key), 'can_be_disabled'),
);
if ($plugins[$plugin]['installed'][$key]['disableable']) {
$plugins[$plugin]['installed'][$key]['activateform'] = activate_plugin_form($plugin, $i);
}
if ($plugin == 'artefact') {
$plugins[$plugin]['installed'][$key]['types'] = array();
safe_require('artefact', $key);
......
......@@ -1072,3 +1072,47 @@ function set_antispam_defaults() {
set_config('spamhaus', 0);
set_config('surbl', 0);
}
function activate_plugin_form($plugintype, $plugin) {
return pieform(array(
'name' => 'activate_' . $plugintype . '_' . $plugin->name,
'renderer' => 'oneline',
'elementclasses' => false,
'successcallback' => 'activate_plugin_submit',
'class' => 'oneline inline',
'jsform' => false,
'action' => get_config('wwwroot') . 'admin/extensions/pluginconfig.php',
'elements' => array(
'plugintype' => array('type' => 'hidden', 'value' => $plugintype),
'pluginname' => array('type' => 'hidden', 'value' => $plugin->name),
'disable' => array('type' => 'hidden', 'value' => $plugin->active),
'enable' => array('type' => 'hidden', 'value' => 1-$plugin->active),
'submit' => array(
'type' => 'submit',
'class' => 'linkbtn',
'value' => $plugin->active ? get_string('hide') : get_string('show')
),
),
));
}
function activate_plugin_submit(Pieform $form, $values) {
global $SESSION;
if ($values['plugintype'] == 'blocktype') {
if (strpos($values['pluginname'], '/') !== false) {
list($artefact, $values['pluginname']) = split('/', $values['pluginname']);
// Don't enable blocktypes unless the artefact plugin that provides them is also enabled
if ($values['enable'] && !get_field('artefact_installed', 'active', 'name', $artefact)) {
$SESSION->add_error_msg(get_string('pluginnotenabled', 'mahara', $artefact));
redirect('/admin/extensions/plugins.php');
}
}
}
else if ($values['plugintype'] == 'artefact' && $values['disable']) {
// Disable all the artefact's blocktypes too
set_field('blocktype_installed', 'active', 0, 'artefactplugin', $values['pluginname']);
}
set_field($values['plugintype'] . '_installed', 'active', $values['enable'], 'name', $values['pluginname']);
$SESSION->add_ok_msg(get_string('plugin' . (($values['enable']) ? 'enabled' : 'disabled')));
redirect('/admin/extensions/plugins.php');
}
......@@ -112,6 +112,7 @@ p {
.nowrap {
white-space: nowrap;
}
form.oneline.inline div,
.inline {
display: inline;
}
......@@ -537,6 +538,9 @@ span.btn a.icon, a span.icon {
border: 0;
cursor: pointer;
color: #0000ee;
background: none;
padding: 0;
font-size: 100%;
}
/* bolding some buttons */
#editgroup #editgroup_submit,
......
......@@ -14,11 +14,7 @@
{foreach from=$installed key='plugin' item='data'}
<li id="{$plugintype}.{$plugin}">{$plugin}
{if $data.disableable}
{if $data.active}
[ <a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}&amp;disable=1&amp;sesskey={$SESSKEY}">{str tag='hide'}</a>
{else}
[ <a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}&amp;enable=1&amp;sesskey={$SESSKEY}">{str tag='show'}</a>
{/if}
[ {$data.activateform|safe}
{/if}
{if $data.config}
{if !$data.disableable} [ {else} | {/if}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment