X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/61c909e2f28758baa7089649f2ae2569213e8eac..2469114dc567fb3a52609b589d85eb28af0cd670:/IkiWiki/Render.pm diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index e6d0bc510..7148d754e 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -9,7 +9,8 @@ sub linkify ($$) { #{{{ my $page=shift; $content =~ s{(\\?)$config{wiki_link_regexp}}{ - $1 ? "[[$2]]" : htmllink($page, $2) + $2 ? ( $1 ? "[[$2|$3]]" : htmllink($page, titlepage($3), 0, 0, pagetitle($2))) + : ( $1 ? "[[$3]]" : htmllink($page, titlepage($3))) }eg; return $content; @@ -85,12 +86,11 @@ sub rsspage ($) { #{{{ return $page.".rss"; } #}}} -sub postprocess { #{{{ - # Takes content to postprocess followed by a list of postprocessor - # commands and subroutine references to run for the commands. +sub preprocess ($$) { #{{{ my $page=shift; my $content=shift; - my %commands=@_; + + my %commands=(inline => \&preprocess_inline); my $handle=sub { my $escape=shift; @@ -138,14 +138,14 @@ sub get_inline_content ($$) { #{{{ my $file=$pagesources{$page}; my $type=pagetype($file); if ($type ne 'unknown') { - return htmlize($type, linkify(readfile("$config{srcdir}/$file"), $parentpage)); + return htmlize($type, linkify(readfile(srcfile($file)), $parentpage)); } else { return ""; } } #}}} -sub postprocess_html_inline { #{{{ +sub preprocess_inline ($@) { #{{{ my $parentpage=shift; my %params=@_; @@ -159,7 +159,7 @@ sub postprocess_html_inline { #{{{ $params{show}=10; } $inlinepages{$parentpage}=$params{pages}; - + my $ret=""; if (exists $params{rootpage}) { @@ -176,8 +176,10 @@ sub postprocess_html_inline { #{{{ ? "$config{templatedir}/inlinepage.tmpl" : "$config{templatedir}/inlinepagetitle.tmpl")); + my @pages; foreach my $page (blog_list($params{pages}, $params{show})) { next if $page eq $parentpage; + push @pages, $page; $template->param(pagelink => htmllink($parentpage, $page)); $template->param(content => get_inline_content($parentpage, $page)) if $params{archive} eq "no"; @@ -185,6 +187,14 @@ sub postprocess_html_inline { #{{{ $ret.=$template->output; } + # TODO: should really add this to renderedfiles and call + # check_overwrite, but currently renderedfiles + # only supports listing one file per page. + if ($config{rss}) { + writefile(rsspage($parentpage), $config{destdir}, + genrss($parentpage, @pages)); + } + return $ret; } #}}} @@ -193,18 +203,16 @@ sub genpage ($$$) { #{{{ my $page=shift; my $mtime=shift; - $content = postprocess($page, $content, inline => \&postprocess_html_inline); - my $title=pagetitle(basename($page)); my $template=HTML::Template->new(blind_cache => 1, filename => "$config{templatedir}/page.tmpl"); if (length $config{cgiurl}) { - $template->param(editurl => "$config{cgiurl}?do=edit&page=$page"); - $template->param(prefsurl => "$config{cgiurl}?do=prefs"); + $template->param(editurl => cgiurl(do => "edit", page => $page)); + $template->param(prefsurl => cgiurl(do => "prefs")); if ($config{rcs}) { - $template->param(recentchangesurl => "$config{cgiurl}?do=recentchanges"); + $template->param(recentchangesurl => cgiurl(do => "recentchanges")); } } @@ -213,9 +221,12 @@ sub genpage ($$$) { #{{{ $u=~s/\[\[file\]\]/$pagesources{$page}/g; $template->param(historyurl => $u); } + if ($config{hyperestraier}) { + $template->param(hyperestraierurl => cgiurl()); + } if ($config{rss} && $inlinepages{$page}) { - $template->param(rssurl => rsspage($page)); + $template->param(rssurl => rsspage(basename($page))); } $template->param( @@ -226,6 +237,7 @@ sub genpage ($$$) { #{{{ backlinks => [backlinks($page)], discussionlink => htmllink($page, "Discussion", 1, 1), mtime => scalar(gmtime($mtime)), + styleurl => styleurl($page), ); return $template->output; @@ -250,10 +262,9 @@ sub absolute_urls ($$) { #{{{ return $content; } #}}} -sub genrss ($$$) { #{{{ - my $content=shift; +sub genrss ($@) { #{{{ my $page=shift; - my $mtime=shift; + my @pages=@_; my $url="$config{url}/".htmlpage($page); @@ -261,35 +272,14 @@ sub genrss ($$$) { #{{{ filename => "$config{templatedir}/rsspage.tmpl"); my @items; - my $isblog=0; - my $gen_blog=sub { - my $parentpage=shift; - my %params=@_; - - return "" if exists $params{archive} && $params{archive} eq 'yes'; - - if (! exists $params{show}) { - $params{show}=10; - } - if (! exists $params{pages}) { - return ""; - } - - $isblog=1; - foreach my $page (blog_list($params{pages}, $params{show})) { - next if $page eq $parentpage; - push @items, { - itemtitle => pagetitle(basename($page)), - itemurl => "$config{url}/$renderedfiles{$page}", - itempubdate => date_822($pagectime{$page}), - itemcontent => absolute_urls(get_inline_content($parentpage, $page), $url), - } if exists $renderedfiles{$page}; - } - - return ""; - }; - - $content = postprocess($page, $content, inline => $gen_blog); + foreach my $p (@pages) { + push @items, { + itemtitle => pagetitle(basename($p)), + itemurl => "$config{url}/$renderedfiles{$p}", + itempubdate => date_822($pagectime{$p}), + itemcontent => absolute_urls(get_inline_content($page, $p), $url), + } if exists $renderedfiles{$p}; + } $template->param( title => $config{wikiname}, @@ -326,7 +316,7 @@ sub findlinks ($$) { #{{{ my @links; while ($content =~ /(?$estdir/$cgi.tmpl") || + error("write $estdir/$cgi.tmpl: $!"); + print TEMPLATE misctemplate("search", + "\n\n\n\n\n\n"); + close TEMPLATE; + open(TEMPLATE, ">$estdir/$cgi.conf") || + error("write $estdir/$cgi.conf: $!"); + my $template=HTML::Template->new( + filename => "$config{templatedir}/estseek.conf" + ); + eval q{use Cwd 'abs_path'}; + $template->param( + index => $estdir, + tmplfile => "$estdir/$cgi.tmpl", + destdir => abs_path($config{destdir}), + url => $config{url}, + ); + print TEMPLATE $template->output; + close TEMPLATE; + $cgi="$estdir/".basename($config{cgiurl}); + unlink($cgi); + symlink("/usr/lib/estraier/estseek.cgi", $cgi) || + error("symlink $cgi: $!"); +} # }}} + +sub estcmd ($;@) { #{{{ + my @params=split(' ', shift); + push @params, "-cl", "$config{wikistatedir}/hyperestraier"; + if (@_) { + push @params, "-"; + } + + my $pid=open(CHILD, "|-"); + if ($pid) { + # parent + foreach (@_) { + print CHILD "$_\n"; + } + close(CHILD) || error("estcmd @params exited nonzero: $?"); + } + else { + # child + open(STDOUT, "/dev/null"); # shut it up (closing won't work) + exec("estcmd", @params) || error("can't run estcmd"); + } +} #}}} + sub refresh () { #{{{ # find existing pages my %exists; @@ -389,9 +425,7 @@ sub refresh () { #{{{ no_chdir => 1, wanted => sub { if (/$config{wiki_file_prune_regexp}/) { - no warnings 'once'; $File::Find::prune=1; - use warnings "all"; } elsif (! -d $_ && ! -l $_) { my ($f)=/$config{wiki_file_regexp}/; # untaint @@ -406,6 +440,30 @@ sub refresh () { #{{{ } }, }, $config{srcdir}); + find({ + no_chdir => 1, + wanted => sub { + if (/$config{wiki_file_prune_regexp}/) { + $File::Find::prune=1; + } + elsif (! -d $_ && ! -l $_) { + my ($f)=/$config{wiki_file_regexp}/; # untaint + if (! defined $f) { + warn("skipping bad filename $_\n"); + } + else { + # Don't add files that are in the + # srcdir. + $f=~s/^\Q$config{underlaydir}\E\/?//; + if (! -e "$config{srcdir}/$f" && + ! -l "$config{srcdir}/$f") { + push @files, $f; + $exists{pagename($f)}=1; + } + } + } + }, + }, $config{underlaydir}); my %rendered; @@ -418,7 +476,7 @@ sub refresh () { #{{{ push @add, $file; $links{$page}=[]; $pagesources{$page}=$file; - $pagectime{$page}=mtime("$config{srcdir}/$file") + $pagectime{$page}=mtime(srcfile($file)) unless exists $pagectime{$page}; } } @@ -439,7 +497,7 @@ sub refresh () { #{{{ my $page=pagename($file); if (! exists $oldpagemtime{$page} || - mtime("$config{srcdir}/$file") > $oldpagemtime{$page}) { + mtime(srcfile($file)) > $oldpagemtime{$page}) { debug("rendering changed file $file"); render($file); $rendered{$file}=1; @@ -482,6 +540,7 @@ FILE: foreach my $file (@files) { if (globlist_match($page, $inlinepages{$p})) { debug("rendering $f, which inlines $page"); render($f); + $rendered{$f}=1; last; } } @@ -516,9 +575,25 @@ FILE: foreach my $file (@files) { if (defined $linkfile) { debug("rendering $linkfile, to update its backlinks"); render($linkfile); + $rendered{$linkfile}=1; } } } + + if ($config{hyperestraier} && (%rendered || @del)) { + debug("updating hyperestraier search index"); + if (%rendered) { + estcmd("gather -cm -bc -cl -sd", + map { $config{destdir}."/".$renderedfiles{pagename($_)} } + keys %rendered); + } + if (@del) { + estcmd("purge -cl"); + } + + debug("generating hyperestraier cgi config"); + estcfg(); + } } #}}} 1