]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Add preview parameter to preprocesser calls, use this rather than the
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Tue, 6 Mar 2007 22:37:05 +0000 (22:37 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Tue, 6 Mar 2007 22:37:05 +0000 (22:37 +0000)
  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.

IkiWiki.pm
IkiWiki/CGI.pm
IkiWiki/Plugin/img.pm
IkiWiki/Plugin/inline.pm
debian/changelog
doc/plugins/write.mdwn
po/ikiwiki.pot

index ed74ff85e65daff5e8c6c76be5b02ef3c0f4733e..763f24e6c72d638099a7f8a73f935049061efbba 100644 (file)
@@ -17,9 +17,7 @@ our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
                  displaytime will_render gettext
                  %config %links %renderedfiles %pagesources);
 our $VERSION = 1.02; # plugin interface version, next is ikiwiki version
                  displaytime will_render gettext
                  %config %links %renderedfiles %pagesources);
 our $VERSION = 1.02; # plugin interface version, next is ikiwiki version
-our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
-my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
-
+our $version="1.45";my $installdir="/usr";
 # Optimisation.
 use Memoize;
 memoize("abs2rel");
 # Optimisation.
 use Memoize;
 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 $destpage=shift; # the page the data will appear in (different for inline)
        my $content=shift;
        my $scan=shift;
        my $page=shift; # the page the data comes from
        my $destpage=shift; # the page the data will appear in (different for inline)
        my $content=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 $escape=shift;
 
        my $handle=sub {
                my $escape=shift;
@@ -562,6 +566,7 @@ sub preprocess ($$$;$) { #{{{
                                @params,
                                page => $page,
                                destpage => $destpage,
                                @params,
                                page => $page,
                                destpage => $destpage,
+                               preview => $preprocess_preview,
                        );
                        $preprocessing{$page}--;
                        return $ret;
                        );
                        $preprocessing{$page}--;
                        return $ret;
index cd6ddc0345350c79566dfbad5235b235ad4b0cac..8d86d8d3e2b2b415ac0d2e605ae538ee2aec2cef 100644 (file)
@@ -396,12 +396,11 @@ sub cgi_editpage ($$) { #{{{
                                value => $content, force => 1);
                $form->field(name => "comments",
                                value => $comments, force => 1);
                                value => $content, force => 1);
                $form->field(name => "comments",
                                value => $comments, force => 1);
-               $config{rss}=$config{atom}=0; # avoid preview writing a feed!
                $form->tmpl_param("page_preview",
                        htmlize($page, $type,
                        linkify($page, "",
                        preprocess($page, $page,
                $form->tmpl_param("page_preview",
                        htmlize($page, $type,
                        linkify($page, "",
                        preprocess($page, $page,
-                       filter($page, $content)))));
+                       filter($page, $content), 0, 1))));
        }
        else {
                $form->tmpl_param("page_preview", "");
        }
        else {
                $form->tmpl_param("page_preview", "");
index 2a6533e39aa357572cdb7cc939667927f3e9e2cd..9135c688fae77cd4d028941b095083213bb90035 100644 (file)
@@ -49,7 +49,6 @@ sub preprocess (@) { #{{{
 
                my $outfile = "$config{destdir}/$dir/${w}x${h}-$base";
                $imglink = "$dir/${w}x${h}-$base";
 
                my $outfile = "$config{destdir}/$dir/${w}x${h}-$base";
                $imglink = "$dir/${w}x${h}-$base";
-               will_render($params{page}, $imglink);
 
                if (-e $outfile && (-M srcfile($file) >= -M $outfile)) {
                        $r = $im->Read($outfile);
 
                if (-e $outfile && (-M srcfile($file) >= -M $outfile)) {
                        $r = $im->Read($outfile);
@@ -62,8 +61,15 @@ sub preprocess (@) { #{{{
                        $r = $im->Resize(geometry => "${w}x${h}");
                        return "[[img failed to resize: $r]]" if $r;
 
                        $r = $im->Resize(geometry => "${w}x${h}");
                        return "[[img failed to resize: $r]]" if $r;
 
-                       my @blob = $im->ImageToBlob();
-                       writefile($imglink, $config{destdir}, $blob[0], 1);
+                       # don't actually write file in preview mode
+                       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="'.
-               IkiWiki::abs2rel($file, IkiWiki::dirname($params{destpage})).
-               '"><img src="'.
-               IkiWiki::abs2rel($imglink, IkiWiki::dirname($params{destpage})).
+       my ($fileurl, $imgurl);
+       if (! $params{preview}) {
+               $fileurl=IkiWiki::abs2rel($file, 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").
                '" height="'.$im->Get("height").'" /></a>';
 } #}}}
 
                '" alt="'.$alt.'" width="'.$im->Get("width").
                '" height="'.$im->Get("height").'" /></a>';
 } #}}}
 
-1;
+1
index d49993e5f44a396c8891901ccea9053172659b5b..6656a821c9aa9aa3b8bc8e5dda7351a85cf3f1b1 100644 (file)
@@ -67,6 +67,7 @@ sub preprocess_inline (@) { #{{{
        my $atom=($config{atom} && exists $params{atom}) ? yesno($params{atom}) : $config{atom};
        my $quick=exists $params{quick} ? yesno($params{quick}) : 0;
        my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick;
        my $atom=($config{atom} && exists $params{atom}) ? yesno($params{atom}) : $config{atom};
        my $quick=exists $params{quick} ? yesno($params{quick}) : 0;
        my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick;
+       $feeds=0 if $params{preview};
        if (! exists $params{show} && ! $archive) {
                $params{show}=10;
        }
        if (! exists $params{show} && ! $archive) {
                $params{show}=10;
        }
index 34c36c06ee8133abe554819f5c4cd7a7f8d424d3..d266ee829788d674b1acd444ceec170dc2307c27 100644 (file)
@@ -6,8 +6,14 @@ ikiwiki (1.45) UNRELEASED; urgency=low
   * Add "template" option to inline plugin to allow for use of customised
     templates.
   * Add titlepage template for inline plugin.
   * Add "template" option to inline plugin to allow for use of customised
     templates.
   * Add titlepage template for inline plugin.
-
- -- Joey Hess <joeyh@debian.org>  Tue,  6 Mar 2007 14:16:21 -0500
+  * 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 16:41:53 -0500
 
 ikiwiki (1.44) unstable; urgency=low
 
 
 ikiwiki (1.44) unstable; urgency=low
 
index 889057e699fc7436049324bc7c42eb8c8ab2c05e..5547ae6999d5a70de49f01b70c2f650bc7396ebd 100644 (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"
 parameter gives the name of the page that embedded the preprocessor
 directive, while a "destpage" parameter gives the name of the page the
 in the example above) is called, and is passed named parameters. A "page"
 parameter gives the name of the page that embedded the preprocessor
 directive, while a "destpage" parameter gives the name of the page the
-content is going to (different for inlined pages). All 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.
+content is going to (different for inlined pages), and a "preview"
+parameter is set to a true value if the page is being previewed. All
+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
 [[PreProcessorDirective]] output is sanitised, which may limit what your
 
 Note that if the [[htmlscrubber]] is enabled, html in
 [[PreProcessorDirective]] output is sanitised, which may limit what your
index c49dc6b2d5254b5ffd834ec8ad92dccf845204cd..c15ec1fbefeddabdcf9abfcb62a55324d7779483 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\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"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -29,28 +29,28 @@ msgstr ""
 msgid "%s is not an editable page"
 msgstr ""
 
 msgid "%s is not an editable page"
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:428 ../IkiWiki/Plugin/brokenlinks.pm:24
-#: ../IkiWiki/Plugin/inline.pm:171 ../IkiWiki/Plugin/opendiscussion.pm:17
+#: ../IkiWiki/CGI.pm:427 ../IkiWiki/Plugin/brokenlinks.pm:24
+#: ../IkiWiki/Plugin/inline.pm:172 ../IkiWiki/Plugin/opendiscussion.pm:17
 #: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:97
 #: ../IkiWiki/Render.pm:165
 msgid "discussion"
 msgstr ""
 
 #: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:97
 #: ../IkiWiki/Render.pm:165
 msgid "discussion"
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:474
+#: ../IkiWiki/CGI.pm:473
 #, perl-format
 msgid "creating %s"
 msgstr ""
 
 #, perl-format
 msgid "creating %s"
 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
 msgid "editing %s"
 msgstr ""
 
 #, perl-format
 msgid "editing %s"
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:668
+#: ../IkiWiki/CGI.pm:667
 msgid "You are banned."
 msgstr ""
 
 msgid "You are banned."
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:700
+#: ../IkiWiki/CGI.pm:699
 msgid "login failed, perhaps you need to turn on cookies?"
 msgstr ""
 
 msgid "login failed, perhaps you need to turn on cookies?"
 msgstr ""
 
@@ -121,21 +121,21 @@ msgstr ""
 msgid "Must specify url to wiki with --url when using --rss or --atom"
 msgstr ""
 
 msgid "Must specify url to wiki with --url when using --rss or --atom"
 msgstr ""
 
-#: ../IkiWiki/Plugin/inline.pm:102
+#: ../IkiWiki/Plugin/inline.pm:103
 #, perl-format
 msgid "unknown sort type %s"
 msgstr ""
 
 #, perl-format
 msgid "unknown sort type %s"
 msgstr ""
 
-#: ../IkiWiki/Plugin/inline.pm:142
+#: ../IkiWiki/Plugin/inline.pm:143
 #, perl-format
 msgid "nonexistant template %s"
 msgstr ""
 
 #, perl-format
 msgid "nonexistant template %s"
 msgstr ""
 
-#: ../IkiWiki/Plugin/inline.pm:179 ../IkiWiki/Render.pm:101
+#: ../IkiWiki/Plugin/inline.pm:180 ../IkiWiki/Render.pm:101
 msgid "Discussion"
 msgstr ""
 
 msgid "Discussion"
 msgstr ""
 
-#: ../IkiWiki/Plugin/inline.pm:394
+#: ../IkiWiki/Plugin/inline.pm:395
 msgid "RPC::XML::Client not found, not pinging"
 msgstr ""
 
 msgid "RPC::XML::Client not found, not pinging"
 msgstr ""
 
@@ -454,7 +454,7 @@ msgstr ""
 #. translators: preprocessor directive name,
 #. translators: the second a page name, the
 #. translators: third a number.
 #. translators: preprocessor directive name,
 #. translators: the second a page name, the
 #. translators: third a number.
-#: ../IkiWiki.pm:557
+#: ../IkiWiki.pm:565
 #, perl-format
 msgid "%s preprocessing loop detected on %s at depth %i"
 msgstr ""
 #, perl-format
 msgid "%s preprocessing loop detected on %s at depth %i"
 msgstr ""