po: do not allow to create pages of type po
authorintrigeri <intrigeri@boum.org>
Fri, 2 Jan 2009 12:43:40 +0000 (13:43 +0100)
committerintrigeri <intrigeri@boum.org>
Fri, 2 Jan 2009 13:09:34 +0000 (14:09 +0100)
The main reason to do so is to bypass the "favor the type of linking page on
page creation" logic, which is unsuitable when a broken link is clicked on
a slave (PO) page.

Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/po.pm
doc/plugins/po.mdwn

index 61331edebf3a2c6a67fa709fb14defbf783d1d34..68fd692836964cc6ce38360a71d39a283ec66816 100644 (file)
@@ -44,6 +44,7 @@ sub import {
        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", id => "po", call => \&formbuilder);
 
        $origsubs{'bestlink'}=\&IkiWiki::bestlink;
        inject(name => "IkiWiki::bestlink", call => \&mybestlink);
@@ -452,6 +453,31 @@ sub formbuilder_setup (@) {
        $form->tmpl_param(message => $template->output);
 }
 
+# Do not allow to create pages of type po: they are automatically created.
+# The main reason to do so is to bypass the "favor the type of linking page
+# on page creation" logic, which is unsuitable when a broken link is clicked
+# on a slave (PO) page.
+sub formbuilder (@) {
+       my %params=@_;
+       my $form=$params{form};
+       my $q=$params{cgi};
+
+       return unless (defined $form->field("do") && $form->field("do") eq "create");
+
+        for my $field ($form->field) {
+               next unless "$field" eq "type";
+               if ($field->type eq 'select') {
+                       # remove po from the types list
+                       my @types = grep { $_ ne 'po' } $field->options;
+                       $field->options(\@types) if scalar @types;
+               }
+               else {
+                       # make sure the default value is not po;
+                       # does this case actually happen?
+                       debug "po(formbuilder) type field is not select - not implemented yet";
+               }
+       }
+}
 
 # ,----
 # | Injected functions
index ed740c39476b3985cba5427c0cfe1e1b8bff2495..f06fd40c6cd64384c96a4e80e02b38681ffd58d9 100644 (file)
@@ -541,13 +541,6 @@ a more complete translation than the existing one.
 Note: committing to the underlying repository is a way to bypass
 this check.
 
-Creating new pages on the web
------------------------------
-
-* Page creation initiated by clicking a broken link on a translation
-  page defaults to po as new page type. It must default to the master
-  page's type instead.
-
 Robustness tests
 ----------------