]> sipb.mit.edu Git - ikiwiki.git/blobdiff - ikiwiki
fix for already relative urls
[ikiwiki.git] / ikiwiki
diff --git a/ikiwiki b/ikiwiki
index dd5758b3a752a1aa01e345a75b890caf03bd2459..5c708919a9288c460c1094adf367b27e2f8777f8 100755 (executable)
--- 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,37 @@ 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,
+                       rss => 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},
@@ -47,6 +50,7 @@ sub getconfig () { #{{{
                        "wrappermode=i" => \$config{wrappermode},
                        "svn!" => \$config{svn},
                        "anonok!" => \$config{anonok},
+                       "rss!" => \$config{rss},
                        "cgi!" => \$config{cgi},
                        "url=s" => \$config{url},
                        "cgiurl=s" => \$config{cgiurl},
@@ -68,8 +72,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();
                }
        }
@@ -83,18 +87,21 @@ sub getconfig () { #{{{
 
 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;
        }
 } #}}}
@@ -107,10 +114,6 @@ sub error ($) { #{{{
        die @_;
 } #}}}
 
-sub usage () { #{{{
-       die "usage: ikiwiki [options] source dest\n";
-} #}}}
-
 sub possibly_foolish_untaint ($) { #{{{
        my $tainted=shift;
        my ($untainted)=$tainted=~/(.*)/;
@@ -236,6 +239,13 @@ sub isinlinableimage ($) { #{{{
        $file=~/\.(png|gif|jpg|jpeg)$/;
 } #}}}
 
+sub pagetitle ($) { #{{{
+       my $page=shift;
+       $page=~s/__(\d+)__/&#$1;/g;
+       $page=~y/_/ /;
+       return $page;
+} #}}}
+
 sub htmllink ($$;$$) { #{{{
        my $page=shift;
        my $link=shift;
@@ -250,7 +260,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 +272,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 +280,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 () { #{{{