use HTML::Template;
use lib '.'; # For use without installation, removed by Makefile.
-use vars qw{%config %links %oldlinks %oldpagemtime %renderedfiles %pagesources};
+use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
+ %renderedfiles %pagesources %inlinepages};
sub usage () { #{{{
die "usage: ikiwiki [options] source dest\n";
sub getconfig () { #{{{
if (! exists $ENV{WRAPPED_OPTIONS}) {
%config=(
- wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)},
- wiki_link_regexp => qr/\[\[([^\s\]]+)\]\]/,
- wiki_file_regexp => qr/(^[-A-Za-z0-9_.\&;:\/+]+$)/,
+ wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$|\.rss$)},
+ wiki_link_regexp => qr/\[\[(?:([^\s\]\|]+)\|)?([^\s\]]+)\]\]/,
+ wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]+)\]\]/,
+ wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/,
verbose => 0,
wikiname => "wiki",
default_pageext => ".mdwn",
anonok => 0,
rss => 0,
rebuild => 0,
+ refresh => 0,
+ getctime => 0,
wrapper => undef,
wrappermode => undef,
srcdir => undef,
destdir => undef,
templatedir => "/usr/share/ikiwiki/templates",
+ underlaydir => "/usr/share/ikiwiki/basewiki",
setup => undef,
adminuser => undef,
);
"wikiname=s" => \$config{wikiname},
"verbose|v!" => \$config{verbose},
"rebuild!" => \$config{rebuild},
+ "refresh!" => \$config{refresh},
+ "getctime" => \$config{getctime},
"wrappermode=i" => \$config{wrappermode},
"svn!" => \$config{svn},
"anonok!" => \$config{anonok},
"templatedir=s" => sub {
$config{templatedir}=possibly_foolish_untaint($_[1])
},
+ "underlaydir=s" => sub {
+ $config{underlaydir}=possibly_foolish_untaint($_[1])
+ },
"wrapper:s" => sub {
$config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
},
return $page.".html";
} #}}}
+sub srcfile ($) { #{{{
+ 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");
+} #}}}
+
sub readfile ($) { #{{{
my $file=shift;
return $ret;
} #}}}
-sub writefile ($$) { #{{{
- my $file=shift;
+sub writefile ($$$) { #{{{
+ my $file=shift; # can include subdirs
+ my $destdir=shift; # directory to put file in
my $content=shift;
- if (-l $file) {
- error("cannot write to a symlink ($file)");
+ my $test=$file;
+ while (length $test) {
+ if (-l "$destdir/$test") {
+ error("cannot write to a symlink ($test)");
+ }
+ $test=dirname($test);
}
- my $dir=dirname($file);
+ my $dir=dirname("$destdir/$file");
if (! -d $dir) {
my $d="";
foreach my $s (split(m!/+!, $dir)) {
}
}
- open (OUT, ">$file") || error("failed to write $file: $!");
+ open (OUT, ">$destdir/$file") || error("failed to write $destdir/$file: $!");
print OUT $content;
close OUT;
} #}}}
sub isinlinableimage ($) { #{{{
my $file=shift;
- $file=~/\.(png|gif|jpg|jpeg)$/;
+ $file=~/\.(png|gif|jpg|jpeg)$/i;
} #}}}
sub pagetitle ($) { #{{{
return $page;
} #}}}
-sub htmllink ($$;$$) { #{{{
+sub titlepage ($) { #{{{
+ my $title=shift;
+ $title=~y/ /_/;
+ $title=~s/([^-A-Za-z0-9_:+\/.])/"__".ord($1)."__"/eg;
+ return $title;
+} #}}}
+
+sub cgiurl (@) { #{{{
+ my %params=@_;
+
+ return $config{cgiurl}."?".join("&", map "$_=$params{$_}", keys %params);
+} #}}}
+
+sub styleurl (;$) { #{{{
+ my $page=shift;
+
+ return "$config{url}/style.css" if ! defined $page;
+
+ $page=~s/[^\/]+$//;
+ $page=~s/[^\/]+\//..\//g;
+ return $page."style.css";
+} #}}}
+
+sub htmllink ($$;$$$) { #{{{
my $page=shift;
my $link=shift;
my $noimageinline=shift; # don't turn links into inline html images
my $forcesubpage=shift; # force a link to a subpage
+ my $linktext=shift; # set to force the link text to something
my $bestlink;
if (! $forcesubpage) {
$bestlink="$page/".lc($link);
}
- my $linktext=pagetitle($link);
+ $linktext=pagetitle(basename($link)) unless defined $linktext;
return $linktext if length $bestlink && $page eq $bestlink;
$bestlink=htmlpage($bestlink);
}
if (! grep { $_ eq $bestlink } values %renderedfiles) {
- return "<a href=\"$config{cgiurl}?do=create&page=$link&from=$page\">?</a>$linktext"
+ return "<span><a href=\"".
+ cgiurl(do => "create", page => $link, from =>$page).
+ "\">?</a>$linktext</span>"
}
$bestlink=File::Spec->abs2rel($bestlink, dirname($page));
if (! $noimageinline && isinlinableimage($bestlink)) {
- return "<img src=\"$bestlink\">";
+ return "<img src=\"$bestlink\" alt=\"$linktext\" />";
}
return "<a href=\"$bestlink\">$linktext</a>";
} #}}}
while (<IN>) {
$_=possibly_foolish_untaint($_);
chomp;
- my ($mtime, $file, $rendered, @links)=split(' ', $_);
- my $page=pagename($file);
- $pagesources{$page}=$file;
- $oldpagemtime{$page}=$mtime;
- $oldlinks{$page}=[@links];
- $links{$page}=[@links];
- $renderedfiles{$page}=$rendered;
+ my %items;
+ $items{link}=[];
+ foreach my $i (split(/ /, $_)) {
+ my ($item, $val)=split(/=/, $i, 2);
+ push @{$items{$item}}, $val;
+ }
+
+ next unless exists $items{src}; # skip bad lines for now
+
+ my $page=pagename($items{src}[0]);
+ if (! $config{rebuild}) {
+ $pagesources{$page}=$items{src}[0];
+ $oldpagemtime{$page}=$items{mtime}[0];
+ $oldlinks{$page}=[@{$items{link}}];
+ $links{$page}=[@{$items{link}}];
+ $inlinepages{$page}=join(" ", @{$items{inlinepage}})
+ if exists $items{inlinepage};
+ $renderedfiles{$page}=$items{dest}[0];
+ }
+ $pagectime{$page}=$items{ctime}[0];
}
close IN;
} #}}}
open (OUT, ">$config{wikistatedir}/index") ||
error("cannot write to $config{wikistatedir}/index: $!");
foreach my $page (keys %oldpagemtime) {
- print OUT "$oldpagemtime{$page} $pagesources{$page} $renderedfiles{$page} ".
- join(" ", @{$links{$page}})."\n"
- if $oldpagemtime{$page};
+ next unless $oldpagemtime{$page};
+ my $line="mtime=$oldpagemtime{$page} ".
+ "ctime=$pagectime{$page} ".
+ "src=$pagesources{$page} ".
+ "dest=$renderedfiles{$page}";
+ $line.=" link=$_" foreach @{$links{$page}};
+ if (exists $inlinepages{$page}) {
+ $line.=" inlinepage=$_" foreach split " ", $inlinepages{$page};
+ }
+ print OUT $line."\n";
}
close OUT;
} #}}}
indexlink => indexlink(),
wikiname => $config{wikiname},
pagebody => $pagebody,
+ styleurl => styleurl(),
);
return $template->output;
}#}}}
sub main () { #{{{
getconfig();
- if ($config{setup}) {
+ if ($config{cgi}) {
+ lockwiki();
+ loadindex();
+ require IkiWiki::CGI;
+ cgi();
+ }
+ elsif ($config{setup}) {
require IkiWiki::Setup;
setup();
}
require IkiWiki::Wrapper;
gen_wrapper();
}
- elsif ($config{cgi}) {
- lockwiki();
- require IkiWiki::CGI;
- cgi();
- }
else {
lockwiki();
- loadindex() unless $config{rebuild};
+ loadindex();
require IkiWiki::Render;
rcs_update();
+ rcs_getctime() if $config{getctime};
refresh();
saveindex();
}