From e41dd1e24e345c974fe4a070088f0d09d1b6ddac Mon Sep 17 00:00:00 2001 From: joey Date: Wed, 29 Mar 2006 03:18:21 +0000 Subject: [PATCH] html validation fixes: - escape & in urls (also clean up cgi url generation) - since markdown wraps inlined pages in

, close and re-open the paragraph tags when generating the embedded html - added XHTML 1.0 doctypes to templates - fixed
and
in templates - add an alt attribute to inline images, based on the WikiLink to the image. Allows things like [[my_image|img.png]] to customise alt text. --- IkiWiki/CGI.pm | 13 +++++++------ IkiWiki/Render.pm | 8 ++++---- doc/todo/html.mdwn | 31 +++++++++++++++++++++++++++++-- ikiwiki | 12 ++++++++++-- templates/blogpost.tmpl | 4 ++-- templates/editpage.tmpl | 12 +++++++----- templates/misc.tmpl | 2 ++ templates/page.tmpl | 8 +++++--- templates/recentchanges.tmpl | 8 +++++--- 9 files changed, 71 insertions(+), 27 deletions(-) diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 7c12bee5b..52da67b9a 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -144,12 +144,13 @@ sub cgi_signin ($$) { #{{{ $session->param("name", $form->field("name")); if (defined $form->field("do") && $form->field("do") ne 'signin') { - print $q->redirect( - "$config{cgiurl}?do=".$form->field("do"). - "&page=".$form->field("page"). - "&title=".$form->field("title"). - "&subpage=".$form->field("subpage"). - "&from=".$form->field("from"));; + print $q->redirect(cgiurl( + do => $form->field("do"), + page => $form->field("page"), + title => $form->field("title"), + subpage => $form->field("subpage"), + from => $form->field("from"), + )); } else { print $q->redirect($config{url}); diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index f897b9b13..1fc047a62 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -186,7 +186,7 @@ sub postprocess_html_inline { #{{{ $ret.=$template->output; } - return $ret; + return "

$ret

"; } #}}} sub genpage ($$$) { #{{{ @@ -202,10 +202,10 @@ sub genpage ($$$) { #{{{ filename => "$config{templatedir}/page.tmpl"); if (length $config{cgiurl}) { - $template->param(editurl => "$config{cgiurl}?do=edit&page=$page"); - $template->param(prefsurl => "$config{cgiurl}?do=prefs"); + $template->param(editurl => cgiurl(do => "edit", page => $page)); + $template->param(prefsurl => cgiurl(do => "prefs")); if ($config{rcs}) { - $template->param(recentchangesurl => "$config{cgiurl}?do=recentchanges"); + $template->param(recentchangesurl => cgiurl(do => "recentchanges")); } } diff --git a/doc/todo/html.mdwn b/doc/todo/html.mdwn index ba167ea62..cb77774b5 100644 --- a/doc/todo/html.mdwn +++ b/doc/todo/html.mdwn @@ -6,8 +6,35 @@ editing the [[templates]] BTW. Current problems: - * A doctype should be added: do we want XHTML 1.0 or HTML 4.01 Trans as default? - * If XHTML: In templates <hr> should become <hr\> etc. + * A doctype should be added: do we want XHTML 1.0 or HTML 4.01 Trans as + default? + + Need to choose a doctype that corresponds to what [[MarkDown]] + generates. For example, it does generate <hr /> + So xhml seems a good fit and I'm going to add that to the + templates. + + One consideration of course is that regular users might embed html + that uses deprecated presentational elements like <center>. + --[[Joey]] + + * If XHTML: In templates <hr> should become <hr /> etc. * Image wikilinks should provide an alt text (maybe '$filname wiki-image'?). + + Now it will be the text of the [[WikiLink]], which even allows + setting a custom alt text like this: \[[my_alt_text|image.png]] + --[[Joey]] + * &'s in (cgi-)url's must be escaped as &amp;. + + Fixed --[[Joey]] + * [ [inlinepage] ] gets wrapped in <p>...</p> which has a high chance of invalidating the page. + + Since markdown does this, the only way I can think to fix it is to + make the inlined page text start with </p> and end with + <p>. Ugly, and of course there could be problems with + markdown enclosing it in other spanning tags in some cases. + I've implemented this hack now. :-/ --[[Joey]] + +Test: [validate this page](http://validator.w3.org/check?url=referer) diff --git a/ikiwiki b/ikiwiki index 44a7abaf4..62a9767b9 100755 --- a/ikiwiki +++ b/ikiwiki @@ -259,6 +259,12 @@ sub titlepage ($) { #{{{ return $title; } #}}} +sub cgiurl (@) { #{{{ + my %params=@_; + + return $config{cgiurl}."?".join("&", map "$_=$params{$_}", keys %params); +} #}}} + sub htmllink ($$;$$$) { #{{{ my $page=shift; my $link=shift; @@ -286,13 +292,15 @@ sub htmllink ($$;$$$) { #{{{ $bestlink=htmlpage($bestlink); } if (! grep { $_ eq $bestlink } values %renderedfiles) { - return "?$linktext" + return " "create", page => $link, from =>$page). + "\">?$linktext" } $bestlink=File::Spec->abs2rel($bestlink, dirname($page)); if (! $noimageinline && isinlinableimage($bestlink)) { - return ""; + return "\"$linktext\""; } return "$linktext"; } #}}} diff --git a/templates/blogpost.tmpl b/templates/blogpost.tmpl index 5ded359a1..8e4bb6a7d 100644 --- a/templates/blogpost.tmpl +++ b/templates/blogpost.tmpl @@ -1,4 +1,4 @@ -


+
@@ -6,4 +6,4 @@ Add a new post titled:
-
+
diff --git a/templates/editpage.tmpl b/templates/editpage.tmpl index c1e7113b4..f77f45036 100644 --- a/templates/editpage.tmpl +++ b/templates/editpage.tmpl @@ -1,3 +1,5 @@ + <TMPL_VAR FORM-TITLE> @@ -16,18 +18,18 @@ confict and commit again to save your changes. -Page location:
+Page location:
-
+
-Optional comment about this change:
-
+Optional comment about this change:
+
-
+

Page preview:

diff --git a/templates/misc.tmpl b/templates/misc.tmpl index a8ee1684b..3e78c3162 100644 --- a/templates/misc.tmpl +++ b/templates/misc.tmpl @@ -1,3 +1,5 @@ + <TMPL_VAR TITLE> diff --git a/templates/page.tmpl b/templates/page.tmpl index 468361a9d..9cef35dc6 100644 --- a/templates/page.tmpl +++ b/templates/page.tmpl @@ -1,3 +1,5 @@ + <TMPL_VAR TITLE> @@ -25,11 +27,11 @@ Preferences 
-
+
-
+
-
+

Links: diff --git a/templates/recentchanges.tmpl b/templates/recentchanges.tmpl index b42975e95..4ab53b892 100644 --- a/templates/recentchanges.tmpl +++ b/templates/recentchanges.tmpl @@ -1,3 +1,5 @@ + <TMPL_VAR TITLE> @@ -6,7 +8,7 @@ / -


+
    @@ -17,13 +19,13 @@ (">diff) -
    +
    changed by : -
    +