X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/0943c375d42862c6db9561787ebd9ddae48d890a..a223f4540fee2d0c49523343a422315377bc0025:/ikiwiki?ds=sidebyside

diff --git a/ikiwiki b/ikiwiki
index a9a0c8ff4..3540f8667 100755
--- a/ikiwiki
+++ b/ikiwiki
@@ -1,5 +1,4 @@
 #!/usr/bin/perl -T
-
 $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
 
 package IkiWiki;
@@ -11,33 +10,36 @@ use lib '.'; # For use without installation, removed by Makefile.
 
 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,
-); #}}}
+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_.\&;:\/+]+$)/,
+			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,
+		);
+
 		eval q{use Getopt::Long};
 		GetOptions(
 			"setup|s=s" => \$config{setup},
@@ -68,8 +70,8 @@ sub getconfig () { #{{{
 
 		if (! $config{setup}) {
 			usage() unless @ARGV == 2;
-			$config{srcdir} = possibly_foolish_untaint(shift);
-			$config{destdir} = possibly_foolish_untaint(shift);
+			$config{srcdir} = possibly_foolish_untaint(shift @ARGV);
+			$config{destdir} = possibly_foolish_untaint(shift @ARGV);
 			checkconfig();
 		}
 	}
@@ -81,7 +83,7 @@ sub getconfig () { #{{{
 	}
 } #}}}
 
-sub checkconfig { #{{{
+sub checkconfig () { #{{{
 	if ($config{cgi} && ! length $config{url}) {
 		error("Must specify url to wiki with --url when using --cgi");
 	}
@@ -90,20 +92,16 @@ sub checkconfig { #{{{
 		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", "<p>Error: @_</p>");
@@ -111,6 +109,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}) {
@@ -121,12 +125,6 @@ sub debug ($) { #{{{
 	}
 } #}}}
 
-sub possibly_foolish_untaint { #{{{
-	my $tainted=shift;
-	my ($untainted)=$tainted=~/(.*)/;
-	return $untainted;
-} #}}}
-
 sub basename ($) { #{{{
 	my $file=shift;
 
@@ -236,7 +234,14 @@ sub isinlinableimage ($) { #{{{
 	$file=~/\.(png|gif|jpg|jpeg)$/;
 } #}}}
 
-sub htmllink { #{{{
+sub pagetitle ($) { #{{{
+	my $page=shift;
+	$page=~s/__(\d+)__/&#$1;/g;
+	$page=~y/_/ /;
+	return $page;
+} #}}}
+
+sub htmllink ($$;$$) { #{{{
 	my $page=shift;
 	my $link=shift;
 	my $noimageinline=shift; # don't turn links into inline html images
@@ -250,7 +255,9 @@ sub htmllink { #{{{
 		$bestlink="$page/".lc($link);
 	}
 
-	return $link if length $bestlink && $page eq $bestlink;
+	my $linktext=pagetitle($link);
+	
+	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
@@ -260,7 +267,7 @@ sub htmllink { #{{{
 		$bestlink=htmlpage($bestlink);
 	}
 	if (! grep { $_ eq $bestlink } values %renderedfiles) {
-		return "<a href=\"$config{cgiurl}?do=create&page=$link&from=$page\">?</a>$link"
+		return "<a href=\"$config{cgiurl}?do=create&page=$link&from=$page\">?</a>$linktext"
 	}
 	
 	$bestlink=File::Spec->abs2rel($bestlink, dirname($page));
@@ -268,7 +275,7 @@ sub htmllink { #{{{
 	if (! $noimageinline && isinlinableimage($bestlink)) {
 		return "<img src=\"$bestlink\">";
 	}
-	return "<a href=\"$bestlink\">$link</a>";
+	return "<a href=\"$bestlink\">$linktext</a>";
 } #}}}
 
 sub indexlink () { #{{{