変換機能

注釈

You need to have configured the phpMyAdmin 環境保管領域 for using transformations feature.

はじめに

To enable transformations, you have to setup the column_info table and the proper directives. Please see the 設定 on how to do so.

カラムごとに別々の変換機能を適用できます。変換機能は各カラムの内容を取得してから、選択された機能に定義されている規則に従って変換を行うためです。

例えば、ファイル名を入れる「filename」というカラムがあるとします。ふつう phpMyAdmin ではこのファイル名しか表示されませんが、変換機能を使うと、このファイル名を HTML リンクに変換できます。phpMyAdmin システムの内部でそのカラムのリンクをクリックすると、新しいブラウザウインドウにそのファイルが表示されます。変換オプションを使えば、その文字列の前後に付け加える文字列や、出力を保存する形式も指定できます。

For a general overview of all available transformations and their options, you can consult your <www.your-host.com>/<your-install- dir>/transformation_overview.php installation.

For a tutorial on how to effectively use transformations, see our Link section on the official phpMyAdmin homepage.

Usage

Go to your tbl_structure.php page (i.e. reached through clicking on the ‘Structure’ link for a table). There click on “Change” (or change icon) and there you will see three new fields at the end of the line. They are called ‘MIME-type’, ‘Browser transformation’ and ‘Transformation options’.

  • 「MIME タイプ」項目はドロップダウンになっています。カラムの内容に対応した MIME タイプを選択してください。なお、MIME タイプを選択しないと変換機能は有効になりませんので注意ください。

  • The field ‘Browser transformation’ is a drop-down field. You can choose from a hopefully growing amount of pre-defined transformations. See below for information on how to build your own transformation. There are global transformations and mimetype-bound transformations. Global transformations can be used for any mimetype. They will take the mimetype, if necessary, into regard. Mimetype-bound transformations usually only operate on a certain mimetype. There are transformations which operate on the main mimetype (like ‘image’), which will most likely take the subtype into regard, and those who only operate on a specific subtype (like ‘image/jpeg’). You can use transformations on mimetypes for which the function was not defined for. There is no security check for you selected the right transformation, so take care of what the output will be like.
  • The field ‘Transformation options’ is a free-type textfield. You have to enter transform-function specific options here. Usually the transforms can operate with default options, but it is generally a good idea to look up the overview to see which options are necessary. Much like the ENUM/SET-Fields, you have to split up several options using the format ‘a’,’b’,’c’,...(NOTE THE MISSING BLANKS). This is because internally the options will be parsed as an array, leaving the first value the first element in the array, and so forth. If you want to specify a MIME character set you can define it in the transformation_options. You have to put that outside of the pre- defined options of the specific mime-transform, as the last value of the set. Use the format “’; charset=XXX’”. If you use a transform, for which you can specify 2 options and you want to append a character set, enter “‘first parameter’,’second parameter’,’charset=us-ascii’”. You can, however use the defaults for the parameters: “’‘,’‘,’charset =us-ascii’”. The default options can be configured using $cfg['DefaultTransformations']

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.

変換機能がファイルに保管されているのは、カスタマイズや新しい変換機能の追加を容易にするためです。

ユーザが独自の MIME タイプを入力することはできませんが、そのおかげで変換機能はいつでも確実に動作することができるのです。ある変換機能を未知の MIME タイプに適用しようとしても無駄です。変換関数は処理の方法を知らないためです。

There is a file called ‘transformations.lib.php‘ that provides some basic functions which can be included by any other transform function.

The file name convention is [Mimetype]_[Subtype]_[Transformation Name].class.php, while the abtract 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:

  1. getMIMEType() and getMIMESubtype() in the main class;
  2. 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:

  1. $buffer - Contains the text inside of the column. This is the text, you want to transform.
  2. $options - Contains any user-passed options to a transform function as an array.
  3. $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 MIME-type of the column (i.e. ‘text/plain’, ‘image/jpeg’ etc.)