]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
merge to basewiki
[ikiwiki.git] / IkiWiki.pm
index 2bef2164e69aea6ae6cc5b13f6626b01f0cebc66..32ca0449fb81c4c59db6a3548f713e86e11b43bf 100644 (file)
@@ -9,7 +9,7 @@ use open qw{:utf8 :std};
 
 use vars qw{%config %links %oldlinks %oldpagemtime %pagectime %pagecase
             %renderedfiles %oldrenderedfiles %pagesources %depends %hooks
-           %forcerebuild};
+           %forcerebuild $gettext_obj};
 
 use Exporter q{import};
 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
@@ -44,7 +44,6 @@ sub defaultconfig () { #{{{
        cgiurl => '',
        historyurl => '',
        diffurl => '',
-       anonok => 0,
        rss => 0,
        atom => 0,
        discussion => 1,
@@ -66,7 +65,7 @@ sub defaultconfig () { #{{{
        setup => undef,
        adminuser => undef,
        adminemail => undef,
-       plugin => [qw{mdwn inline htmlscrubber passwordauth}],
+       plugin => [qw{mdwn inline htmlscrubber passwordauth signinedit lockedit}],
        timeformat => '%c',
        locale => undef,
        sslcookie => 0,
@@ -83,8 +82,10 @@ sub checkconfig () { #{{{
        if (defined $config{locale}) {
                eval q{use POSIX};
                error($@) if $@;
-               $ENV{LANG} = $config{locale}
-                       if POSIX::setlocale(&POSIX::LC_ALL, $config{locale});
+               if (POSIX::setlocale(&POSIX::LC_ALL, $config{locale})) {
+                       $ENV{LANG}=$config{locale};
+                       $gettext_obj=undef;
+               }
        }
 
        if ($config{w3mmode}) {
@@ -230,9 +231,10 @@ sub srcfile ($) { #{{{
        error("internal error: $file cannot be found");
 } #}}}
 
-sub readfile ($;$) { #{{{
+sub readfile ($;$$) { #{{{
        my $file=shift;
        my $binary=shift;
+       my $wantfd=shift;
 
        if (-l $file) {
                error("cannot read a symlink ($file)");
@@ -241,16 +243,18 @@ sub readfile ($;$) { #{{{
        local $/=undef;
        open (IN, $file) || error("failed to read $file: $!");
        binmode(IN) if ($binary);
+       return \*IN if $wantfd;
        my $ret=<IN>;
        close IN;
        return $ret;
 } #}}}
 
-sub writefile ($$$;$) { #{{{
+sub writefile ($$$;$$) { #{{{
        my $file=shift; # can include subdirs
        my $destdir=shift; # directory to put file in
        my $content=shift;
        my $binary=shift;
+       my $wantfd=shift;
        
        my $test=$file;
        while (length $test) {
@@ -273,6 +277,7 @@ sub writefile ($$$;$) { #{{{
        
        open (OUT, ">$destdir/$file") || error("failed to write $destdir/$file: $!");
        binmode(OUT) if ($binary);
+       return \*OUT if $wantfd;
        print OUT $content;
        close OUT;
 } #}}}
@@ -784,7 +789,6 @@ sub file_pruned ($$) { #{{{
        $file =~ m/$regexp/;
 } #}}}
 
-my $gettext_obj;
 sub gettext { #{{{
        # Only use gettext in the rare cases it's needed.
        if (exists $ENV{LANG} || exists $ENV{LC_ALL} || exists $ENV{LC_MESSAGES}) {
@@ -850,23 +854,35 @@ sub pagespec_translate ($) { #{{{
                        $code.=" match_$1(\$page, ".safequote($2).")";
                }
                else {
-                       $code.=" match_glob(\$page, ".safequote($word).")";
+                       $code.=" match_glob(\$page, ".safequote($word).", \$from)";
                }
        }
 
        return $code;
 } #}}}
 
-sub pagespec_match ($$) { #{{{
+sub pagespec_match ($$;$) { #{{{
        my $page=shift;
        my $spec=shift;
+       my $from=shift;
+       if (! defined $from){
+               $from = "";
+       }
 
        return eval pagespec_translate($spec);
 } #}}}
 
-sub match_glob ($$) { #{{{
+sub match_glob ($$$) { #{{{
        my $page=shift;
        my $glob=shift;
+       my $from=shift;
+
+       # relative matching
+       if ($glob =~ m!^\./!) {
+               $from=~s!/?[^/]+$!!;
+               $glob=~s!^\./!!;
+               $glob="$from/$glob" if length $from;
+       }
 
        # turn glob into safe regexp
        $glob=quotemeta($glob);