po(formbuilder_setup): remove the rename/remove buttons on slave pages
authorintrigeri <intrigeri@boum.org>
Fri, 2 Jan 2009 14:50:47 +0000 (15:50 +0100)
committerintrigeri <intrigeri@boum.org>
Fri, 2 Jan 2009 15:02:25 +0000 (16:02 +0100)
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 <intrigeri@boum.org>
IkiWiki/Plugin/po.pm
doc/plugins/po.mdwn

index 80b8749390f63c7412b063098061e69f03aeeab0..ff73a14e6c62e1c05b64946e7277f0fe8883d09d 100644 (file)
@@ -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.
index aced3799841e39e9e348f94b309623da11e34bcd..3822c05399c2950663eb038afbf18aece33d0a43 100644 (file)
@@ -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.