Перетворення

Примітка

You need to have configured the Зберігання конфігурації phpMyAdmin to use the transformations feature.

Вступ

To enable transformations, you have to set up the column_info table and the proper directives. Please see the Конфігурація 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.

Консультації про те, як ефективно використовувати перетворення, дивіться наш Link section на офіційній сторінці phpMyAdmin.

Використання

Go to the table structure page (reached by clicking on the „Structure“ link for a table). There click on «Change» (or the change icon) and there you will see the five transformation–related fields at the end of the line. They are called „Media type“, „Browser transformation“ and „Transformation options“.

  • The field „Media type“ is a drop-down field. Select the Media type that corresponds to the column’s contents. Please note that many transformations are inactive until a Media type is selected.
  • The field „Browser display 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.
  • Поле «Параметри трансформації відображення браузера» є вільним текстовим полем. Тут потрібно ввести специфічні параметри функції перетворення. Зазвичай перетворення можуть працювати з параметрами за замовчуванням, але загалом добре подивитися огляд, щоб побачити, які опції потрібні. Багато чого, як ENUM / SET-поля, ви повинні розділити кілька варіантів, використовуючи формат „a“, „b“, „c“,… (ПРИМІТКА ПРОБЛЕМИ БЕЗПЕКИ). Це тому, що внутрішні параметри будуть проаналізовані як масив, залишивши перше значення першим елементом масиву і так далі. Якщо ви хочете вказати набір символів MIME, ви можете визначити його у transformation_options. Ви повинні виставити це за межами попередньо визначених параметрів конкретного mime-перетворення, як останнє значення набору. Використовуйте формат «“; charset=XXX“». Якщо ви використовуєте перетворення, для якого ви можете вказати 2 опції, і ви хочете додати набір символів, введіть «“перший параметр“,“другий параметр“,“charset=us-ascii“». Можна, однак, використовувати параметри за замовчанням: «““,““,“charset =us-ascii“». Параметри за замовчанням можна налаштувати за допомогою $cfg['DefaultTransformations'].
  • „Input transformation“ is another drop-down menu that corresponds exactly with the instructions above for «Browser display transformation» except these these affect the data before insertion in to the database. These are most commonly used to either provide a specialized editor (for example, using the phpMyAdmin SQL editor interface) or selector (such as for uploading an image). It’s also possible to manipulate the data such as converting an IPv4 address to binary or parsing it through a regular expression.
  • Finally, „Input transformation options“ is the equivalent of the «Browser display transformation options» section above and is where optional and required parameters are entered.

Структура файлу

All specific transformations for mimetypes are defined through class files in the directory src/Plugins/Transformations/. Each of them extends a certain transformation abstract class declared in src/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 src/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:

  1. getMIMEType() і getMIMESubtype() в основному класі;
  2. getName(), getInfo() і applyTransformation() поширюється в абстрактному класі.

Методи getMIMEType(), getMIMESubtype() і getName() повертають ім’я типу MIME, MIME-підтип і перетворення відповідно. getInfo() повертає опис трансформації та можливі варіанти, які він може отримати і applyTransformation() метод, який виконує фактичну роботу модуля перетворення.

Please see the src/Plugins/Transformations/TEMPLATE and src/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.

Метод applyTransformation() завжди отримує три змінні:

  1. $buffer - Містить текст усередині стовпця. Це текст, який ви хочете перетворити.
  2. $options - Містить будь-які параметри, передані користувачем, до функції перетворення, як масив.
  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 Media type of the column (i.e. „text/plain“, „image/jpeg“ etc.)