From 6643db0cd20be4fdc6d06c767b079575e4e757f2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 30 Jun 2008 21:15:19 -0400 Subject: add support for an attachment upload field FormBuilder makes it annoyingly hard to move a submit button to a nonstandard place. The button name has to be "_submit" or FormBuilder will ignore it. --- templates/editpage.tmpl | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'templates') diff --git a/templates/editpage.tmpl b/templates/editpage.tmpl index b0bb0ecb9..36b616f5b 100644 --- a/templates/editpage.tmpl +++ b/templates/editpage.tmpl @@ -60,6 +60,11 @@ Optional comment about this change:
+ +

+Attach a file: +

+
-- cgit v1.2.3 From c1e9e121b738909a84eba8be327b5eaca74e7964 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 1 Jul 2008 17:19:38 -0400 Subject: basic attachment list --- IkiWiki/Plugin/attachment.pm | 51 ++++++++++++++++++++++++++++++++++++-------- templates/editpage.tmpl | 16 +++++++++++--- 2 files changed, 55 insertions(+), 12 deletions(-) (limited to 'templates') diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index 48cd954d9..1d392589e 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -15,12 +15,50 @@ sub checkconfig () { #{{{ $config{cgi_disable_uploads}=0; } #}}} +sub attachment_location ($) { + my $page=shift; + + # Put the attachment in a subdir of the page it's attached + # to, unless that page is an "index" page. + $page=~s/(^|\/)index//; + $page.="/" if length $page; + + return $page; +} + +sub attachment_list ($) { + my $loc=attachment_location(shift); + + my @ret; + foreach my $f (values %pagesources) { + print STDERR ">>$f\n" if ! defined IkiWiki::pagetype($f); + if (! defined IkiWiki::pagetype($f) && + $f=~m/^\Q$loc\E[^\/]+$/ && + -e "$config{srcdir}/$f") { + push @ret, { + "field-select" => '', + link => $f, + size => (stat(_))[7], + mtime => displaytime($IkiWiki::pagemtime{$f}), + }; + } + } + + return @ret; +} + sub formbuilder_setup (@) { #{{{ my %params=@_; my $form=$params{form}; if ($form->field("do") eq "edit") { $form->field(name => 'attachment', type => 'file'); + $form->tmpl_param("attachment_list" => [attachment_list($form->field('page'))]); + + # These buttons are not put in the usual place, so + # is not added to the normal formbuilder button list. + $form->tmpl_param("field-upload" => ''); + $form->tmpl_param("field-link" => ''); } elsif ($form->title eq "preferences") { my $session=$params{session}; @@ -66,15 +104,10 @@ sub formbuilder (@) { #{{{ # of the temp file that CGI writes the upload to. my $tempfile=$q->tmpFileName($filename); - # Put the attachment in a subdir of the page it's attached - # to, unless that page is an "index" page. - my $page=$form->field('page'); - $page=~s/(^|\/)index//; - $filename=(length $page ? $page."/" : "").IkiWiki::basename($filename); - - # To untaint the filename, escape any hazardous characters, - # and make sure it isn't pruned. - $filename=IkiWiki::titlepage(IkiWiki::possibly_foolish_untaint($filename)); + $filename=IkiWiki::titlepage( + IkiWiki::possibly_foolish_untaint( + attachment_location($form->field('page')). + IkiWiki::basename($filename))); if (IkiWiki::file_pruned($filename, $config{srcdir})) { error(gettext("bad attachment filename")); } diff --git a/templates/editpage.tmpl b/templates/editpage.tmpl index 36b616f5b..1a27beb6f 100644 --- a/templates/editpage.tmpl +++ b/templates/editpage.tmpl @@ -61,9 +61,19 @@ Optional comment about this change:
-

-Attach a file: -

+
+
+ + + + + + + + + +
Attachments
+
-- cgit v1.2.3 From d593533af58d5133ef6ecfc4323e3e1d55d71c48 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 2 Jul 2008 15:42:32 -0400 Subject: attachments interface visibility toggling --- IkiWiki/Plugin/attachment.pm | 17 ++++++++++++++++- templates/editpage.tmpl | 8 +++++--- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'templates') diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index ae06922d4..a58f696eb 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -18,6 +18,7 @@ sub checkconfig () { #{{{ sub formbuilder_setup (@) { #{{{ my %params=@_; my $form=$params{form}; + my $q=$params{cgi}; if ($form->field("do") eq "edit") { $form->field(name => 'attachment', type => 'file'); @@ -25,6 +26,20 @@ sub formbuilder_setup (@) { #{{{ # are not added to the normal formbuilder button list. $form->tmpl_param("field-upload" => ''); $form->tmpl_param("field-link" => ''); + + # Add the javascript from the toggle plugin; + # the attachments interface uses it to toggle visibility. + require IkiWiki::Plugin::toggle; + $form->tmpl_param("javascript" => $IkiWiki::Plugin::toggle::javascript); + # Start with the attachments interface toggled invisible, + # but if it was used, keep it open. + if ($form->submitted ne "Upload Attachment" && + ! length $q->param("attachment_select")) { + $form->tmpl_param("attachments-class" => "toggleable"); + } + else { + $form->tmpl_param("attachments-class" => "toggleable-open"); + } } elsif ($form->title eq "preferences") { my $session=$params{session}; @@ -136,7 +151,7 @@ sub formbuilder (@) { #{{{ } $form->field(name => 'editcontent', value => $form->field('editcontent')."\n\n".$add, - force => 1); + force => 1) if length $add; } # Generate the attachment list only after having added any new diff --git a/templates/editpage.tmpl b/templates/editpage.tmpl index 1a27beb6f..fdb142c70 100644 --- a/templates/editpage.tmpl +++ b/templates/editpage.tmpl @@ -60,10 +60,10 @@ Optional comment about this change:
+Attachments -
-
- +
+
Attachments
@@ -86,3 +86,5 @@ Optional comment about this change:
+ + -- cgit v1.2.3 From 1289beb53ba11693cba6d74c5a7da5c29e7cf7fa Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 2 Jul 2008 16:08:48 -0400 Subject: xhtml fixes --- IkiWiki/Plugin/attachment.pm | 2 +- templates/editpage.tmpl | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'templates') diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index a58f696eb..c1d1d1c60 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -180,7 +180,7 @@ sub attachment_list ($) { $f=~m/^\Q$loc\E[^\/]+$/ && -e "$config{srcdir}/$f") { push @ret, { - "field-select" => '', + "field-select" => '', link => htmllink($page, $page, $f, noimageinline => 1), size => humansize((stat(_))[7]), mtime => displaytime($IkiWiki::pagemtime{$f}), diff --git a/templates/editpage.tmpl b/templates/editpage.tmpl index fdb142c70..42d61c188 100644 --- a/templates/editpage.tmpl +++ b/templates/editpage.tmpl @@ -64,14 +64,13 @@ Optional comment about this change:
- + - + -
-- cgit v1.2.3 From edfbd7e1aa8f9f2cb789f45c0668a0d987e0b368 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 2 Jul 2008 16:14:18 -0400 Subject: toggle: Add javascript to top of page, not to end. This avoids flicker since closed toggles will not be displayed as the page is loading. --- IkiWiki/Plugin/toggle.pm | 4 ++-- debian/changelog | 2 ++ templates/editpage.tmpl | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'templates') diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm index f969d7686..284eb8249 100644 --- a/IkiWiki/Plugin/toggle.pm +++ b/IkiWiki/Plugin/toggle.pm @@ -108,9 +108,9 @@ sub format (@) { #{{{ if ($params{content}=~s!(
)
!$1!g) { $params{content}=~s/
//g; - if (! ($params{content}=~s!^<\/body>!$javascript!m)) { + if (! ($params{content}=~s!^!$javascript!m)) { # no tag, probably in preview mode - $params{content}.=$javascript; + $params{content}=$javascript.$params{content}; } } return $params{content}; diff --git a/debian/changelog b/debian/changelog index 314415788..e6ffa17de 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ ikiwiki (2.52) UNRELEASED; urgency=low uploads by default. (An anti-DOS measure.) * toggle: Add support for toggles that are open by default. * toggle: Fix to work in preview mode. + * toggle: Add javascript to top of page, not to end. This avoids flicker + since closed toggles will not be displayed as the page is loading. -- Joey Hess Mon, 30 Jun 2008 19:56:28 -0400 diff --git a/templates/editpage.tmpl b/templates/editpage.tmpl index 42d61c188..f8eda1b47 100644 --- a/templates/editpage.tmpl +++ b/templates/editpage.tmpl @@ -1,3 +1,4 @@ +

Your changes conflict with other changes made to the page. @@ -85,5 +86,3 @@ Optional comment about this change:

- - -- cgit v1.2.3