Introduction
To enable transformations, you have to set up the column_info
table and the proper directives. Please see the Configuration on how to do so.
phpMyAdmin has two different types of transformations: browser display
transformations, which affect only how the data is shown when browsing
through phpMyAdmin; and input transformations, which affect a value
prior to being inserted through phpMyAdmin.
You can apply different transformations to the contents of each
column. Each transformation has options to define how it will affect the
stored data.
Say you have a column filename
which contains a filename. Normally
you would see in phpMyAdmin only this filename. Using display transformations
you can transform that filename into a HTML link, so you can click
inside of the phpMyAdmin structure on the column’s link and will see
the file displayed in a new browser window. Using transformation
options you can also specify strings to append/prepend to a string or
the format you want the output stored in.
For a general overview of all available transformations and their
options, you can either go to the Change
link for an existing column
or from the dialog to create a new column, in either case there is a link
on that column structure page for “Browser display transformation” and
“Input transformation” which will show more information about each
transformation that is available on your system.
For a tutorial on how to effectively use transformations, see our
Link section on the
official phpMyAdmin homepage.
File structure
All specific transformations for mimetypes are defined through class
files in the directory libraries/classes/Plugins/Transformations/
. Each of
them extends a certain transformation abstract class declared in
libraries/classes/Plugins/Transformations/Abs
.
They are stored in files to ease customization and to allow easy adding of
new or custom transformations.
Because the user cannot enter their own mimetypes, it is kept certain that
the transformations will always work. It makes no sense to apply a
transformation to a mimetype the transform-function doesn’t know to
handle.
There is a file called libraries/classes/Plugins/Transformations.php
that provides some
basic functions which can be included by any other transform function.
The file name convention is [Mimetype]_[Subtype]_[Transformation
Name].php
, while the abstract class that it extends has the
name [Transformation Name]TransformationsPlugin
. All of the
methods that have to be implemented by a transformations plug-in are:
getMIMEType() and getMIMESubtype() in the main class;
getName(), getInfo() and applyTransformation() in the abstract class
it extends.
The getMIMEType(), getMIMESubtype() and getName() methods return the
name of the MIME type, MIME Subtype and transformation accordingly.
getInfo() returns the transformation’s description and possible
options it may receive and applyTransformation() is the method that
does the actual work of the transformation plug-in.
Please see the libraries/classes/Plugins/Transformations/TEMPLATE
and
libraries/classes/Plugins/Transformations/TEMPLATE_ABSTRACT
files for adding
your own transformation plug-in. You can also generate a new
transformation plug-in (with or without the abstract transformation
class), by using
scripts/transformations_generator_plugin.sh
or
scripts/transformations_generator_main_class.sh
.
The applyTransformation() method always gets passed three variables:
$buffer - Contains the text inside of the column. This is the
text, you want to transform.
$options - Contains any user-passed options to a transform
function as an array.
$meta - Contains an object with information about your column. The
data is drawn from the output of the mysql_fetch_field() function. This means, all
object properties described on the manual page are available in this
variable and can be used to transform a column accordingly to
unsigned/zerofill/not_null/… properties. The $meta->mimetype
variable contains the original Media type of the column (i.e.
‘text/plain’, ‘image/jpeg’ etc.)