X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/f9f38ae31c239ce2f44ea0ed2984295aac09ead3..a61cf7a0d4711054ec8d263ccd3eead5f87b52d8:/IkiWiki/CGI.pm?ds=sidebyside diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 155010a97..35c62ce3e 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -33,10 +33,9 @@ sub showform ($$$$) { #{{{ buttons => $buttons); }); } - else { - printheader($session); - print misctemplate($form->title, $form->render(submit => $buttons)); - } + + printheader($session); + print misctemplate($form->title, $form->render(submit => $buttons)); } sub redirect ($$) { #{{{ @@ -72,14 +71,10 @@ sub check_canedit ($$$;$) { #{{{ return $canedit; } #}}} -sub decode_form_utf8 ($) { #{{{ - my $form = shift; - foreach my $f ($form->field) { - next if Encode::is_utf8(scalar $form->field($f)); - $form->field(name => $f, - value => decode_utf8($form->field($f)), - force => 1, - ); +sub decode_cgi_utf8 ($) { #{{{ + my $cgi = shift; + foreach my $f ($cgi->param) { + $cgi->param($f, map { decode_utf8 $_ } $cgi->param($f)); } } #}}} @@ -151,6 +146,7 @@ sub cgi_signin ($$) { #{{{ my $q=shift; my $session=shift; + decode_cgi_utf8($q); eval q{use CGI::FormBuilder}; error($@) if $@; my $form = CGI::FormBuilder->new( @@ -174,8 +170,6 @@ sub cgi_signin ($$) { #{{{ $form->field(name => "do", type => "hidden", value => "signin", force => 1); - decode_form_utf8($form); - run_hooks(formbuilder_setup => sub { shift->(form => $form, cgi => $q, session => $session, buttons => $buttons); @@ -213,6 +207,7 @@ sub cgi_prefs ($$) { #{{{ needsignin($q, $session); + decode_cgi_utf8($q); eval q{use CGI::FormBuilder}; error($@) if $@; my $form = CGI::FormBuilder->new( @@ -238,8 +233,6 @@ sub cgi_prefs ($$) { #{{{ ); my $buttons=["Save Preferences", "Logout", "Cancel"]; - decode_form_utf8($form); - run_hooks(formbuilder_setup => sub { shift->(form => $form, cgi => $q, session => $session, buttons => $buttons); @@ -249,7 +242,7 @@ sub cgi_prefs ($$) { #{{{ $form->field(name => "email", size => 50, fieldset => "preferences"); $form->field(name => "subscriptions", size => 50, fieldset => "preferences", - comment => "(".htmllink("", "", "PageSpec", noimageinline => 1).")"); + comment => "(".htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).")"); $form->field(name => "banned_users", size => 50, fieldset => "admin"); @@ -304,6 +297,7 @@ sub cgi_editpage ($$) { #{{{ my @fields=qw(do rcsinfo subpage from page type editcontent comments); my @buttons=("Save Page", "Preview", "Cancel"); + decode_cgi_utf8($q); eval q{use CGI::FormBuilder}; error($@) if $@; my $form = CGI::FormBuilder->new( @@ -311,9 +305,6 @@ sub cgi_editpage ($$) { #{{{ fields => \@fields, charset => "utf-8", method => 'POST', - validate => { - editcontent => '/.+/', - }, required => [qw{editcontent}], javascript => 0, params => $q, @@ -324,8 +315,6 @@ sub cgi_editpage ($$) { #{{{ wikiname => $config{wikiname}, ); - decode_form_utf8($form); - run_hooks(formbuilder_setup => sub { shift->(form => $form, cgi => $q, session => $session, buttons => \@buttons); @@ -357,6 +346,7 @@ sub cgi_editpage ($$) { #{{{ $form->field(name => "rcsinfo", value => rcs_prepedit($file), force => 1); } + $form->field(name => "editcontent", validate => '/.*/'); } else { $type=$form->param('type'); @@ -372,6 +362,7 @@ sub cgi_editpage ($$) { #{{{ if (! $form->submitted) { $form->field(name => "rcsinfo", value => "", force => 1); } + $form->field(name => "editcontent", validate => '/.+/'); } $form->field(name => "do", type => 'hidden'); @@ -386,7 +377,9 @@ sub cgi_editpage ($$) { #{{{ $form->tmpl_param("can_commit", $config{rcs}); $form->tmpl_param("indexlink", indexlink()); $form->tmpl_param("helponformattinglink", - htmllink("", "", "HelpOnFormatting", noimageinline => 1)); + htmllink("", "", "ikiwiki/formatting", + noimageinline => 1, + linktext => "FormattingHelp")); $form->tmpl_param("baseurl", baseurl()); if ($form->submitted eq "Cancel") { @@ -551,6 +544,7 @@ sub cgi_editpage ($$) { #{{{ }); $content=~s/\r\n/\n/g; $content=~s/\r/\n/g; + $content.="\n" if $content !~ /\n$/; $config{cgi}=0; # avoid cgi error message eval { writefile($file, $config{srcdir}, $content) }; @@ -596,6 +590,10 @@ sub cgi_editpage ($$) { #{{{ # may have been committed while the post-commit hook was # disabled. require IkiWiki::Render; + # Reload index, since the first time it's loaded is before + # the wiki is locked, and things may have changed in the + # meantime. + loadindex(); refresh(); saveindex();