Skip to content

Commit

Permalink
[#618 state:resolved] Major enhancements to plugin listing screen and…
Browse files Browse the repository at this point in the history
… numerous bugs fixed.

* Fixed bug in which table selection was not happening properly. With this change you can select rows, or ALL rows in batch, or use any of the various table navigation hot keys.
* Plugins can now be enabled and disabled properly.
* Removed obsolete javascript methods.
* Numerous changes were made to MT.pm and fixes to the init_plugins_core method to properly initialize plugins, in particular disabled plugins which don't typically have a lot of metadata stored about them.
* Added feature by which an attempt is made to read the config.yaml of disabled plugins so that their proper name can be displayed in the "Disabled Plugins" table as opposed to the more inscrutable plugin signature.

I also made changes to the names of screens and the nav:

* Renamed plugin listing screen since "Packs" are not listed here.
* Renamed side nav to be congruent with name of plugin listing screen.

Tickets will be logged for the following:

TODO - add the global Plugin Switch to turn off plugins globally.
TODO - rename page to Installed Plugins (since packs are not listed)
TODO - add shortvcut links to plugin directory and a quick way to edit plugin preferences
  • Loading branch information
byrnereese authored and jayallen committed Dec 10, 2010
1 parent 72b19f7 commit 1d687ed
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 135 deletions.
15 changes: 7 additions & 8 deletions lib/MT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,6 @@ sub init_addons {
my $cfg = $mt->config;
my $addons = $mt->find_addons('pack');

# print STDERR Dumper({addons => $addons})."\n";
return $mt->_init_plugins_core( {}, 1, $addons );
}

Expand All @@ -1442,7 +1441,6 @@ sub init_plugins {
my $PluginSwitch = $cfg->PluginSwitch || {};
my $plugins = $mt->find_addons('plugin');

# print STDERR Dumper({plugins => $plugins})."\n";
return $mt->_init_plugins_core( $PluginSwitch, $use_plugins, $plugins );
}

Expand All @@ -1462,7 +1460,7 @@ sub _init_plugins_core {
my ( $plugin, $sig ) = @_;
die "Bad plugin filename '$plugin'"
if ( $plugin !~ /^([-\\\/\@\:\w\.\s~]+)$/ );
local $plugin_sig = $sig;
local $plugin_sig = $plugin->{sig};
local $plugin_registry = {};
$plugin = $1;
if (
Expand Down Expand Up @@ -1533,13 +1531,13 @@ sub _init_plugins_core {
$pclass eq 'MT::Plugin'
&& (
!$use_plugins
|| ( exists $PluginSwitch->{ $plugin->{dir} }
&& !$PluginSwitch->{ $plugin->{dir} } )
|| ( exists $PluginSwitch->{ $plugin->{sig} }
&& !$PluginSwitch->{ $plugin->{sig} } )
)
)
{
$Plugins{ $plugin->{dir} }{full_path} = $plugin->{path};
$Plugins{ $plugin->{dir} }{enabled} = 0;
$Plugins{ $plugin->{sig} }{full_path} = File::Spec->catfile($plugin->{path},$plugin->{file});
$Plugins{ $plugin->{sig} }{enabled} = 0;
next;
}

Expand Down Expand Up @@ -1788,7 +1786,7 @@ sub scan_directory_for_addons {
my $plugin_file
= File::Spec->catfile( $plugin_full_path, $file );
if ( -f $plugin_file ) {

my $sig = File::Spec->catfile( $plugin_dir, $file );
# Plugin is a file, add it to list for processing
push @{ $plugins{$type} }, {
label => $label, # used only by packs
Expand All @@ -1797,6 +1795,7 @@ sub scan_directory_for_addons {
base => $plugin_full_path,
dir => $plugin_dir,
file => $file,
sig => $sig,

# TODO: remove following comment if app is stable
# Changed from $plugin_file because load_tmpl was failing
Expand Down
2 changes: 2 additions & 0 deletions lib/MT/App/CMS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ sub core_methods {
'handle_junk' => "${pkg}Comment::handle_junk",
'not_junk' => "${pkg}Comment::not_junk",

'switch_plugins' => "${pkg}Plugin::switch",

'ping' => "${pkg}Entry::send_pings",
'rebuild_phase' => "${pkg}Blog::rebuild_phase",
'rebuild' => "${pkg}Blog::rebuild_pages",
Expand Down
53 changes: 39 additions & 14 deletions lib/MT/CMS/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@ package MT::CMS::Plugin;
use strict;
use MT::Util qw( remove_html );

# plugin enablement/disablement
sub switch {
my ($app) = @_;
$app->validate_magic or return;
return unless _can_config_plugins($app);
my $cfg = $app->config;

my $PluginSwitch = $cfg->PluginSwitch || {};

my @plugins = $app->query->param('id');
for my $sig (@plugins) {
if ( exists $MT::Plugins{$sig} ) {
my $state;
if ( exists $PluginSwitch->{$sig} && !$PluginSwitch->{$sig} ) {
$state = "1";
} else {
$state = "0";
}
$cfg->PluginSwitch( $sig.'='.$state, 1 );
}
}
$cfg->save_config;

$app->add_return_arg( 'switched' => 1 );
$app->call_return;
}

sub list_plugins {
my $app = shift;
my $q = $app->query;
Expand Down Expand Up @@ -413,29 +440,27 @@ sub build_plugin_table {
# don't list non-configurable plugins for blog scope...
next if $scope ne 'system';

# Removed for Melody - obsolete
# if ( $last_fld ne $fld ) {
# $row = {
# plugin_sig => $plugin_sig,
# plugin_folder => $folder,
# plugin_set => $fld ? $folder_counts{$fld} > 1 : 0,
# plugin_error => $profile->{error},
# };
# push @$enabled_plugins, $row;
# $last_fld = $fld;
# $next_is_first = 1;
# }

my $yaml;
if (!$profile->{enabled} && -f $profile->{full_path}) {
require YAML::Tiny;
$yaml = eval { YAML::Tiny->read($profile->{full_path}) };
}
# no registered plugin objects--
$row = {
first => $next_is_first,
plugin_major => $fld ? 0 : 1,
plugin_icon => $icon,
plugin_name => $plugin_sig,
plugin_sig => $plugin_sig,
plugin_error => $profile->{error},
plugin_disabled => $profile->{enabled} ? 0 : 1,
plugin_id => $id,
$yaml ? (
plugin_name => $yaml->[0]->{name},
plugin_version => $yaml->[0]->{version},
# plugin_desc => MT->translate( $yaml->[0]->{description} ),
) : (
plugin_name => $plugin_sig,
),
};
push @enabled_plugins, $row if $profile->{enabled};
push @disabled_plugins, $row if !$profile->{enabled};
Expand Down
2 changes: 1 addition & 1 deletion tmpl/cms/include/sysinfo_content_nav.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<li<mt:if name="system-information"> class="active"</mt:if>><a href="<$mt:var name="mt_url"$>?__mode=system_check&amp;blog_id=<$mt:var name="blog_id"$>"><b><__trans phrase="System Information"></b></a></li>
</mt:unless>
</mt:if>
<li<mt:if name="plugins"> class="active"</mt:if>><a href="<$mt:var name="mt_url"$>?__mode=list_plugin"><b><__trans phrase="Plugins &amp; Addons"></b></a></li>
<li<mt:if name="plugins"> class="active"</mt:if>><a href="<$mt:var name="mt_url"$>?__mode=list_plugin"><b><__trans phrase="Installed Plugins"></b></a></li>
<li<mt:if name="resources"> class="active"</mt:if>><a href="<$mt:var name="mt_url"$>?__mode=resources"><b><__trans phrase="Resources"></b></a></li>
<li<mt:if name="sanity"> class="active"</mt:if>><a href="<$mt:var name="mt_url"$>?__mode=sanity_check"><b><__trans phrase="Sanity Check"></b></a></li>
</ul>
148 changes: 36 additions & 112 deletions tmpl/cms/list_plugin.tmpl
Original file line number Diff line number Diff line change
@@ -1,132 +1,56 @@
<$mt:setvar name="plugins" value="1"$>
<$mt:setvar name="page_title" value="<__trans phrase="Installed Add-Ons &amp; Plugins">"$>
<$mt:setvar name="page_title" value="<__trans phrase="Installed Plugins">"$>
<$mt:setvar name="position_actions_top" value="1"$>
<$mt:setvar name="system-plugin-settings" value="1"$>
<mt:setvarblock name="content_nav">
<mt:include name="include/sysinfo_content_nav.tmpl">
</mt:setvarblock>

<mt:setvarblock name="plugins"> class="active"</mt:setvarblock>
<MTSetVarBlock name="system_msg">
<mt:if name="blog_id">
<mt:if name="saved">
<mtapp:statusmsg
id="saved"
class="success">
<__trans phrase="Your plugin settings have been saved.">
</mtapp:statusmsg>
</mt:if>
<mt:if name="reset">
<mtapp:statusmsg
<mt:setvarblock name="system_msg">
<mt:if name="saved">
<mtapp:statusmsg
id="saved"
class="success">
<__trans phrase="Your plugin settings have been saved.">
</mtapp:statusmsg>
</mt:if>
<mt:if name="reset">
<mtapp:statusmsg
id="reset"
class="success">
<__trans phrase="Your plugin settings have been reset.">
</mtapp:statusmsg>
</mt:if>
<mt:if name="switched">
<mt:if name="needs_restart">
<mtapp:statusmsg
id="switched"
class="success">
<__trans phrase="Your plugins have been reconfigured. Since you're running in a persistent application environment, you will need to restart your web server for these changes to take effect.">
</mtapp:statusmsg>
<mt:else>
<mtapp:statusmsg
id="switched"
class="success">
<__trans phrase="Your plugins have been reconfigured.">
</mtapp:statusmsg>
</mt:if>
</mt:if>
<mt:else>
<mt:if name="saved">
<mtapp:statusmsg
id="saved"
</mtapp:statusmsg>
</mt:if>
<mt:if name="switched">
<mt:if name="needs_restart">
<mtapp:statusmsg
id="switched"
class="success">
<__trans phrase="Your plugin settings have been saved.">
<__trans phrase="Your plugins have been reconfigured. Since you're running in a persistent application environment, you will need to restart your web server for these changes to take effect.">
</mtapp:statusmsg>
</mt:if>
<mt:if name="reset">
<mtapp:statusmsg
id="reset"
<mt:else>
<mtapp:statusmsg
id="switched"
class="success">
<__trans phrase="Your plugin settings have been reset.">
</mtapp:statusmsg>
</mt:if>
<mt:if name="switched">
<mt:if name="needs_restart">
<mtapp:statusmsg
id="switched"
class="success">
<__trans phrase="Your plugins have been reconfigured. Since you're running in a persistent application environment, you will need to restart your web server for these changes to take effect.">
</mtapp:statusmsg>
<mt:else>
<mtapp:statusmsg
id="switched"
class="success">
<__trans phrase="Your plugins have been reconfigured.">
</mtapp:statusmsg>
</mt:if>
</mt:if>
</mt:if>
<__trans phrase="Your plugins have been reconfigured.">
</mtapp:statusmsg>
</mt:if>
</mt:if>
</MTSetVarBlock>
<mt:setvarblock name="html_head" append="1">
<script type="text/javascript">
/* <![CDATA[ */
var last_shown;
<mt:if name="can_config">
function resetPlugin(f) {
if (confirm("<__trans phrase="Are you sure you want to reset the settings for this plugin?" escape="js">")) {
f['__mode'].value = 'reset_plugin_config';
f.submit();
}
}

function activatePlugin(flag, plugin_sig) {
var question;
if (flag == 0) {
if (plugin_sig == '*') {
question = '<__trans phrase="Are you sure you want to disable plugin functionality?" escape="js">';
} else {
question = '<__trans phrase="Disable this plugin?" escape="js">';
}
} else {
if (plugin_sig == '*') {
question = '<__trans phrase="Are you sure you want to enable plugin functionality? (This will re-enable any plugins that were not individually disabled.)" escape="js">';
} else {
question = '<__trans phrase="Enable this plugin?" escape="js">';
}
}
if (confirm(question)) {
var f = getByID("plugin_control");
f['plugin_sig'].value = plugin_sig;
f['state'].value = flag == 0 ? 'off' : 'on';
f.submit();
}
return false;
};
function togglePlugin(plugin_id) {
if (last_shown && last_shown == plugin_id) {
if (DOM.hasClassName('plugin-' + plugin_id, 'plugin-expanded')) {
DOM.removeClassName('plugin-' + plugin_id, 'plugin-expanded');
DOM.removeClassName(DOM.getFirstAncestorByClassName(DOM.getElement('plugin-' + plugin_id), 'plugin-group'), 'plugin-group-expanded')
} else {
DOM.addClassName('plugin-' + plugin_id, 'plugin-expanded');
DOM.addClassName(DOM.getFirstAncestorByClassName(DOM.getElement('plugin-' + plugin_id), 'plugin-group'), 'plugin-group-expanded')
}
} else if (last_shown) {
DOM.removeClassName('plugin-' + last_shown, 'plugin-expanded');
DOM.removeClassName(DOM.getFirstAncestorByClassName(DOM.getElement('plugin-' + last_shown), 'plugin-group'), 'plugin-group-expanded')
DOM.addClassName('plugin-' + plugin_id, 'plugin-expanded');
DOM.addClassName(DOM.getFirstAncestorByClassName(DOM.getElement('plugin-' + plugin_id), 'plugin-group'), 'plugin-group-expanded')
} else {
DOM.addClassName('plugin-' + plugin_id, 'plugin-expanded');
DOM.addClassName(DOM.getFirstAncestorByClassName(DOM.getElement('plugin-' + plugin_id), 'plugin-group'), 'plugin-group-expanded')
}
last_shown = plugin_id;
}
</mt:if>
/* ]]> */
var tableSelect = [];
function init() {
tableSelect.push(new TC.TableSelect( 'enabled-plugins-table' ));
tableSelect[tableSelect.length-1].rowSelect = true;
tableSelect.push(new TC.TableSelect( 'disabled-plugins-table' ));
tableSelect[tableSelect.length-1].rowSelect = true;
}
TC.attachLoadEvent(init);
/* ]]> */
</script>
</mt:setvarblock>
<mt:include name="include/header.tmpl">
Expand Down Expand Up @@ -161,7 +85,7 @@

<mt:setvarblock name="action_buttons">
<a href="javascript:void(0)"
onclick="doForMarkedInThisWindow(getByID('enabled-plugins-form'), '<__trans phrase="plugin" escape="js">', '<__trans phrase="plugins" escape="js">', 'id', 'disable_item', {}, '<__trans phrase="to publish" escape="js">'); return false;"
onclick="doForMarkedInThisWindow(getByID('enabled-plugins-form'), '<__trans phrase="plugin" escape="js">', '<__trans phrase="plugins" escape="js">', 'id', 'switch_plugins', {}, '<__trans phrase="to publish" escape="js">'); return false;"
accesskey="a"
title="<__trans phrase="Disable selected plugins (a)">"
><__trans phrase="Disable"></a>
Expand All @@ -171,7 +95,7 @@

<mt:setvarblock name="action_buttons">
<a href="javascript:void(0)"
onclick="doForMarkedInThisWindow(getByID('disabled-plugins-form'), '<__trans phrase="plugin" escape="js">', '<__trans phrase="plugins" escape="js">', 'id', 'enable_item', {}, '<__trans phrase="to publish" escape="js">'); return false;"
onclick="doForMarkedInThisWindow(getByID('disabled-plugins-form'), '<__trans phrase="plugin" escape="js">', '<__trans phrase="plugins" escape="js">', 'id', 'switch_plugins', {}, '<__trans phrase="to publish" escape="js">'); return false;"
accesskey="a"
title="<__trans phrase="Enable selected plugins (a)">"
><__trans phrase="Enable"></a>
Expand Down

0 comments on commit 1d687ed

Please sign in to comment.