]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/inline.pm
Rename show parameter of [[!inline]] and [[!pagestats]] to limit
[git.ikiwiki.info.git] / IkiWiki / Plugin / inline.pm
index a50c4b7b79dbe2ba9b3ab932a365cf315c2d1d21..b122bd0f2a4e55fca4a7be3d0d07d367c979eb0b 100644 (file)
@@ -180,11 +180,29 @@ sub preprocess_inline (@) {
        my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick && ! $raw;
        my $emptyfeeds=exists $params{emptyfeeds} ? yesno($params{emptyfeeds}) : 1;
        my $feedonly=yesno($params{feedonly});
        my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick && ! $raw;
        my $emptyfeeds=exists $params{emptyfeeds} ? yesno($params{emptyfeeds}) : 1;
        my $feedonly=yesno($params{feedonly});
-       if (! exists $params{show} && ! $archive) {
-               $params{show}=10;
+
+       # Backwards compatibility
+       if (defined $params{show} && $params{show} =~ m/^\d+$/) {
+               $params{limit} = $params{show};
+               delete $params{show};
+       }
+       if (defined $params{feedshow} && $params{feedshow} =~ m/^\d+$/) {
+               $params{feedlimit} = $params{feedshow};
+               delete $params{feedshow};
+       }
+
+       if (! exists $params{limit} && ! $archive) {
+               $params{limit}=10;
+       }
+       if (! exists $params{feedlimit} && exists $params{limit}) {
+               $params{feedlimit}=$params{limit};
+       }
+       my $title;
+       if (exists $params{title}) {
+               $title = $params{title};
        }
        }
-       if (! exists $params{feedshow} && exists $params{show}) {
-               $params{feedshow}=$params{show};
+       else {
+               $title = $params{page} ne "index" ? pagetitle($params{page}) : $config{wikiname};
        }
        my $desc;
        if (exists $params{description}) {
        }
        my $desc;
        if (exists $params{description}) {
@@ -211,9 +229,7 @@ sub preprocess_inline (@) {
                        }
                }
 
                        }
                }
 
-               @list = grep { $_ ne '' } 
-                       map { bestlink($params{page}, $_) }
-                       split ' ', $params{pagenames};
+               @list = split ' ', $params{pagenames};
 
                if (yesno($params{reverse})) {
                        @list=reverse(@list);
 
                if (yesno($params{reverse})) {
                        @list=reverse(@list);
@@ -222,14 +238,16 @@ sub preprocess_inline (@) {
                foreach my $p (@list) {
                        add_depends($params{page}, $p, deptype($quick ? "presence" : "content"));
                }
                foreach my $p (@list) {
                        add_depends($params{page}, $p, deptype($quick ? "presence" : "content"));
                }
+
+               @list = grep { exists $pagesources{$_} } @list;
        }
        else {
                my $num=0;
        }
        else {
                my $num=0;
-               if ($params{show}) {
-                       $num=$params{show};
+               if ($params{limit}) {
+                       $num=$params{limit};
                }
                }
-               if ($params{feedshow} && $num < $params{feedshow} && $num > 0) {
-                       $num=$params{feedshow};
+               if ($params{feedlimit} && $num < $params{feedlimit} && $num > 0) {
+                       $num=$params{feedlimit};
                }
                if ($params{skip} && $num) {
                        $num+=$params{skip};
                }
                if ($params{skip} && $num) {
                        $num+=$params{skip};
@@ -250,17 +268,17 @@ sub preprocess_inline (@) {
        
        my @feedlist;
        if ($feeds) {
        
        my @feedlist;
        if ($feeds) {
-               if (exists $params{feedshow} &&
-                   $params{feedshow} && @list > $params{feedshow}) {
-                       @feedlist=@list[0..$params{feedshow} - 1];
+               if (exists $params{feedlimit} &&
+                   $params{feedlimit} && @list > $params{feedlimit}) {
+                       @feedlist=@list[0..$params{feedlimit} - 1];
                }
                else {
                        @feedlist=@list;
                }
        }
        
                }
                else {
                        @feedlist=@list;
                }
        }
        
-       if ($params{show} && @list > $params{show}) {
-               @list=@list[0..$params{show} - 1];
+       if ($params{limit} && @list > $params{limit}) {
+               @list=@list[0..$params{limit} - 1];
        }
 
        if ($feeds && exists $params{feedpages}) {
        }
 
        if ($feeds && exists $params{feedpages}) {
@@ -322,8 +340,12 @@ sub preprocess_inline (@) {
 
        my $ret="";
 
 
        my $ret="";
 
-       if (length $config{cgiurl} && ! $params{preview} && (exists $params{rootpage} ||
-           (exists $params{postform} && yesno($params{postform}))) &&
+       my $postform = (exists $params{rootpage});
+       if (exists $params{postform}) {
+               $postform = yesno($params{postform});
+       }
+
+       if (length $config{cgiurl} && ! $params{preview} && $postform &&
            IkiWiki->can("cgi_editpage")) {
                # Add a blog post form, with feed buttons.
                my $formtemplate=template_depends("blogpost.tmpl", $params{page}, blind_cache => 1);
            IkiWiki->can("cgi_editpage")) {
                # Add a blog post form, with feed buttons.
                my $formtemplate=template_depends("blogpost.tmpl", $params{page}, blind_cache => 1);
@@ -384,7 +406,9 @@ sub preprocess_inline (@) {
                                        blind_cache => 1);
                        };
                        if ($@) {
                                        blind_cache => 1);
                        };
                        if ($@) {
-                               error sprintf(gettext("failed to process template %s"), $params{template}.".tmpl").": $@";
+                               # gettext can clobber $@
+                               my $error = $@;
+                               error sprintf(gettext("failed to process template %s"), $params{template}.".tmpl").": $error";
                        }
                }
                my $needcontent=$raw || (!($archive && $quick) && $template->query(name => 'content'));
                        }
                }
                my $needcontent=$raw || (!($archive && $quick) && $template->query(name => 'content'));
@@ -465,7 +489,7 @@ sub preprocess_inline (@) {
                        if (! $params{preview}) {
                                writefile($rssp, $config{destdir},
                                        genfeed("rss",
                        if (! $params{preview}) {
                                writefile($rssp, $config{destdir},
                                        genfeed("rss",
-                                               $config{url}."/".$rssp, $desc, $params{guid}, $params{page}, @feedlist));
+                                               $config{url}."/".$rssp, $title, $desc, $params{guid}, $params{page}, @feedlist));
                                $toping{$params{destpage}}=1 unless $config{rebuild};
                                $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/rss+xml" title="$rssdesc" href="$rssurl" />};
                        }
                                $toping{$params{destpage}}=1 unless $config{rebuild};
                                $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/rss+xml" title="$rssdesc" href="$rssurl" />};
                        }
@@ -475,7 +499,7 @@ sub preprocess_inline (@) {
                        will_render($params{destpage}, $atomp);
                        if (! $params{preview}) {
                                writefile($atomp, $config{destdir},
                        will_render($params{destpage}, $atomp);
                        if (! $params{preview}) {
                                writefile($atomp, $config{destdir},
-                                       genfeed("atom", $config{url}."/".$atomp, $desc, $params{guid}, $params{page}, @feedlist));
+                                       genfeed("atom", $config{url}."/".$atomp, $title, $desc, $params{guid}, $params{page}, @feedlist));
                                $toping{$params{destpage}}=1 unless $config{rebuild};
                                $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/atom+xml" title="$atomdesc" href="$atomurl" />};
                        }
                                $toping{$params{destpage}}=1 unless $config{rebuild};
                                $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/atom+xml" title="$atomdesc" href="$atomurl" />};
                        }
@@ -611,9 +635,30 @@ sub absolute_urls ($$) {
        return $ret;
 }
 
        return $ret;
 }
 
+sub genenclosure {
+       my $itemtemplate=shift;
+       my $url=shift;
+       my $file=shift;
+
+       return unless $itemtemplate->query(name => "enclosure");
+
+       my $size=(srcfile_stat($file))[8];
+       my $mime="unknown";
+       eval q{use File::MimeInfo};
+       if (! $@) {
+               $mime = mimetype($file);
+       }
+       $itemtemplate->param(
+               enclosure => $url,
+               type => $mime,
+               length => $size,
+       );
+}
+
 sub genfeed ($$$$$@) {
        my $feedtype=shift;
        my $feedurl=shift;
 sub genfeed ($$$$$@) {
        my $feedtype=shift;
        my $feedurl=shift;
+        my $feedtitle=shift;
        my $feeddesc=shift;
        my $guid=shift;
        my $page=shift;
        my $feeddesc=shift;
        my $guid=shift;
        my $page=shift;
@@ -627,6 +672,7 @@ sub genfeed ($$$$$@) {
        foreach my $p (@pages) {
                my $u=URI->new(encode_utf8(urlto($p, "", 1)));
                my $pcontent = absolute_urls(get_inline_content($p, $page), $url);
        foreach my $p (@pages) {
                my $u=URI->new(encode_utf8(urlto($p, "", 1)));
                my $pcontent = absolute_urls(get_inline_content($p, $page), $url);
+               my $fancy_enclosure_seen = 0;
 
                $itemtemplate->param(
                        title => pagetitle(basename($p)),
 
                $itemtemplate->param(
                        title => pagetitle(basename($p)),
@@ -648,32 +694,23 @@ sub genfeed ($$$$$@) {
                                $itemtemplate->param(mdate_822 => date_822($pagestate{$p}{meta}{updated}));
                                $itemtemplate->param(mdate_3339 => date_3339($pagestate{$p}{meta}{updated}));
                        }
                                $itemtemplate->param(mdate_822 => date_822($pagestate{$p}{meta}{updated}));
                                $itemtemplate->param(mdate_3339 => date_3339($pagestate{$p}{meta}{updated}));
                        }
-               }
 
 
-               if ($itemtemplate->query(name => "enclosure")) {
-                       my $file=$pagesources{$p};
-                       my $type=pagetype($file);
-                       if (defined $type) {
-                               $itemtemplate->param(content => $pcontent);
-                       }
-                       else {
-                               my $size=(srcfile_stat($file))[8];
-                               my $mime="unknown";
-                               eval q{use File::MimeInfo};
-                               if (! $@) {
-                                       $mime = mimetype($file);
-                               }
-                               $itemtemplate->param(
-                                       enclosure => $u,
-                                       type => $mime,
-                                       length => $size,
-                               );
+                       if (exists $pagestate{$p}{meta}{enclosure}) {
+                               my $absurl = $pagestate{$p}{meta}{enclosure};
+                               my $file = $pagestate{$p}{meta}{enclosurefile};
+                               genenclosure($itemtemplate, $absurl, $file);
+                               $fancy_enclosure_seen = 1;
                        }
                }
                        }
                }
-               else {
-                       $itemtemplate->param(content => $pcontent);
+
+               my $file=$pagesources{$p};
+               unless ($fancy_enclosure_seen || defined(pagetype($file))) {
+                       genenclosure($itemtemplate, $u, $file);
+                       $itemtemplate->param(simplepodcast => 1);
                }
 
                }
 
+               $itemtemplate->param(content => $pcontent);
+
                run_hooks(pagetemplate => sub {
                        shift->(page => $p, destpage => $page,
                                template => $itemtemplate);
                run_hooks(pagetemplate => sub {
                        shift->(page => $p, destpage => $page,
                                template => $itemtemplate);
@@ -687,13 +724,14 @@ sub genfeed ($$$$$@) {
 
        my $template=template_depends($feedtype."page.tmpl", $page, blind_cache => 1);
        $template->param(
 
        my $template=template_depends($feedtype."page.tmpl", $page, blind_cache => 1);
        $template->param(
-               title => $page ne "index" ? pagetitle($page) : $config{wikiname},
+               title => $feedtitle,
                wikiname => $config{wikiname},
                pageurl => $url,
                content => $content,
                feeddesc => $feeddesc,
                guid => $guid,
                feeddate => date_3339($lasttime),
                wikiname => $config{wikiname},
                pageurl => $url,
                content => $content,
                feeddesc => $feeddesc,
                guid => $guid,
                feeddate => date_3339($lasttime),
+               feeddate_822 => date_822($lasttime),
                feedurl => $feedurl,
        );
        run_hooks(pagetemplate => sub {
                feedurl => $feedurl,
        );
        run_hooks(pagetemplate => sub {