转换

注解

要使用转换功能,您需要配置 phpMyAdmin配置存储

介绍

要开启转换功能,你必须设置好 column_info 表以及正确的指令。具体设置请见 设置 一节。

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.

假设你有一个存有文件名的字段 filename 。正常情况下你只能在 phpMyAdmin 中看到文件名。通过显示转换你可以将它们转换成一个 HTML 链接,你就能直接在 phpMyAdmin 中点击并在浏览器的新窗口中看到这个文件。使用转换选项,你还可以指定要追加/预处理的字符串,或者你希望输出结果的存储格式。

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.

为了更有效地使用转换器,请查阅官方主页上的 链接部分

使用方法

通过点击一张表的“结构”链接前往表格结构页面。点击“修改”(或修改图标)后你就能看到在最下方出现五个与转换相关的表单项。它们分别叫 媒体类型、’浏览器转换’ 和 ‘转换选项’ 。

  • 字段 ‘Media type’ 是一个下拉框。选择与字段内容一致的 Media type 类型。请注意如果没有选择任何 Media type 类型转换功能是不起作用的。
  • 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.
  • The field ‘Browser display 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'].
  • ‘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.

它们存储于文件中,方便自定义和添加新的或自定义转换器。

因为用户不能输入他们的类型,这将保证转换可以正常工作。但这不能避免设置一个转换函数无法处理的类型的问题。

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() 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 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.)