aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-08-02 16:40:46 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-08-02 16:41:37 -0400
commit4708aeceb3ec518a00069ad7a112ab0a5596275c (patch)
tree6d04be0c5f2733162a0a9d28ba5432b15e00e775 /IkiWiki/Plugin
parentb0f4767448670ca53aa84e1748a887c7bfccd4f3 (diff)
downloadikiwiki-4708aeceb3ec518a00069ad7a112ab0a5596275c.tar
ikiwiki-4708aeceb3ec518a00069ad7a112ab0a5596275c.tar.gz
websetup form display done
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/anonok.pm2
-rw-r--r--IkiWiki/Plugin/attachment.pm2
-rw-r--r--IkiWiki/Plugin/lockedit.pm2
-rw-r--r--IkiWiki/Plugin/websetup.pm133
4 files changed, 122 insertions, 17 deletions
diff --git a/IkiWiki/Plugin/anonok.pm b/IkiWiki/Plugin/anonok.pm
index d5e409117..9d21fe367 100644
--- a/IkiWiki/Plugin/anonok.pm
+++ b/IkiWiki/Plugin/anonok.pm
@@ -13,7 +13,7 @@ sub import { #{{{
sub getsetup () { #{{{
return
anonok_pagespec => {
- type => "string",
+ type => "pagespec",
example => "*/discussion",
description => "PageSpec to limit which pages anonymous users can edit",
description_html => htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm
index bd21ed1ed..27f984c29 100644
--- a/IkiWiki/Plugin/attachment.pm
+++ b/IkiWiki/Plugin/attachment.pm
@@ -22,7 +22,7 @@ sub getsetup () { #{{{
rebuild => 0,
},
allowed_attachments => {
- type => "string",
+ type => "pagespec",
example => "mimetype(image/*) and maxsize(50kb)",
description => "enhanced PageSpec specifying what attachments are allowed",
description_html => htmllink("", "",
diff --git a/IkiWiki/Plugin/lockedit.pm b/IkiWiki/Plugin/lockedit.pm
index 4e1b4f878..93a525677 100644
--- a/IkiWiki/Plugin/lockedit.pm
+++ b/IkiWiki/Plugin/lockedit.pm
@@ -15,7 +15,7 @@ sub import { #{{{
sub getsetup () { #{{{
return
locked_pages => {
- type => "string",
+ type => "pagespec",
example => "!*/Discussion",
description => "PageSpec controlling which pages are locked",
description_html => htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).
diff --git a/IkiWiki/Plugin/websetup.pm b/IkiWiki/Plugin/websetup.pm
index a30475977..0a0d4480f 100644
--- a/IkiWiki/Plugin/websetup.pm
+++ b/IkiWiki/Plugin/websetup.pm
@@ -5,46 +5,114 @@ use warnings;
use strict;
use IkiWiki 2.00;
+my @rcs_plugins=(qw{git svn bzr mercurial monotone tla norcs});
+my @default_force_plugins=(qw{amazon_s3});
+
sub import { #{{{
- hook(type => "sessioncgi", id => "websetup",
- call => \&sessioncgi);
- hook(type => "formbuilder_setup", id => "websetup",
+ hook(type => "checkconfig", id => "websetup", call => \&checkconfig);
+ hook(type => "getsetup", id => "websetup", call => \&getsetup);
+ hook(type => "sessioncgi", id => "websetup", call => \&sessioncgi);
+ hook(type => "formbuilder_setup", id => "websetup",
call => \&formbuilder_setup);
} # }}}
-sub addfields ($$@) {
+sub getsetup () { #{{{
+ return
+ websetup_force_plugins => {
+ type => "string",
+ example => \@default_force_plugins,
+ description => "list of plugins that cannot be enabled/disabled via the web interface",
+ safe => 0,
+ rebuild => 0,
+ },
+} #}}}
+
+sub checkconfig () { #{{{
+ if (! exists $config{websetup_force_plugins}) {
+ $config{websetup_force_plugins}=\@default_force_plugins;
+ }
+} #}}}
+
+sub formatexample ($) { #{{{
+ my $example=shift;
+
+ if (defined $example && ! ref $example && length $example) {
+ return "<br/ ><small>Example: <tt>$example</tt></small>";
+ }
+ else {
+ return "";
+ }
+} #}}}
+
+sub showfields ($$$@) { #{{{
my $form=shift;
- my $section=shift;
+ my $plugin=shift;
+ my $enabled=shift;
+ my @show;
while (@_) {
my $key=shift;
my %info=%{shift()};
- next if ! $info{safe} || $info{type} eq "internal";
+ # skip complex, unsafe, or internal settings
+ next if ref $config{$key} || ! $info{safe} || $info{type} eq "internal";
+ # these are handled specially, so don't show
+ next if $key eq 'add_plugins' || $key eq 'disable_plugins';
+
+ push @show, $key, \%info;
+ }
- my $description=exists $info{description_html} ? $info{description_html} : $info{description};
+ return 0 unless @show;
- my $value=$config{$key};
- # multiple plugins can have the same key
- my $name=$section.".".$key;
+ my $section=defined $plugin ? $plugin." ".gettext("plugin") : gettext("main");
+
+ if (defined $plugin) {
+ if (! showplugintoggle($form, $plugin, $enabled, $section) && ! $enabled) {
+ # plugin not enabled and cannot be, so skip showing
+ # its configuration
+ return 0;
+ }
+ }
+
+ while (@show) {
+ my $key=shift @show;
+ my %info=%{shift @show};
+ my $description=exists $info{description_html} ? $info{description_html} : $info{description};
+ my $value=$config{$key};
+ # multiple plugins can have the same field
+ my $name=defined $plugin ? $plugin.".".$key : $key;
+
if ($info{type} eq "string") {
$form->field(
name => $name,
label => $description,
- comment => exists $info{example} && length $info{example} && $info{example} ne $value ? "<br/ ><small>Example: <tt>$info{example}</tt></small>" : "",
+ comment => defined $value && length $value ? "" : formatexample($info{example}),
type => "text",
value => $value,
size => 60,
fieldset => $section,
);
}
+ elsif ($info{type} eq "pagespec") {
+ $form->field(
+ name => $name,
+ label => $description,
+ comment => formatexample($info{example}),
+ type => "text",
+ value => $value,
+ size => 60,
+ validate => \&IkiWiki::pagespec_valid,
+ fieldset => $section,
+ );
+ }
elsif ($info{type} eq "integer") {
$form->field(
name => $name,
label => $description,
type => "text",
value => $value,
+ size => 5,
validate => '/^[0-9]+$/',
fieldset => $section,
);
@@ -60,7 +128,29 @@ sub addfields ($$@) {
);
}
}
-}
+
+ return 1;
+} #}}}
+
+sub showplugintoggle ($$$$) { #{{{
+ my $form=shift;
+ my $plugin=shift;
+ my $enabled=shift;
+ my $section=shift;
+
+ return 0 if (grep { $_ eq $plugin } @{$config{websetup_force_plugins}}, @rcs_plugins);
+
+ $form->field(
+ name => "enable.$plugin",
+ label => "",
+ type => "checkbox",
+ options => [ [ 1 => sprintf(gettext("enable %s?"), $plugin) ] ],
+ value => $enabled,
+ fieldset => $section,
+ );
+
+ return 1;
+} #}}}
sub showform ($$) { #{{{
my $cgi=shift;
@@ -81,6 +171,7 @@ sub showform ($$) { #{{{
charset => "utf-8",
method => 'POST',
javascript => 0,
+ reset => 1,
params => $cgi,
action => $config{cgiurl},
template => {type => 'div'},
@@ -97,14 +188,28 @@ sub showform ($$) { #{{{
$form->field(name => "do", type => "hidden", value => "setup",
force => 1);
- addfields($form, gettext("main"), IkiWiki::getsetup());
+ showfields($form, undef, undef, IkiWiki::getsetup());
+
+ # record all currently enabled plugins before all are loaded
+ my %enabled_plugins=%IkiWiki::loaded_plugins;
+
+ # per-plugin setup
require IkiWiki::Setup;
+ my %plugins=map { $_ => 1 } IkiWiki::listplugins();
foreach my $pair (IkiWiki::Setup::getsetup()) {
my $plugin=$pair->[0];
my $setup=$pair->[1];
- addfields($form, $plugin." ".gettext("plugin"), @{$setup});
+
+ # skip all rcs plugins except for the one in use
+ next if $plugin ne $config{rcs} && grep { $_ eq $plugin } @rcs_plugins;
+
+ delete $plugins{$plugin} if showfields($form, $plugin, $enabled_plugins{$plugin}, @{$setup});
}
+ # list all remaining plugins (with no setup options) at the end
+ showplugintoggle($form, $_, $enabled_plugins{$_}, gettext("other plugins"))
+ foreach sort keys %plugins;
+
if ($form->submitted eq "Cancel") {
IkiWiki::redirect($cgi, $config{url});
return;