]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/po.pm
avoid standalone -e or foo syntax
[ikiwiki.git] / IkiWiki / Plugin / po.pm
index f826f9503805a55da1548a1f1d124315ee0ddb06..be7a28722845ab099a09a8108f4af0b1c0ad23c0 100644 (file)
@@ -10,6 +10,16 @@ use warnings;
 use strict;
 use IkiWiki 3.00;
 use Encode;
+BEGIN {
+       eval 'use Locale::Po4a::Common qw(nowrapi18n)';
+       if ($@) {
+               warning(sprintf(gettext('%s is too old, can not disable %s; '.
+                                       'a denial of service can thus be '.
+                                       'triggered by malicious content'),
+                               'Locale::Po4a', 'Text::WrapI18N'));
+               eval 'use Locale::Po4a::Common';
+       }
+}
 use Locale::Po4a::Chooser;
 use Locale::Po4a::Po;
 use File::Basename;
@@ -39,7 +49,7 @@ sub import {
        hook(type => "rename", id => "po", call => \&renamepages, first => 1);
        hook(type => "delete", id => "po", call => \&mydelete);
        hook(type => "change", id => "po", call => \&change);
-       hook(type => "cansave", id => "po", call => \&cansave);
+       hook(type => "checkcontent", id => "po", call => \&checkcontent);
        hook(type => "canremove", id => "po", call => \&canremove);
        hook(type => "canrename", id => "po", call => \&canrename);
        hook(type => "editcontent", id => "po", call => \&editcontent);
@@ -426,11 +436,11 @@ sub change(@) {
        }
 }
 
-sub cansave ($$$$) {
-       my ($page, $content, $cgi, $session) = (shift, shift, shift, shift);
+sub checkcontent (@) {
+       my %params=@_;
 
-       if (istranslation($page)) {
-               my $res = isvalidpo($content);
+       if (istranslation($params{page})) {
+               my $res = isvalidpo($params{content});
                if ($res) {
                        return undef;
                }
@@ -841,9 +851,9 @@ sub refreshpofiles ($@) {
        my @pofiles=@_;
 
        my $potfile=potfile($masterfile);
-       (-e $potfile)
-               or error("po(refreshpofiles) ".sprintf(gettext("POT file (%s) does not exist"),
-                                                      $potfile));
+       if (! -e $potfile) {
+               error("po(refreshpofiles) ".sprintf(gettext("POT file (%s) does not exist"), $potfile));
+       }
 
        foreach my $pofile (@pofiles) {
                IkiWiki::prep_writefile(basename($pofile),dirname($pofile));