From fae3cef41a55dace8545429c0139d01b93c69307 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Fri, 2 Jan 2009 15:50:47 +0100 Subject: po(formbuilder_setup): remove the rename/remove buttons on slave pages This has to be done after the rename/remove plugins have added their buttons, so we set this hook to be run last. The canrename/canremove hooks already ensure this is forbidden at the backend level, so this is only UI sugar. Signed-off-by: intrigeri --- IkiWiki/Plugin/po.pm | 30 +++++++++++++++++++++++++----- doc/plugins/po.mdwn | 3 --- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 80b874939..ff73a14e6 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -43,7 +43,7 @@ sub import { hook(type => "canremove", id => "po", call => \&canremove); hook(type => "canrename", id => "po", call => \&canrename); hook(type => "editcontent", id => "po", call => \&editcontent); - hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup); + hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup, last => 1); hook(type => "formbuilder", id => "po", call => \&formbuilder); $origsubs{'bestlink'}=\&IkiWiki::bestlink; @@ -447,11 +447,31 @@ sub formbuilder_setup (@) { my $form=$params{form}; my $q=$params{cgi}; - return unless (defined $form->field("do") && $form->field("do") eq "create"); + return unless defined $form->field("do"); - my $template=template("pocreatepage.tmpl"); - $template->param(LANG => $config{po_master_language}{name}); - $form->tmpl_param(message => $template->output); + if ($form->field("do") eq "create") { + # Warn the user: new pages must be written in master language. + my $template=template("pocreatepage.tmpl"); + $template->param(LANG => $config{po_master_language}{name}); + $form->tmpl_param(message => $template->output); + } + elsif ($form->field("do") eq "edit") { + # Remove the rename/remove buttons on slave pages. + # This has to be done after the rename/remove plugins have added + # their buttons, which is why this hook must be run last. + # The canrename/canremove hooks already ensure this is forbidden + # at the backend level, so this is only UI sugar. + if (istranslation($form->field("page"))) { + map { + for (my $i = 0; $i < @{$params{buttons}}; $i++) { + if (@{$params{buttons}}[$i] eq $_) { + delete @{$params{buttons}}[$i]; + last; + } + } + } qw(Rename Remove); + } + } } # Do not allow to create pages of type po: they are automatically created. diff --git a/doc/plugins/po.mdwn b/doc/plugins/po.mdwn index aced37998..3822c0539 100644 --- a/doc/plugins/po.mdwn +++ b/doc/plugins/po.mdwn @@ -576,6 +576,3 @@ Misc * Can the form validation system be used instead of creating the `cansave` hook? -* Use the formbuilder_setup hook to remove the rename/remove buttons - on slave edit pages. The canrename/canremove hook ensure this is - forbidden at the backend level, and this change would improve the UI. -- cgit v1.2.3