]> sipb.mit.edu Git - ikiwiki.git/commitdiff
Improved handling of wikilinks containing characters that are not allowed
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Wed, 29 Mar 2006 02:14:55 +0000 (02:14 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Wed, 29 Mar 2006 02:14:55 +0000 (02:14 +0000)
in filenames. Now converts to valid filenames automatically.

Note, need to --refresh your wiki after updating to this version, if you
use any pages with __nn__ in their names.

IkiWiki/CGI.pm
IkiWiki/Render.pm
doc/foo___40__1975-__41__.mdwn [deleted file]
doc/wikilink.mdwn
ikiwiki

index fb4fd4475e9fb90d6bd9fcbf28d14492079b0379..7c12bee5bdef4b091ab360d465a908acf01d39be 100644 (file)
@@ -294,8 +294,10 @@ sub cgi_editpage ($$) { #{{{
        );
        my @buttons=("Save Page", "Preview", "Cancel");
        
        );
        my @buttons=("Save Page", "Preview", "Cancel");
        
-       my ($page)=$form->param('page')=~/$config{wiki_file_regexp}/;
-       if (! defined $page || ! length $page || $page ne $q->param('page') ||
+       # This untaint is safe because titlepage removes any problimatic
+       # characters.
+       my ($page)=titlepage(possibly_foolish_untaint(lc($form->param('page'))));
+       if (! defined $page || ! length $page ||
            $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) {
                error("bad page name");
        }
            $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) {
                error("bad page name");
        }
@@ -364,7 +366,7 @@ sub cgi_editpage ($$) { #{{{
                                my $dir=$from."/";
                                $dir=~s![^/]+/$!!;
                                
                                my $dir=$from."/";
                                $dir=~s![^/]+/$!!;
                                
-                               if (length $form->param('subpage') ||
+                               if ((defined $form->param('subpage') && length $form->param('subpage')) ||
                                    $page eq 'discussion') {
                                        $best_loc="$from/$page";
                                }
                                    $page eq 'discussion') {
                                        $best_loc="$from/$page";
                                }
@@ -511,12 +513,8 @@ sub cgi () { #{{{
                cgi_prefs($q, $session);
        }
        elsif ($do eq 'blog') {
                cgi_prefs($q, $session);
        }
        elsif ($do eq 'blog') {
-               # munge page name to be valid, no matter what freeform text
-               # is entered
-               my $page=lc($q->param('title'));
-               $page=~y/ /_/;
-               $page=~s/([^-A-Za-z0-9_:+\/])/"__".ord($1)."__"/eg;
-               # if the page already exist, munge it to be unique
+               my $page=titlepage(lc($q->param('title')));
+               # if the page already exists, munge it to be unique
                my $from=$q->param('from');
                my $add="";
                while (exists $oldpagemtime{"$from/$page$add"}) {
                my $from=$q->param('from');
                my $add="";
                while (exists $oldpagemtime{"$from/$page$add"}) {
index 504edc843cc8d7e6693822659ac2477c39798d13..f897b9b1397f2dd5d810c5d589b87997de30960e 100644 (file)
@@ -9,8 +9,8 @@ sub linkify ($$) { #{{{
        my $page=shift;
 
        $content =~ s{(\\?)$config{wiki_link_regexp}}{
        my $page=shift;
 
        $content =~ s{(\\?)$config{wiki_link_regexp}}{
-               $2 ? ( $1 ? "[[$2|$3]]" : htmllink($page, $3, 0, 0, pagetitle($2)))
-                  : ( $1 ? "[[$3]]" :    htmllink($page, $3))
+               $2 ? ( $1 ? "[[$2|$3]]" : htmllink($page, titlepage($3), 0, 0, pagetitle($2)))
+                  : ( $1 ? "[[$3]]" :    htmllink($page, titlepage($3)))
        }eg;
        
        return $content;
        }eg;
        
        return $content;
@@ -325,7 +325,7 @@ sub findlinks ($$) { #{{{
 
        my @links;
        while ($content =~ /(?<!\\)$config{wiki_link_regexp}/g) {
 
        my @links;
        while ($content =~ /(?<!\\)$config{wiki_link_regexp}/g) {
-               push @links, lc($2);
+               push @links, titlepage($2);
        }
        # Discussion links are a special case since they're not in the text
        # of the page, but on its template.
        }
        # Discussion links are a special case since they're not in the text
        # of the page, but on its template.
diff --git a/doc/foo___40__1975-__41__.mdwn b/doc/foo___40__1975-__41__.mdwn
deleted file mode 100644 (file)
index 30d74d2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-test
\ No newline at end of file
index 25c7586130784126ac95b841220d64b7fcd47f8e..6051fe1206bf6a706b76c227084c0f46d392e9b0 100644 (file)
@@ -11,16 +11,6 @@ play when linking between [[SubPage]]s.
 WikiLinks can be entered in any case you like, the page they link to is
 always lowercased.
 
 WikiLinks can be entered in any case you like, the page they link to is
 always lowercased.
 
-While a WikiLink is limited to alphanumerics and only a few special
-charaters, it is possible to create page names containing other characters:
-
-* To display a page name with a space in it, use "\_" in the WikiLink, for
-  example, "\[[Multi\_Word\_Page\_Name]]". 
-* For any other special character, you can use "\_\__nnnn_\_\_" where
- _nnnn_ is the unicode character number. For example,
-  "\[[This\_page\_name\_is\_\_44\_\_\_uselessly\_\_44\_\_\_a\_complete\_sentence\_\_46\_\_]]"
-  Limiting use of this to when you really need it is a good idea.
-
 Note that if the file linked to by a WikiLink looks like an image, it will
 be displayed inline on the page.
 
 Note that if the file linked to by a WikiLink looks like an image, it will
 be displayed inline on the page.
 
diff --git a/ikiwiki b/ikiwiki
index 9e9c293544170cb61ed6a60310e7967496825098..44a7abaf46a438456be7c22c7e02345a2af1c65b 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -252,6 +252,13 @@ sub pagetitle ($) { #{{{
        return $page;
 } #}}}
 
        return $page;
 } #}}}
 
+sub titlepage ($) { #{{{
+       my $title=shift;
+       $title=~y/ /_/;
+       $title=~s/([^-A-Za-z0-9_:+\/])/"__".ord($1)."__"/eg;
+       return $title;
+} #}}}
+
 sub htmllink ($$;$$$) { #{{{
        my $page=shift;
        my $link=shift;
 sub htmllink ($$;$$$) { #{{{
        my $page=shift;
        my $link=shift;