]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/CGI.pm
fix
[git.ikiwiki.info.git] / IkiWiki / CGI.pm
index 4f4c488762ee477245cb3ad79dc39ae449fdac59..3e4cbe4cf4a97598b42bf03fad16ff54b2269423 100644 (file)
@@ -4,6 +4,8 @@ use warnings;
 use strict;
 use IkiWiki;
 use IkiWiki::UserInfo;
 use strict;
 use IkiWiki;
 use IkiWiki::UserInfo;
+use open qw{:utf8 :std};
+use Encode;
 
 package IkiWiki;
 
 
 package IkiWiki;
 
@@ -32,9 +34,7 @@ sub cgi_recentchanges ($) { #{{{
        
        unlockwiki();
 
        
        unlockwiki();
 
-       my $template=HTML::Template->new(
-               filename => "$config{templatedir}/recentchanges.tmpl"
-       );
+       my $template=template("recentchanges.tmpl"); 
        $template->param(
                title => "RecentChanges",
                indexlink => indexlink(),
        $template->param(
                title => "RecentChanges",
                indexlink => indexlink(),
@@ -43,8 +43,7 @@ sub cgi_recentchanges ($) { #{{{
                styleurl => styleurl(),
                baseurl => "$config{url}/",
        );
                styleurl => styleurl(),
                baseurl => "$config{url}/",
        );
-       require Encode;
-       print $q->header(-charset=>'utf-8'), Encode::decode_utf8($template->output);
+       print $q->header(-charset=>'utf-8'), $template->output;
 } #}}}
 
 sub cgi_signin ($$) { #{{{
 } #}}}
 
 sub cgi_signin ($$) { #{{{
@@ -70,7 +69,7 @@ sub cgi_signin ($$) { #{{{
                action => $config{cgiurl},
                header => 0,
                template => (-e "$config{templatedir}/signin.tmpl" ?
                action => $config{cgiurl},
                header => 0,
                template => (-e "$config{templatedir}/signin.tmpl" ?
-                             "$config{templatedir}/signin.tmpl" : ""),
+                            {template_params("signin.tmpl")} : ""),
                stylesheet => styleurl(),
        );
        
                stylesheet => styleurl(),
        );
        
@@ -183,9 +182,7 @@ sub cgi_signin ($$) { #{{{
                }
                elsif ($form->submitted eq 'Mail Password') {
                        my $user_name=$form->field("name");
                }
                elsif ($form->submitted eq 'Mail Password') {
                        my $user_name=$form->field("name");
-                       my $template=HTML::Template->new(
-                               filename => "$config{templatedir}/passwordmail.tmpl"
-                       );
+                       my $template=template("passwordmail.tmpl");
                        $template->param(
                                user_name => $user_name,
                                user_password => userinfo_get($user_name, "password"),
                        $template->param(
                                user_name => $user_name,
                                user_password => userinfo_get($user_name, "password"),
@@ -237,7 +234,7 @@ sub cgi_prefs ($$) { #{{{
                params => $q,
                action => $config{cgiurl},
                template => (-e "$config{templatedir}/prefs.tmpl" ?
                params => $q,
                action => $config{cgiurl},
                template => (-e "$config{templatedir}/prefs.tmpl" ?
-                             "$config{templatedir}/prefs.tmpl" : ""),
+                            {template_params("prefs.tmpl")} : ""),
                stylesheet => styleurl(),
        );
        my @buttons=("Save Preferences", "Logout", "Cancel");
                stylesheet => styleurl(),
        );
        my @buttons=("Save Preferences", "Logout", "Cancel");
@@ -306,23 +303,27 @@ sub cgi_editpage ($$) { #{{{
                params => $q,
                action => $config{cgiurl},
                table => 0,
                params => $q,
                action => $config{cgiurl},
                table => 0,
-               template => "$config{templatedir}/editpage.tmpl"
+               template => {template_params("editpage.tmpl")},
        );
        my @buttons=("Save Page", "Preview", "Cancel");
        
        # This untaint is safe because titlepage removes any problimatic
        # characters.
        );
        my @buttons=("Save Page", "Preview", "Cancel");
        
        # This untaint is safe because titlepage removes any problimatic
        # characters.
-       my ($page)=titlepage(possibly_foolish_untaint(lc($form->param('page'))));
+       my ($page)=Encode::decode_utf8($form->param('page'));
+       $page=titlepage(possibly_foolish_untaint(lc($page)));
        if (! defined $page || ! length $page ||
            $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) {
                error("bad page name");
        }
        $page=lc($page);
        
        if (! defined $page || ! length $page ||
            $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) {
                error("bad page name");
        }
        $page=lc($page);
        
-       my $file=$page.$config{default_pageext};
+       my $file;
        if (exists $pagesources{lc($page)}) {
                $file=$pagesources{lc($page)};
        }
        if (exists $pagesources{lc($page)}) {
                $file=$pagesources{lc($page)};
        }
+       else {
+               $file=$page.".".$config{default_pageext};
+       }
        my $newfile=0;
        if (! -e "$config{srcdir}/$file") {
                $newfile=1;
        my $newfile=0;
        if (! -e "$config{srcdir}/$file") {
                $newfile=1;
@@ -353,12 +354,17 @@ sub cgi_editpage ($$) { #{{{
        }
        elsif ($form->submitted eq "Preview") {
                require IkiWiki::Render;
        }
        elsif ($form->submitted eq "Preview") {
                require IkiWiki::Render;
-               require Encode;
+               # Apparently FormBuilder doesn't not treat input as
+               # utf-8, so decode from it.
                my $content = Encode::decode_utf8($form->field('editcontent'));
                my $content = Encode::decode_utf8($form->field('editcontent'));
-               $form->field(name => "editcontent", value => $content, force => 1);
+               my $comments = Encode::decode_utf8($form->field('comments'));
+               $form->field(name => "editcontent",
+                               value => $content, force => 1);
+               $form->field(name => "comments",
+                               value => $comments, force => 1);
                $form->tmpl_param("page_preview",
                $form->tmpl_param("page_preview",
-                       Encode::decode_utf8(htmlize($config{default_pageext},
-                               linkify($page, $page, $content))));
+                       htmlize(pagetype($file),
+                               linkify($page, $page, $content)));
        }
        else {
                $form->tmpl_param("page_preview", "");
        }
        else {
                $form->tmpl_param("page_preview", "");
@@ -421,8 +427,7 @@ sub cgi_editpage ($$) { #{{{
                            ! length $form->field('editcontent')) {
                                my $content="";
                                if (exists $pagesources{lc($page)}) {
                            ! length $form->field('editcontent')) {
                                my $content="";
                                if (exists $pagesources{lc($page)}) {
-                                       require Encode;
-                                       $content=Encode::decode_utf8(readfile(srcfile($pagesources{lc($page)})));
+                                       $content=readfile(srcfile($pagesources{lc($page)}));
                                        $content=~s/\n/\r\n/g;
                                }
                                $form->field(name => "editcontent", value => $content,
                                        $content=~s/\n/\r\n/g;
                                }
                                $form->field(name => "editcontent", value => $content,
@@ -439,13 +444,16 @@ sub cgi_editpage ($$) { #{{{
                # save page
                page_locked($page, $session);
                
                # save page
                page_locked($page, $session);
                
-               my $content=$form->field('editcontent');
+               # Decode utf-8 since FormBuilder does not
+               my $content=Encode::decode_utf8($form->field('editcontent'));
+
                $content=~s/\r\n/\n/g;
                $content=~s/\r/\n/g;
                writefile($file, $config{srcdir}, $content);
                
                my $message="web commit ";
                $content=~s/\r\n/\n/g;
                $content=~s/\r/\n/g;
                writefile($file, $config{srcdir}, $content);
                
                my $message="web commit ";
-               if (length $session->param("name")) {
+               if (defined $session->param("name") && 
+                   length $session->param("name")) {
                        $message.="by ".$session->param("name");
                }
                else {
                        $message.="by ".$session->param("name");
                }
                else {
@@ -453,8 +461,7 @@ sub cgi_editpage ($$) { #{{{
                }
                if (defined $form->field('comments') &&
                    length $form->field('comments')) {
                }
                if (defined $form->field('comments') &&
                    length $form->field('comments')) {
-                       require Encode;
-                       $message.=Encode::decode_utf8(": ".$form->field('comments'));
+                       $message.=": ".Encode::decode_utf8($form->field('comments'));
                }
                
                if ($config{rcs}) {
                }
                
                if ($config{rcs}) {
@@ -473,6 +480,7 @@ sub cgi_editpage ($$) { #{{{
                                        force => 1);
                                $form->tmpl_param("page_conflict", 1);
                                $form->field("editcontent", value => $conflict, force => 1);
                                        force => 1);
                                $form->tmpl_param("page_conflict", 1);
                                $form->field("editcontent", value => $conflict, force => 1);
+                               $form->field(name => "comments", value => Encode::decode_utf8($form->field('comments')), force => 1);
                                $form->field("do", "edit)");
                                $form->tmpl_param("page_select", 0);
                                $form->field(name => "page", type => 'hidden');
                                $form->field("do", "edit)");
                                $form->tmpl_param("page_select", 0);
                                $form->field(name => "page", type => 'hidden');