]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/po.pm
po: fix interdiction to create pages of type po
[ikiwiki.git] / IkiWiki / Plugin / po.pm
index 61f8db3283a5cdffaf7743354628eeda1ec059ea..b9f59f3e8c84bebcc7c79829f03c48036bd4d3e2 100644 (file)
@@ -51,8 +51,6 @@ sub import {
        hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup, last => 1);
        hook(type => "formbuilder", id => "po", call => \&formbuilder);
 
-       $origsubs{'bestlink'}=\&IkiWiki::bestlink;
-       inject(name => "IkiWiki::bestlink", call => \&mybestlink);
        $origsubs{'beautify_urlpath'}=\&IkiWiki::beautify_urlpath;
        inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
        $origsubs{'targetpage'}=\&IkiWiki::targetpage;
@@ -153,6 +151,10 @@ sub checkconfig () {
                warn(gettext('po_link_to=negotiated requires usedirs to be enabled, falling back to po_link_to=default'));
                $config{po_link_to}='default';
        }
+       unless ($config{po_link_to} eq 'default') {
+               $origsubs{'bestlink'}=\&IkiWiki::bestlink;
+               inject(name => "IkiWiki::bestlink", call => \&mybestlink);
+       }
 
        push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/;
 
@@ -302,6 +304,9 @@ sub pagetemplate (@) {
            && $masterpage eq "index") {
                $template->param('parentlinks' => []);
        }
+       if (ishomepage($page) && $template->query(name => "title")) {
+               $template->param(title => $config{wikiname});
+       }
 } # }}}
 
 # Add the renamed page translations to the list of to-be-renamed pages.
@@ -528,7 +533,7 @@ sub formbuilder (@) {
                        next unless "$field" eq "type";
                        if ($field->type eq 'select') {
                                # remove po from the list of types
-                               my @types = grep { $_ ne 'po' } $field->options;
+                               my @types = grep { $_->[0] ne 'po' } $field->options;
                                $field->options(\@types) if @types;
                        }
                }
@@ -540,13 +545,13 @@ sub formbuilder (@) {
 # `----
 
 # Implement po_link_to 'current' and 'negotiated' settings.
+# Not injected otherwise.
 sub mybestlink ($$) {
        my $page=shift;
        my $link=shift;
 
        my $res=$origsubs{'bestlink'}->(masterpage($page), $link);
        if (length $res
-           && ($config{po_link_to} eq "current" || $config{po_link_to} eq "negotiated")
            && istranslatable($res)
            && istranslation($page)) {
                return $res . "." . lang($page);
@@ -957,6 +962,14 @@ sub homepageurl (;$) {
        return urlto('', $page);
 }
 
+sub ishomepage ($) {
+       my $page = shift;
+
+       return 1 if $page eq 'index';
+       map { return 1 if $page eq 'index.'.$_ } keys %{$config{po_slave_languages}};
+       return undef;
+}
+
 sub deletetranslations ($) {
        my $deletedmasterfile=shift;