* Add preview parameter to preprocesser calls, use this rather than the

previous ugly hack used to avoid writing rss feeds in previews.
* Fix the img plugin to avoid overwriting images in previews. Instead it
  does all the work to make sure the resizing works, and dummys up a resized
  image using width and height attributes.
* Also fixes img preview display, the links were wrong in preview before.
master
joey 2007-03-06 22:37:05 +00:00
parent 2f9d9c9ef5
commit 1202b4fd7b
7 changed files with 56 additions and 30 deletions

View File

@ -17,9 +17,7 @@ our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
displaytime will_render gettext displaytime will_render gettext
%config %links %renderedfiles %pagesources); %config %links %renderedfiles %pagesources);
our $VERSION = 1.02; # plugin interface version, next is ikiwiki version our $VERSION = 1.02; # plugin interface version, next is ikiwiki version
our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE our $version="1.45";my $installdir="/usr";
my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
# Optimisation. # Optimisation.
use Memoize; use Memoize;
memoize("abs2rel"); memoize("abs2rel");
@ -506,11 +504,17 @@ sub linkify ($$$) { #{{{
} #}}} } #}}}
my %preprocessing; my %preprocessing;
sub preprocess ($$$;$) { #{{{ our $preprocess_preview=0;
sub preprocess ($$$;$$) { #{{{
my $page=shift; # the page the data comes from my $page=shift; # the page the data comes from
my $destpage=shift; # the page the data will appear in (different for inline) my $destpage=shift; # the page the data will appear in (different for inline)
my $content=shift; my $content=shift;
my $scan=shift; my $scan=shift;
my $preview=shift;
# Using local because it needs to be set within any nested calls
# of this function.
local $preprocess_preview=$preview if defined $preview;
my $handle=sub { my $handle=sub {
my $escape=shift; my $escape=shift;
@ -562,6 +566,7 @@ sub preprocess ($$$;$) { #{{{
@params, @params,
page => $page, page => $page,
destpage => $destpage, destpage => $destpage,
preview => $preprocess_preview,
); );
$preprocessing{$page}--; $preprocessing{$page}--;
return $ret; return $ret;

View File

@ -396,12 +396,11 @@ sub cgi_editpage ($$) { #{{{
value => $content, force => 1); value => $content, force => 1);
$form->field(name => "comments", $form->field(name => "comments",
value => $comments, force => 1); value => $comments, force => 1);
$config{rss}=$config{atom}=0; # avoid preview writing a feed!
$form->tmpl_param("page_preview", $form->tmpl_param("page_preview",
htmlize($page, $type, htmlize($page, $type,
linkify($page, "", linkify($page, "",
preprocess($page, $page, preprocess($page, $page,
filter($page, $content))))); filter($page, $content), 0, 1))));
} }
else { else {
$form->tmpl_param("page_preview", ""); $form->tmpl_param("page_preview", "");

View File

@ -49,7 +49,6 @@ sub preprocess (@) { #{{{
my $outfile = "$config{destdir}/$dir/${w}x${h}-$base"; my $outfile = "$config{destdir}/$dir/${w}x${h}-$base";
$imglink = "$dir/${w}x${h}-$base"; $imglink = "$dir/${w}x${h}-$base";
will_render($params{page}, $imglink);
if (-e $outfile && (-M srcfile($file) >= -M $outfile)) { if (-e $outfile && (-M srcfile($file) >= -M $outfile)) {
$r = $im->Read($outfile); $r = $im->Read($outfile);
@ -62,8 +61,15 @@ sub preprocess (@) { #{{{
$r = $im->Resize(geometry => "${w}x${h}"); $r = $im->Resize(geometry => "${w}x${h}");
return "[[img failed to resize: $r]]" if $r; return "[[img failed to resize: $r]]" if $r;
my @blob = $im->ImageToBlob(); # don't actually write file in preview mode
writefile($imglink, $config{destdir}, $blob[0], 1); if (! $params{preview}) {
will_render($params{page}, $imglink);
my @blob = $im->ImageToBlob();
writefile($imglink, $config{destdir}, $blob[0], 1);
}
else {
$imglink = $file;
}
} }
} }
else { else {
@ -74,12 +80,19 @@ sub preprocess (@) { #{{{
add_depends($imglink, $params{page}); add_depends($imglink, $params{page});
return '<a href="'. my ($fileurl, $imgurl);
IkiWiki::abs2rel($file, IkiWiki::dirname($params{destpage})). if (! $params{preview}) {
'"><img src="'. $fileurl=IkiWiki::abs2rel($file, IkiWiki::dirname($params{destpage}));
IkiWiki::abs2rel($imglink, IkiWiki::dirname($params{destpage})). $imgurl=IkiWiki::abs2rel($imglink, IkiWiki::dirname($params{destpage}));
}
else {
$fileurl="$config{url}/$file";
$imgurl="$config{url}/$imglink";
}
return '<a href="'.$fileurl.'"><img src="'.$imgurl.
'" alt="'.$alt.'" width="'.$im->Get("width"). '" alt="'.$alt.'" width="'.$im->Get("width").
'" height="'.$im->Get("height").'" /></a>'; '" height="'.$im->Get("height").'" /></a>';
} #}}} } #}}}
1; 1

View File

@ -67,6 +67,7 @@ sub preprocess_inline (@) { #{{{
my $atom=($config{atom} && exists $params{atom}) ? yesno($params{atom}) : $config{atom}; my $atom=($config{atom} && exists $params{atom}) ? yesno($params{atom}) : $config{atom};
my $quick=exists $params{quick} ? yesno($params{quick}) : 0; my $quick=exists $params{quick} ? yesno($params{quick}) : 0;
my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick; my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick;
$feeds=0 if $params{preview};
if (! exists $params{show} && ! $archive) { if (! exists $params{show} && ! $archive) {
$params{show}=10; $params{show}=10;
} }

8
debian/changelog vendored
View File

@ -6,8 +6,14 @@ ikiwiki (1.45) UNRELEASED; urgency=low
* Add "template" option to inline plugin to allow for use of customised * Add "template" option to inline plugin to allow for use of customised
templates. templates.
* Add titlepage template for inline plugin. * Add titlepage template for inline plugin.
* Add preview parameter to preprocesser calls, use this rather than the
previous ugly hack used to avoid writing rss feeds in previews.
* Fix the img plugin to avoid overwriting images in previews. Instead it
does all the work to make sure the resizing works, and dummys up a resized
image using width and height attributes.
* Also fixes img preview display, the links were wrong in preview before.
-- Joey Hess <joeyh@debian.org> Tue, 6 Mar 2007 14:16:21 -0500 -- Joey Hess <joeyh@debian.org> Tue, 6 Mar 2007 16:41:53 -0500
ikiwiki (1.44) unstable; urgency=low ikiwiki (1.44) unstable; urgency=low

View File

@ -96,9 +96,11 @@ Each time the directive is processed, the referenced function (`preprocess`
in the example above) is called, and is passed named parameters. A "page" in the example above) is called, and is passed named parameters. A "page"
parameter gives the name of the page that embedded the preprocessor parameter gives the name of the page that embedded the preprocessor
directive, while a "destpage" parameter gives the name of the page the directive, while a "destpage" parameter gives the name of the page the
content is going to (different for inlined pages). All parameters included content is going to (different for inlined pages), and a "preview"
in the directive are included as named parameters as well. Whatever the parameter is set to a true value if the page is being previewed. All
function returns goes onto the page in place of the directive. parameters included in the directive are included as named parameters as
well. Whatever the function returns goes onto the page in place of the
directive.
Note that if the [[htmlscrubber]] is enabled, html in Note that if the [[htmlscrubber]] is enabled, html in
[[PreProcessorDirective]] output is sanitised, which may limit what your [[PreProcessorDirective]] output is sanitised, which may limit what your

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-03-02 21:27-0500\n" "POT-Creation-Date: 2007-03-06 17:08-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -29,28 +29,28 @@ msgstr ""
msgid "%s is not an editable page" msgid "%s is not an editable page"
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:428 ../IkiWiki/Plugin/brokenlinks.pm:24 #: ../IkiWiki/CGI.pm:427 ../IkiWiki/Plugin/brokenlinks.pm:24
#: ../IkiWiki/Plugin/inline.pm:171 ../IkiWiki/Plugin/opendiscussion.pm:17 #: ../IkiWiki/Plugin/inline.pm:172 ../IkiWiki/Plugin/opendiscussion.pm:17
#: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:97 #: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:97
#: ../IkiWiki/Render.pm:165 #: ../IkiWiki/Render.pm:165
msgid "discussion" msgid "discussion"
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:474 #: ../IkiWiki/CGI.pm:473
#, perl-format #, perl-format
msgid "creating %s" msgid "creating %s"
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:491 ../IkiWiki/CGI.pm:527 ../IkiWiki/CGI.pm:571 #: ../IkiWiki/CGI.pm:490 ../IkiWiki/CGI.pm:526 ../IkiWiki/CGI.pm:570
#, perl-format #, perl-format
msgid "editing %s" msgid "editing %s"
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:668 #: ../IkiWiki/CGI.pm:667
msgid "You are banned." msgid "You are banned."
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:700 #: ../IkiWiki/CGI.pm:699
msgid "login failed, perhaps you need to turn on cookies?" msgid "login failed, perhaps you need to turn on cookies?"
msgstr "" msgstr ""
@ -121,21 +121,21 @@ msgstr ""
msgid "Must specify url to wiki with --url when using --rss or --atom" msgid "Must specify url to wiki with --url when using --rss or --atom"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/inline.pm:102 #: ../IkiWiki/Plugin/inline.pm:103
#, perl-format #, perl-format
msgid "unknown sort type %s" msgid "unknown sort type %s"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/inline.pm:142 #: ../IkiWiki/Plugin/inline.pm:143
#, perl-format #, perl-format
msgid "nonexistant template %s" msgid "nonexistant template %s"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/inline.pm:179 ../IkiWiki/Render.pm:101 #: ../IkiWiki/Plugin/inline.pm:180 ../IkiWiki/Render.pm:101
msgid "Discussion" msgid "Discussion"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/inline.pm:394 #: ../IkiWiki/Plugin/inline.pm:395
msgid "RPC::XML::Client not found, not pinging" msgid "RPC::XML::Client not found, not pinging"
msgstr "" msgstr ""
@ -454,7 +454,7 @@ msgstr ""
#. translators: preprocessor directive name, #. translators: preprocessor directive name,
#. translators: the second a page name, the #. translators: the second a page name, the
#. translators: third a number. #. translators: third a number.
#: ../IkiWiki.pm:557 #: ../IkiWiki.pm:565
#, perl-format #, perl-format
msgid "%s preprocessing loop detected on %s at depth %i" msgid "%s preprocessing loop detected on %s at depth %i"
msgstr "" msgstr ""