]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
Merge branch 'master' of ssh://git.kitenet.net/srv/git/ikiwiki.info
[ikiwiki.git] / IkiWiki.pm
index ca75d885b3e738ef9e99923f6d8c17941a17bfd6..bd804269dd16fee904743a59bd9ce33428479e4b 100644 (file)
@@ -37,21 +37,6 @@ sub defaultconfig () { #{{{
                qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//,
                qr/(^|\/)_MTN\//,
                qr/\.dpkg-tmp$/],
-       wiki_link_regexp => qr{
-               \[\[(?=[^!])            # beginning of link
-               (?:
-                       ([^\]\|]+)      # 1: link text
-                       \|              # followed by '|'
-               )?                      # optional
-               
-               ([^\s\]#]+)             # 2: page to link to
-               (?:
-                       \#              # '#', beginning of anchor
-                       ([^\s\]]+)      # 3: anchor text
-               )?                      # optional
-               
-               \]\]                    # end of link
-       }x,
        wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
        web_commit_regexp => qr/^web commit (by (.*?(?=: |$))|from (\d+\.\d+\.\d+\.\d+)):?(.*)/,
        verbose => 0,
@@ -89,8 +74,8 @@ sub defaultconfig () { #{{{
        setup => undef,
        adminuser => undef,
        adminemail => undef,
-       plugin => [qw{mdwn inline htmlscrubber passwordauth openid signinedit
-                     lockedit conditional recentchanges}],
+       plugin => [qw{mdwn link inline htmlscrubber passwordauth openid
+                       signinedit lockedit conditional recentchanges}],
        libdir => undef,
        timeformat => '%c',
        locale => undef,
@@ -147,24 +132,6 @@ sub checkconfig () { #{{{
                umask(possibly_foolish_untaint($config{umask}));
        }
 
-       if (!$config{prefix_directives}) {
-               $config{wiki_link_regexp} = qr{
-                       \[\[                    # beginning of link
-                       (?:
-                               ([^\]\|\n\s]+)  # 1: link text
-                               \|              # followed by '|'
-                       )?                      # optional
-
-                       ([^\s\]#]+)             # 2: page to link to
-                       (?:
-                               \#              # '#', beginning of anchor
-                               ([^\s\]]+)      # 3: anchor text
-                       )?                      # optional
-
-                       \]\]                    # end of link
-               }x,
-       }
-
        run_hooks(checkconfig => sub { shift->() });
 
        return 1;
@@ -684,21 +651,17 @@ sub htmlize ($$$) { #{{{
 } #}}}
 
 sub linkify ($$$) { #{{{
-       my $lpage=shift; # the page containing the links
-       my $page=shift; # the page the link will end up on (different for inline)
+       my $page=shift;
+       my $destpage=shift;
        my $content=shift;
 
-       $content =~ s{(\\?)$config{wiki_link_regexp}}{
-               defined $2
-                       ? ( $1 
-                               ? "[[$2|$3".($4 ? "#$4" : "")."]]" 
-                               : htmllink($lpage, $page, linkpage($3),
-                                       anchor => $4, linktext => pagetitle($2)))
-                       : ( $1 
-                               ? "[[$3".($4 ? "#$4" : "")."]]"
-                               : htmllink($lpage, $page, linkpage($3),
-                                       anchor => $4))
-       }eg;
+       run_hooks(linkify => sub {
+               $content=shift->(
+                       page => $page,
+                       destpage => $destpage,
+                       content => $content,
+               );
+       });
        
        return $content;
 } #}}}
@@ -999,7 +962,7 @@ sub saveindex () { #{{{
                if (exists $pagestate{$page}) {
                        foreach my $id (@hookids) {
                                foreach my $key (keys %{$pagestate{$page}{$id}}) {
-                                       $line.=' '.$id.'_'.encode_entities($key)."=".encode_entities($pagestate{$page}{$id}{$key}, " \t\n");
+                                       $line.=' '.$id.'_'.encode_entities($key, " \t\n")."=".encode_entities($pagestate{$page}{$id}{$key}, " \t\n");
                                }
                        }
                }
@@ -1143,6 +1106,8 @@ sub add_depends ($$) { #{{{
        my $page=shift;
        my $pagespec=shift;
        
+       return unless pagespec_valid($pagespec);
+
        if (! exists $depends{$page}) {
                $depends{$page}=$pagespec;
        }
@@ -1271,6 +1236,17 @@ sub pagespec_match ($$;@) { #{{{
        return $ret;
 } #}}}
 
+sub pagespec_valid ($) { #{{{
+       my $spec=shift;
+
+       # used by generated code
+       my $page="";
+       my @params;
+
+       eval pagespec_translate($spec);
+       return ! $@;
+} #}}}
+
 package IkiWiki::FailReason;
 
 use overload ( #{{{