]> sipb.mit.edu Git - ikiwiki.git/commitdiff
comments: instead of hard-coding mdwn, allow any supported page format
authorSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Thu, 11 Dec 2008 00:19:39 +0000 (00:19 +0000)
committerSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Thu, 11 Dec 2008 21:14:05 +0000 (21:14 +0000)
IkiWiki/Plugin/comments.pm
templates/comments_form.tmpl

index 13ced6ffd806d456e3549ca90d380dc7f36e56f8..b45a4a97b53edc707fa20cdc477c566da382a3e4 100644 (file)
@@ -22,7 +22,6 @@ sub import { #{{{
        hook(type => "htmlize", id => "_comment", call => \&htmlize);
        hook(type => "pagetemplate", id => "comments", call => \&pagetemplate);
        hook(type => "cgi", id => "comments", call => \&linkcgi);
-       IkiWiki::loadplugin("mdwn");
        IkiWiki::loadplugin("inline");
 } # }}}
 
@@ -243,7 +242,7 @@ sub sessioncgi ($$) { #{{{
 
        my @buttons = (POST_COMMENT, PREVIEW, CANCEL);
        my $form = CGI::FormBuilder->new(
-               fields => [qw{do sid page subject body}],
+               fields => [qw{do sid page subject body type}],
                charset => 'utf-8',
                method => 'POST',
                required => [qw{body}],
@@ -264,13 +263,26 @@ sub sessioncgi ($$) { #{{{
                });
        IkiWiki::decode_form_utf8($form);
 
+       my $type = $form->param('type');
+       if (defined $type && length $type && $IkiWiki::hooks{htmlize}{$type}) {
+               $type = possibly_foolish_untaint($type);
+       }
+       else {
+               $type = $config{default_pageext};
+       }
+       my @page_types;
+       if (exists $IkiWiki::hooks{htmlize}) {
+               @page_types = grep { !/^_/ } keys %{$IkiWiki::hooks{htmlize}};
+       }
+
        $form->field(name => 'do', type => 'hidden');
        $form->field(name => 'sid', type => 'hidden', value => $session->id,
                force => 1);
        $form->field(name => 'page', type => 'hidden');
        $form->field(name => 'subject', type => 'text', size => 72);
-       $form->field(name => 'body', type => 'textarea', rows => 5,
-               cols => 80);
+       $form->field(name => 'body', type => 'textarea', rows => 10);
+       $form->field(name => "type", value => $type, force => 1,
+               type => 'select', options => \@page_types);
 
        # The untaint is OK (as in editpage) because we're about to pass
        # it to file_pruned anyway
@@ -341,7 +353,7 @@ sub sessioncgi ($$) { #{{{
        my $anchor = "${comments_pagename}${i}";
 
        $body =~ s/"/\\"/g;
-       my $content = "[[!comment format=mdwn\n";
+       my $content = "[[!comment format=$type\n";
 
        # FIXME: handling of double quotes probably wrong?
        if (defined $session->param('name')) {
@@ -371,7 +383,7 @@ sub sessioncgi ($$) { #{{{
        # - this means that if they do, rocks fall and everyone dies
 
        if ($form->submitted eq PREVIEW) {
-               my $preview = IkiWiki::htmlize($location, $page, 'mdwn',
+               my $preview = IkiWiki::htmlize($location, $page, '_comment',
                                IkiWiki::linkify($page, $page,
                                        IkiWiki::preprocess($page, $page,
                                                IkiWiki::filter($location,
index 59c03b4f065943fed7d6fc10203272d99b4317fc..e798fcdde7339bf7ca745ef1d685b4706d38a3f8 100644 (file)
@@ -6,10 +6,11 @@
 <TMPL_VAR FIELD-PAGE>
 Subject: <TMPL_VAR FIELD-SUBJECT><br />
 <TMPL_VAR FIELD-BODY><br />
+Page type: <TMPL_VAR FIELD-TYPE><br />
 <TMPL_VAR FORM-SUBMIT><br />
 <TMPL_VAR HELPONFORMATTINGLINK><br />
-Formatting with Markdown and HTML are allowed.<br />
-IkiWiki directives ([[!directive]]) are <TMPL_UNLESS NAME="ALLOWDIRECTIVES">not </TMPL_UNLESS>allowed.<br />
+A subset of HTML is allowed.<br />
+IkiWiki directives ([[!directive]]) are <TMPL_UNLESS NAME="ALLOWDIRECTIVES">not </TMPL_UNLESS>allowed in comments on this wiki.<br />
 <TMPL_VAR NAME="FORM-END">
 
 <TMPL_IF NAME="PAGE_PREVIEW">