]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/CGI.pm
Encode is used in nearly all code paths so stop loading it on demand
[ikiwiki.git] / IkiWiki / CGI.pm
index d9c9fe82896c8f5a52490ccb7be3147684ace455..73afe2468edaaa7c3c73fbb2cb427183e2a63ca9 100644 (file)
@@ -5,6 +5,7 @@ use strict;
 use IkiWiki;
 use IkiWiki::UserInfo;
 use encoding 'utf8'; # force use of utf8 for io layer
+use Encode;
 
 package IkiWiki;
 
@@ -33,14 +34,7 @@ sub cgi_recentchanges ($) { #{{{
        
        unlockwiki();
 
-       # Force reading the template as utf-8, necessary if
-       # rcs_recentchanges returns true utf-8 strings.
-       open(TMPL, "<:utf8", "$config{templatedir}/recentchanges.tmpl");
-       my $template=HTML::Template->new(filehandle => *TMPL);
-       close(TMPL);
-       my $template=HTML::Template->new(
-               filename => "$config{templatedir}/recentchanges.tmpl"
-       );
+       my $template=template("recentchanges.tmpl"); 
        $template->param(
                title => "RecentChanges",
                indexlink => indexlink(),
@@ -75,7 +69,7 @@ sub cgi_signin ($$) { #{{{
                action => $config{cgiurl},
                header => 0,
                template => (-e "$config{templatedir}/signin.tmpl" ?
-                             "$config{templatedir}/signin.tmpl" : ""),
+                            {template_params("signin.tmpl")} : ""),
                stylesheet => styleurl(),
        );
        
@@ -188,9 +182,7 @@ sub cgi_signin ($$) { #{{{
                }
                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"),
@@ -242,7 +234,7 @@ sub cgi_prefs ($$) { #{{{
                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");
@@ -311,13 +303,14 @@ sub cgi_editpage ($$) { #{{{
                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 ($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");
@@ -360,12 +353,12 @@ sub cgi_editpage ($$) { #{{{
                require IkiWiki::Render;
                # Apparently FormBuilder doesn't not treat input as
                # utf-8, so decode from it.
-               require Encode;
                my $content = Encode::decode_utf8($form->field('editcontent'));
+               my $comments = Encode::decode_utf8($form->field('comments'));
                $form->field(name => "editcontent",
                                value => $content, force => 1);
                $form->field(name => "comments",
-                               value => Encode::decode_utf8($form->field('comments')), force => 1);
+                               value => $comments, force => 1);
                $form->tmpl_param("page_preview",
                        htmlize($config{default_pageext},
                                linkify($page, $page, $content)));
@@ -449,7 +442,6 @@ sub cgi_editpage ($$) { #{{{
                page_locked($page, $session);
                
                # Decode utf-8 since FormBuilder does not
-               require Encode;
                my $content=Encode::decode_utf8($form->field('editcontent'));
 
                $content=~s/\r\n/\n/g;
@@ -466,7 +458,7 @@ sub cgi_editpage ($$) { #{{{
                }
                if (defined $form->field('comments') &&
                    length $form->field('comments')) {
-                       $message.=Encode::decode_utf8(": ".$form->field('comments'));
+                       $message.=": ".Encode::decode_utf8($form->field('comments'));
                }
                
                if ($config{rcs}) {