]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
proper spelling of viruses
[ikiwiki.git] / IkiWiki.pm
index 1a55945a83f7ec5d1f1f06da675e1eebbb4ea8f6..17e2a2a857e098e7feb10bc21fe326ee22df509e 100644 (file)
@@ -120,7 +120,7 @@ sub getsetup () { #{{{
        },
        default_plugins => {
                type => "internal",
-               default => [qw{mdwn link inline htmlscrubber passwordauth
+               default => [qw{mdwn link inline meta htmlscrubber passwordauth
                                openid signinedit lockedit conditional
                                recentchanges parentlinks editpage}],
                description => "plugins to enable by default",
@@ -403,6 +403,13 @@ sub getsetup () { #{{{
                safe => 0,
                rebuild => 0,
        },
+       wikistatedir => {
+               type => "internal",
+               default => undef,
+               description => "path to the .ikiwiki directory holding ikiwiki state",
+               safe => 0,
+               rebuild => 0,
+       },
        setupfile => {
                type => "internal",
                default => undef,
@@ -411,7 +418,7 @@ sub getsetup () { #{{{
                rebuild => 0,
        },
        allow_symlinks_before_srcdir => {
-               type => "string",
+               type => "boolean",
                default => 0,
                description => "allow symlinks in the path leading to the srcdir (potentially insecure)",
                safe => 0,
@@ -467,7 +474,7 @@ sub checkconfig () { #{{{
        }
        
        $config{wikistatedir}="$config{srcdir}/.ikiwiki"
-               unless exists $config{wikistatedir};
+               unless exists $config{wikistatedir} && defined $config{wikistatedir};
 
        if (defined $config{umask}) {
                umask(possibly_foolish_untaint($config{umask}));
@@ -714,6 +721,10 @@ sub readfile ($;$$) { #{{{
        binmode($in) if ($binary);
        return \*$in if $wantfd;
        my $ret=<$in>;
+       # check for invalid utf-8, and toss it back to avoid crashes
+       if (! utf8::valid($ret)) {
+               $ret=encode_utf8($ret);
+       }
        close $in || error("failed to read $file: $!");
        return $ret;
 } #}}}
@@ -931,9 +942,9 @@ sub beautify_urlpath ($) { #{{{
                $url =~ s!/index.$config{htmlext}$!/!;
        }
 
-       # Ensure url is not an empty link, and
-       # if it's relative, make that explicit to avoid colon confusion.
-       if ($url !~ /^\//) {
+       # Ensure url is not an empty link, and if necessary,
+       # add ./ to avoid colon confusion.
+       if ($url !~ /^\// && $url !~ /^\.\.\//) {
                $url="./$url";
        }
 
@@ -1273,8 +1284,7 @@ sub indexlink () { #{{{
 
 my $wikilock;
 
-sub lockwiki (;$) { #{{{
-       my $wait=@_ ? shift : 1;
+sub lockwiki () { #{{{
        # Take an exclusive lock on the wiki to prevent multiple concurrent
        # run issues. The lock will be dropped on program exit.
        if (! -d $config{wikistatedir}) {
@@ -1282,25 +1292,14 @@ sub lockwiki (;$) { #{{{
        }
        open($wikilock, '>', "$config{wikistatedir}/lockfile") ||
                error ("cannot write to $config{wikistatedir}/lockfile: $!");
-       if (! flock($wikilock, 2 | 4)) { # LOCK_EX | LOCK_NB
-               if ($wait) {
-                       debug("wiki seems to be locked, waiting for lock");
-                       my $wait=600; # arbitrary, but don't hang forever to 
-                                     # prevent process pileup
-                       for (1..$wait) {
-                               return if flock($wikilock, 2 | 4);
-                               sleep 1;
-                       }
-                       error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
-               }
-               else {
-                       return 0;
-               }
+       if (! flock($wikilock, 2)) { # LOCK_EX
+               error("failed to get lock");
        }
        return 1;
 } #}}}
 
 sub unlockwiki () { #{{{
+       POSIX::close($ENV{IKIWIKI_CGILOCK_FD}) if exists $ENV{IKIWIKI_CGILOCK_FD};
        return close($wikilock) if $wikilock;
        return;
 } #}}}
@@ -1894,6 +1893,10 @@ sub match_link ($$;@) { #{{{
                else {
                        return IkiWiki::SuccessReason->new("$page links to page $p matching $link")
                                if match_glob($p, $link, %params);
+                       $p=~s/^\///;
+                       $link=~s/^\///;
+                       return IkiWiki::SuccessReason->new("$page links to page $p matching $link")
+                               if match_glob($p, $link, %params);
                }
        }
        return IkiWiki::FailReason->new("$page does not link to $link");