Transformationen

Bemerkung

You need to have configured the phpMyAdmin-Konfigurationsspeicher to use the transformations feature.

Einführung

To enable transformations, you have to set up the column_info table and the proper directives. Please see the Konfiguration on how to do so.

phpMyAdmin besitzt zwei unterschiedliche Arten von Transformationen: Browser-Anzeigetransformationen, die nur beeinflussen, wie die Daten angezeigt werden, wenn sie durch phpMyAdmin abgerufen werden und Eingabe-Transformationen, die einen Wert beeinflussen, bevor sie über phpMyAdmin eingetragen werden. Sie können unterschiedliche Transformationen auf die Inhalte jeder Spalte anwenden. Jede Transformation besitzt Optionen um festzulegen, wie die gespeicherten Daten beeinflusst werden.

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.

Für einen allgemeinen Überblick aller verfügbaren Transformationen und ihrer Optionen können Sie entweder die Ändern-Verknüpfung einer vorhandenen Spalte, oder die im Dialog zur Erzeugung einer neue Spalte, verwenden. In jedem Fall gibt es eine Verknüpfung auf dieser Spaltenstrukturseite für „Browser-Anzeigetransformation“ und „Eingabetransformation“ die weitere Informationen zu jeder Transformation zeigt, die auf Ihrem System verfügbar ist.

Eine Anleitung, wie man Transformationen effektiv einsetzt, finden Sie auf der offiziellen phpMyAdmin-Homepage unter Link-Sektion.

Verbrauch

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.
  • 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.

Dateistruktur

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.

Die Dateinamenskonvention lautet [Mimetype]_[Subtype]_[Transformationsname].php, während die von ihr erweiterte abstract-Klasse den Namen [Transformationsname]TransformationsPlugin hat. Alle Methoden, die von einem Transformations-Plugin implementiert werden müssen, sind:

  1. getMIMEType() und getMIMESubtype() in der Hauptklasse;
  2. getName(), getInfo() und applyTransformation() in der erweiterten abstrakten Klasse.

Die Methoden getMIMEType(), getMIMESubtype() und getName() geben den Namen des MIME-Typs, des MIME-Subtyps und der Transformation entsprechend zurück. getInfo() gibt die Beschreibung der Transformation und mögliche Optionen zurück, die sie erhalten kann und applyTransformation() ist die Methode, die die eigentliche Arbeit des Transformations-Plugins ausführt.

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.

Die Methode applyTransformation() bekommt immer drei Variablen übergeben:

  1. $buffer - Enthält den Text in der Tabellenspalte. Das ist der Text den Sie verändern wollen.
  2. $options - Enthält alle vom Benutzer übergebenen Parameter für die Transformationsfunktion als Array.
  3. $meta - Enthält ein Objekt mit Informationen über die Spalte. Die Daten stammen aus der Ausgabe der Funktion mysql_fetch_field(). Das bedeutet, dass alle Objekteigenschaften, die auf der Handbuchseite beschrieben sind, in dieser Variable verfügbar sind und verwendet werden können, um eine Spalte entsprechend in unsigned/zerofill/not_null/…. Eigenschaften zu transformieren. Die Variable $meta->mimetype enthält den ursprünglichen Media type der Spalte (z.B. ‚text/plain‘, ‚image/jpeg‘ usw.)