]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
need to remove trailing slashes in not one, but 2 places
[ikiwiki.git] / IkiWiki.pm
index 18a518f3f57ba06c7fdb4942e90cd13af4a1d882..81a634e2b185a4c1e32ac1539e90275777405d69 100644 (file)
@@ -17,6 +17,7 @@ use Exporter q{import};
 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
                  bestlink htmllink readfile writefile pagetype srcfile pagename
                  displaytime will_render gettext urlto targetpage
 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
                  bestlink htmllink readfile writefile pagetype srcfile pagename
                  displaytime will_render gettext urlto targetpage
+                add_underlay
                  %config %links %renderedfiles %pagesources %destsources);
 our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
                  %config %links %renderedfiles %pagesources %destsources);
 our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
@@ -38,7 +39,7 @@ sub defaultconfig () { #{{{
        wiki_link_regexp => qr{
                \[\[                    # beginning of link
                (?:
        wiki_link_regexp => qr{
                \[\[                    # beginning of link
                (?:
-                       ([^\]\|]+)      # 1: link text
+                       ([^\]\|\n\s]+)  # 1: link text
                        \|              # followed by '|'
                )?                      # optional
                
                        \|              # followed by '|'
                )?                      # optional
                
@@ -83,6 +84,7 @@ sub defaultconfig () { #{{{
        pingurl => [],
        templatedir => "$installdir/share/ikiwiki/templates",
        underlaydir => "$installdir/share/ikiwiki/basewiki",
        pingurl => [],
        templatedir => "$installdir/share/ikiwiki/templates",
        underlaydir => "$installdir/share/ikiwiki/basewiki",
+       underlaydirs => [],
        setup => undef,
        adminuser => undef,
        adminemail => undef,
        setup => undef,
        adminuser => undef,
        adminemail => undef,
@@ -285,11 +287,26 @@ sub srcfile ($) { #{{{
        my $file=shift;
 
        return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
        my $file=shift;
 
        return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
-       return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file";
-       error("internal error: $file cannot be found in $config{srcdir} or $config{underlaydir}");
+       foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) {
+               return "$dir/$file" if -e "$dir/$file";
+       }
+       error("internal error: $file cannot be found in $config{srcdir} or underlay");
        return;
 } #}}}
 
        return;
 } #}}}
 
+sub add_underlay ($) { #{{{
+       my $dir=shift;
+
+       if ($dir=~/^\//) {
+               unshift @{$config{underlaydirs}}, $dir;
+       }
+       else {
+               unshift @{$config{underlaydirs}}, "$config{underlaydir}/../$dir";
+       }
+
+       return 1;
+} #}}}
+
 sub readfile ($;$$) { #{{{
        my $file=shift;
        my $binary=shift;
 sub readfile ($;$$) { #{{{
        my $file=shift;
        my $binary=shift;
@@ -390,6 +407,7 @@ sub bestlink ($$) { #{{{
                # absolute links
                $cwd="";
        }
                # absolute links
                $cwd="";
        }
+       $link=~s/\/$//;
 
        do {
                my $l=$cwd;
 
        do {
                my $l=$cwd;
@@ -481,13 +499,16 @@ sub abs2rel ($$) { #{{{
        return $ret;
 } #}}}
 
        return $ret;
 } #}}}
 
-sub displaytime ($) { #{{{
+sub displaytime ($;$) { #{{{
        my $time=shift;
        my $time=shift;
+       my $format=shift;
+       if (! defined $format) {
+               $format=$config{timeformat};
+       }
 
        # strftime doesn't know about encodings, so make sure
        # its output is properly treated as utf8
 
        # strftime doesn't know about encodings, so make sure
        # its output is properly treated as utf8
-       return decode_utf8(POSIX::strftime(
-                       $config{timeformat}, localtime($time)));
+       return decode_utf8(POSIX::strftime($format, localtime($time)));
 } #}}}
 
 sub beautify_url ($) { #{{{
 } #}}}
 
 sub beautify_url ($) { #{{{
@@ -522,6 +543,8 @@ sub htmllink ($$$;@) { #{{{
        my $link=shift;
        my %opts=@_;
 
        my $link=shift;
        my %opts=@_;
 
+       $link=~s/\/$//;
+
        my $bestlink;
        if (! $opts{forcesubpage}) {
                $bestlink=bestlink($lpage, $link);
        my $bestlink;
        if (! $opts{forcesubpage}) {
                $bestlink=bestlink($lpage, $link);
@@ -546,7 +569,7 @@ sub htmllink ($$$;@) { #{{{
 
                if (! $destsources{$bestlink}) {
                        return $linktext unless length $config{cgiurl};
 
                if (! $destsources{$bestlink}) {
                        return $linktext unless length $config{cgiurl};
-                       return "<span><a href=\"".
+                       return "<span class=\"createlink\"><a href=\"".
                                cgiurl(
                                        do => "create",
                                        page => pagetitle(lc($link), 1),
                                cgiurl(
                                        do => "create",
                                        page => pagetitle(lc($link), 1),
@@ -571,6 +594,9 @@ sub htmllink ($$$;@) { #{{{
        if (defined $opts{rel}) {
                push @attrs, ' rel="'.$opts{rel}.'"';
        }
        if (defined $opts{rel}) {
                push @attrs, ' rel="'.$opts{rel}.'"';
        }
+       if (defined $opts{class}) {
+               push @attrs, ' class="'.$opts{class}.'"';
+       }
 
        return "<a href=\"$bestlink\"@attrs>$linktext</a>";
 } #}}}
 
        return "<a href=\"$bestlink\"@attrs>$linktext</a>";
 } #}}}
@@ -806,6 +832,11 @@ sub enable_commit_hook () { #{{{
 } #}}}
 
 sub loadindex () { #{{{
 } #}}}
 
 sub loadindex () { #{{{
+       %oldrenderedfiles=%pagectime=();
+       if (! $config{rebuild}) {
+               %pagesources=%pagemtime=%oldlinks=%links=%depends=
+                       %destsources=%renderedfiles=%pagecase=();
+       }
        open (my $in, "<", "$config{wikistatedir}/index") || return;
        while (<$in>) {
                $_=possibly_foolish_untaint($_);
        open (my $in, "<", "$config{wikistatedir}/index") || return;
        while (<$in>) {
                $_=possibly_foolish_untaint($_);
@@ -886,7 +917,7 @@ sub template_params (@) { #{{{
        my @ret=(
                filter => sub {
                        my $text_ref = shift;
        my @ret=(
                filter => sub {
                        my $text_ref = shift;
-                       ${$text_ref} = Encode::decode_utf8(${$text_ref});
+                       ${$text_ref} = decode_utf8(${$text_ref});
                },
                filename => $filename,
                loop_context_vars => 1,
                },
                filename => $filename,
                loop_context_vars => 1,
@@ -1203,7 +1234,7 @@ sub match_link ($$;@) { #{{{
                                if $bestlink eq IkiWiki::bestlink($page, $p);
                }
                else {
                                if $bestlink eq IkiWiki::bestlink($page, $p);
                }
                else {
-                       return IkiWiki::SuccessReason->new("$page links to page matching $link")
+                       return IkiWiki::SuccessReason->new("$page links to page $p matching $link")
                                if match_glob($p, $link, %params);
                }
        }
                                if match_glob($p, $link, %params);
                }
        }