]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
po(delete): added hook, and function skeleton
[ikiwiki.git] / IkiWiki.pm
index 90fedca4f5dfb5614c229be58f453ea83307ea28..d949566d834fb1cfcc053bd48ae91398f2571e80 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,
@@ -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}));
@@ -655,19 +662,8 @@ sub newpagefile ($$) { #{{{
 sub targetpage ($$) { #{{{
        my $page=shift;
        my $ext=shift;
-
-       my $targetpage='';
-       run_hooks(targetpage => sub {
-               $targetpage=shift->(
-                       page => $page,
-                       ext => $ext,
-               );
-       });
-
-       if (defined $targetpage && (length($targetpage) > 0)) {
-               return $targetpage;
-       }
-       elsif (! $config{usedirs} || $page eq 'index') {
+       
+       if (! $config{usedirs} || $page eq 'index') {
                return $page.".".$ext;
        }
        else {
@@ -815,7 +811,6 @@ sub will_render ($$;$) { #{{{
 sub bestlink ($$) { #{{{
        my $page=shift;
        my $link=shift;
-       my $res=undef;
        
        my $cwd=$page;
        if ($link=~s/^\/+//) {
@@ -830,35 +825,25 @@ sub bestlink ($$) { #{{{
                $l.=$link;
 
                if (exists $links{$l}) {
-                       $res=$l;
+                       return $l;
                }
                elsif (exists $pagecase{lc $l}) {
-                       $res=$pagecase{lc $l};
+                       return $pagecase{lc $l};
                }
-       } while ($cwd=~s{/?[^/]+$}{} && ! defined $res);
+       } while $cwd=~s{/?[^/]+$}{};
 
-       if (! defined $res && length $config{userdir}) {
+       if (length $config{userdir}) {
                my $l = "$config{userdir}/".lc($link);
                if (exists $links{$l}) {
-                       $res=$l;
+                       return $l;
                }
                elsif (exists $pagecase{lc $l}) {
-                       $res=$pagecase{lc $l};
+                       return $pagecase{lc $l};
                }
        }
 
-       if (defined $res) {
-               run_hooks(tweakbestlink => sub {
-                       $res=shift->(
-                               page => $page,
-                               link => $res);
-               });
-               return $res;
-       }
-       else {
-               #print STDERR "warning: page $page, broken link: $link\n";
-               return "";
-       }
+       #print STDERR "warning: page $page, broken link: $link\n";
+       return "";
 } #}}}
 
 sub isinlinableimage ($) { #{{{
@@ -953,10 +938,6 @@ sub beautify_urlpath ($) { #{{{
                $url =~ s!/index.$config{htmlext}$!/!;
        }
 
-       run_hooks(tweakurlpath => sub {
-               $url=shift->(url => $url);
-       });
-
        # Ensure url is not an empty link, and
        # if it's relative, make that explicit to avoid colon confusion.
        if ($url !~ /^\//) {
@@ -1299,8 +1280,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}) {
@@ -1308,20 +1288,8 @@ 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;
 } #}}}
@@ -1920,6 +1888,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");