X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/b645dc5a4118feabd37d95fabbc6aaa803e3c45f..c438458b8a0f1c9ab7a762380e1f0b8b3db6c67d:/ikiwiki diff --git a/ikiwiki b/ikiwiki index b59aa8c8f..d1173d399 100755 --- a/ikiwiki +++ b/ikiwiki @@ -1,105 +1,118 @@ #!/usr/bin/perl -T - $ENV{PATH}="/usr/local/bin:/usr/bin:/bin"; -use lib '.'; # For use without installation, removed by Makefile. - package IkiWiki; use warnings; use strict; -use Memoize; use File::Spec; use HTML::Template; +use lib '.'; # For use without installation, removed by Makefile. + +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\]\|]+)\|)?([^\s\]]+)\]\]/, + wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]+)\]\]/, + wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/, + verbose => 0, + wikiname => "wiki", + default_pageext => ".mdwn", + cgi => 0, + svn => 1, + url => '', + cgiurl => '', + historyurl => '', + diffurl => '', + anonok => 0, + rss => 0, + rebuild => 0, + refresh => 0, + getctime => 0, + wrapper => undef, + wrappermode => undef, + srcdir => undef, + destdir => undef, + templatedir => "/usr/share/ikiwiki/templates", + setup => undef, + adminuser => undef, + ); + + eval q{use Getopt::Long}; + GetOptions( + "setup|s=s" => \$config{setup}, + "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}, + "rss!" => \$config{rss}, + "cgi!" => \$config{cgi}, + "url=s" => \$config{url}, + "cgiurl=s" => \$config{cgiurl}, + "historyurl=s" => \$config{historyurl}, + "diffurl=s" => \$config{diffurl}, + "exclude=s@" => sub { + $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/; + }, + "adminuser=s@" => sub { + push @{$config{adminuser}}, $_[1] + }, + "templatedir=s" => sub { + $config{templatedir}=possibly_foolish_untaint($_[1]) + }, + "wrapper:s" => sub { + $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap" + }, + ) || usage(); + + if (! $config{setup}) { + usage() unless @ARGV == 2; + $config{srcdir} = possibly_foolish_untaint(shift @ARGV); + $config{destdir} = possibly_foolish_untaint(shift @ARGV); + checkconfig(); + } + } + else { + # wrapper passes a full config structure in the environment + # variable + eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS}); + checkconfig(); + } +} #}}} -use vars qw{%config %links %oldlinks %oldpagemtime %renderedfiles %pagesources}; - -# Holds global config settings, also used by some modules. -our %config=( #{{{ - wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)}, - wiki_link_regexp => qr/\[\[([^\s\]]+)\]\]/, - wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/, - verbose => 0, - wikiname => "wiki", - default_pageext => ".mdwn", - cgi => 0, - svn => 1, - url => '', - cgiurl => '', - historyurl => '', - diffurl => '', - anonok => 0, - rebuild => 0, - wrapper => undef, - wrappermode => undef, - srcdir => undef, - destdir => undef, - templatedir => "/usr/share/ikiwiki/templates", - setup => undef, - adminuser => undef, -); #}}} - -# option parsing #{{{ -if (! exists $ENV{WRAPPED_OPTIONS}) { - eval q{use Getopt::Long}; - GetOptions( - "setup|s=s" => \$config{setup}, - "wikiname=s" => \$config{wikiname}, - "verbose|v!" => \$config{verbose}, - "rebuild!" => \$config{rebuild}, - "wrapper:s" => sub { $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap" }, - "wrappermode=i" => \$config{wrappermode}, - "svn!" => \$config{svn}, - "anonok!" => \$config{anonok}, - "cgi!" => \$config{cgi}, - "url=s" => \$config{url}, - "cgiurl=s" => \$config{cgiurl}, - "historyurl=s" => \$config{historyurl}, - "diffurl=s" => \$config{diffurl}, - "exclude=s@" => sub { - $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/; - }, - "adminuser=s@" => sub { push @{$config{adminuser}}, $_[1] }, - "templatedir=s" => sub { $config{templatedir}=possibly_foolish_untaint($_[1]) }, - ) || usage(); - - if (! $config{setup}) { - usage() unless @ARGV == 2; - $config{srcdir} = possibly_foolish_untaint(shift); - $config{destdir} = possibly_foolish_untaint(shift); - checkoptions(); - } -} -else { - # wrapper passes a full config structure in the environment - # variable - eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS}); - checkoptions(); -} -#}}} - -sub checkoptions { #{{{ +sub checkconfig () { #{{{ if ($config{cgi} && ! length $config{url}) { - error("Must specify url to wiki with --url when using --cgi"); + error("Must specify url to wiki with --url when using --cgi\n"); + } + if ($config{rss} && ! length $config{url}) { + error("Must specify url to wiki with --url when using --rss\n"); } $config{wikistatedir}="$config{srcdir}/.ikiwiki" unless exists $config{wikistatedir}; if ($config{svn}) { - require IkiWiki::RCS::SVN; + require IkiWiki::Rcs::SVN; $config{rcs}=1; } else { - require IkiWiki::RCS::Stub; + require IkiWiki::Rcs::Stub; $config{rcs}=0; } } #}}} -sub usage { #{{{ - die "usage: ikiwiki [options] source dest\n"; -} #}}} - -sub error { #{{{ +sub error ($) { #{{{ if ($config{cgi}) { print "Content-type: text/html\n\n"; print misctemplate("Error", "
Error: @_
"); @@ -107,6 +120,12 @@ sub error { #{{{ die @_; } #}}} +sub possibly_foolish_untaint ($) { #{{{ + my $tainted=shift; + my ($untainted)=$tainted=~/(.*)/; + return $untainted; +} #}}} + sub debug ($) { #{{{ return unless $config{verbose}; if (! $config{cgi}) { @@ -117,12 +136,6 @@ sub debug ($) { #{{{ } } #}}} -sub possibly_foolish_untaint { #{{{ - my $tainted=shift; - my ($untainted)=$tainted=~/(.*)/; - return $untainted; -} #}}} - sub basename ($) { #{{{ my $file=shift; @@ -229,14 +242,35 @@ sub bestlink ($$) { #{{{ sub isinlinableimage ($) { #{{{ my $file=shift; - $file=~/\.(png|gif|jpg|jpeg)$/; + $file=~/\.(png|gif|jpg|jpeg)$/i; } #}}} -sub htmllink { #{{{ +sub pagetitle ($) { #{{{ + my $page=shift; + $page=~s/__(\d+)__/$1;/g; + $page=~y/_/ /; + return $page; +} #}}} + +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 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) { @@ -246,7 +280,9 @@ sub htmllink { #{{{ $bestlink="$page/".lc($link); } - return $link if length $bestlink && $page eq $bestlink; + $linktext=pagetitle(basename($link)) unless defined $linktext; + + return $linktext if length $bestlink && $page eq $bestlink; # TODO BUG: %renderedfiles may not have it, if the linked to page # was also added and isn't yet rendered! Note that this bug is @@ -256,15 +292,17 @@ sub htmllink { #{{{ $bestlink=htmlpage($bestlink); } if (! grep { $_ eq $bestlink } values %renderedfiles) { - return "?$link" + return " "create", page => $link, from =>$page). + "\">?$linktext" } $bestlink=File::Spec->abs2rel($bestlink, dirname($page)); if (! $noimageinline && isinlinableimage($bestlink)) { - return ""; + return ""; } - return "$link"; + return "$linktext"; } #}}} sub indexlink () { #{{{ @@ -300,13 +338,26 @@ sub loadindex () { #{{{ while (