+sub formbuilder_setup (@) {
+ my %params=@_;
+ my $form=$params{form};
+ my $q=$params{cgi};
+
+ return unless defined $form->field("do");
+
+ 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);
+ }
+ }
+}
+
+sub formbuilder (@) {
+ my %params=@_;
+ my $form=$params{form};
+ my $q=$params{cgi};
+
+ return unless defined $form->field("do");
+
+ # 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.
+ # This cannot be done in the formbuilder_setup hook as the list of types is
+ # computed later.
+ if ($form->field("do") eq "create") {
+ foreach my $field ($form->field) {
+ next unless "$field" eq "type";
+ next unless $field->type eq 'select';
+ my $orig_value = $field->value;
+ # remove po from the list of types
+ my @types = grep { $_->[0] ne 'po' } $field->options;
+ $field->options(\@types) if @types;
+ # favor the type of linking page's masterpage
+ if ($orig_value eq 'po') {
+ my ($from, $type);
+ if (defined $form->field('from')) {
+ ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
+ $from = masterpage($from);
+ }
+ if (defined $from && exists $pagesources{$from}) {
+ $type=pagetype($pagesources{$from});
+ }
+ $type=$config{default_pageext} unless defined $type;
+ $field->value($type) ;
+ }
+ }
+ }
+}