The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Konstrukt::Plugin::wiki::backend::image - Base class for image backends

SYNOPSIS

        use base 'Konstrukt::Plugin::wiki::backend::image';
        #overwrite the methods
        
        #note that you can use $self->backend_method() in the action methods as
        #only an instance of the backend class will be created and it will inherit your methods.
        

DESCRIPTION

Base class for a backend class that implements the backend functionality (store, retrieve, ...) for images (*.jpg, *.gif, *.png, ...).

This one is very similar to Konstrukt::Plugin::wiki::backend::file but adds some image-specific funtionality.

Includes the control/display code for managing images as it won't change with different backend types (DBI, file, ...). So the implementing backend class will inherit this code but must overwrite the data retrieval and update code.

Although currently only DBI-backends exist, it should be easy to develop other backends (e.g. file based).

Note that the name of the images will be normalized. All characters but letters, numbers, hyphens, parenthesis, brackets and dots will be replaced by underscores. Internally image names are case insensitive. So SomeImage.jpg will point to the same page as someimage.jpg.

METHODS

init

Initialization for this plugin.

If you overwrite this one in your implementation, make sure to call $self-SUPER::init(@_);> to let the base class (this class) also do its init work.

install

Installs the templates.

Parameters:

none

actions

See "actions" in Konstrukt::Plugin::wiki::backend for a description of this one.

Responsible for the actions to show manage images.

prepare

The served image content will of course be dynamic. Don't do anything here.

execute

This one will be called, when an image's content will be downloaded. It will retrieve the content from the backend and return it to the browser.

Parameters:

  • $tag - Reference to the tag (and its children) that shall be handled.

image_show

Will handle the action to show an information page for an image.

image_edit_show

Will handle the action to show the form to edit/upload an image.

image_edit

Will handle the action to update an image.

image_revision_list

Will handle the action to show the revision history of an image.

image_restore

Will handle the action to restore an image's content and/or description.

exists

This method will return true, if a specified image exists. It will return undef otherwise.

Must be overwritten by the implementing class.

Parameters:

  • $title - The title of the image

  • $revision - Optional: A specific revision of an image

revision

This method will return the latest revision number/number of revisions of a specified image. It will return undef if the specified image does not exist.

Must be overwritten by the implementing class.

Parameters:

  • $title - The title of the image

revisions

This method will return all revisions of the specified image as an array of hash references ordered by ascending revision numbers:

        [
                { revision => 1, description => 'foo', description_revision => 3, content_revision => 4, content => 1, author => 'bar', host => '123.123.123.123', year => 2005, month => 1, day => 1, hour => 0, => minute => 0 },
                { revision => 2, ...},
                ...
        ]
        

Will return undef, if the image doesn't exist.

Note that description_revision and content_revision may also be 0 if no content has been saved yet.

Must be overwritten by the implementing class.

Parameters:

  • $title - The title of the image

get_info

This method will return the image info as a hashref:

                { title => 'foo', revision => 7, description => 'some text', description_revision => 3, content_revision => 4, width, height, mimetype, author => 'foo', host => '123.123.123.123', year => 2005, month => 1, day => 1, hour => 0, => minute => 0 },

Will return undef, if the requested image doesn't exist.

Note that the description_revision and content_revision may also be 0 if no content has been saved yet.

If there is no content yet (content_revision == 0), the fields width, height and mimetype will be undefined/will not exist.

Must be overwritten by the implementing class.

Parameters:

  • $title - The title of the image

  • $revision - Optional: A specific revision of an image. When not specified, the latest revision will be returned.

get_content

This method will return the image content as a hashref:

                { content => 'binarydata', mimetype => 'image/jpg', width => 800, height => 600, original => 'boolean' }

Will return undef, if the requested image doesn't exist or there is no content yet.

Must be overwritten by the implementing class.

Parameters:

  • $title - The title of the image

  • $revision - Optional: A specific revision of an image's content (which). When not defined, the latest revision will be returned.

  • $width - Optional: Return a resized version of this image. The image should only be downscaled and not upscaled. When not defined, the original resolution will be used.

store

This method will add a new image (or new revision if the image already exists) to the store.

If the image already exists, you may also just add a new description or a new content for the image. Pass undef for the value, you don't want to change.

Will return -1 if no change has been made (which is the case, when no new content and no new description has been passed and the image already exists in the database).

Will return -2 if the passed content is no valid image file.

Will return true on successful update and undef on error.

Parameters:

  • $title - The title of the image

  • $store_description - True, if a new description should be stored. False, if the old one should be left.

  • $description - A description of this image. May be undef to reset (delete) the description for the new revision.

  • $store_content - True, if a new content should be stored. False, if the old one should be left.

  • $content - The (binary) content that should be stored. May be undef to reset (delete) the content for the new revision.

  • $mimetype - The MIME type of the image

  • $author - User id of the creator

  • $host - Internet address of the creator

restore

This method will restore a description and/or a content from a given image revision.

Will return -1 if no change has been made (which is the case, when the current data and the data, which should be restored, are the same). Will return true on successful update and undef on error.

Parameters:

  • $title - The title of the image

  • $revision - The revision from which the description will be restored.

  • $restore_description - True, when the description should be restored

  • $restore_content - True, when the content should be restored

  • $author - User id of the modifier

  • $host - Internet address of the modifier

AUTHOR

Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.

This document is free software. It is distributed under the same terms as Perl itself.

SEE ALSO

Konstrukt::Plugin, Konstrukt::Plugin, Konstrukt