Skip to content

Commit

Permalink
RFE-637: Custom field handlers (input transformations)
Browse files Browse the repository at this point in the history
Signed-off-by: Chirayu Chiripal <[email protected]>
  • Loading branch information
chirayuchiripal committed Jul 11, 2014
1 parent 43f3179 commit 1f324be
Show file tree
Hide file tree
Showing 66 changed files with 2,557 additions and 371 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ phpMyAdmin - ChangeLog
+ rfe #654 Range Search Capability
+ rfe #1490 Dynamic process list
+ rfe #1522 Drag and Drop SQL import
+ rfe #637 Custom Field Handlers

4.2.6.0 (not yet released)
- bug #4471 Undefined index warning with referenced column.
Expand Down
26 changes: 19 additions & 7 deletions doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ Server connection settings

* 'config' authentication (``$auth_type = 'config'``) is the plain old
way: username and password are stored in :file:`config.inc.php`.
* 'cookie' authentication mode (``$auth_type = 'cookie'``) allows you to
log in as any valid MySQL user with the help of cookies.
* 'cookie' authentication mode (``$auth_type = 'cookie'``) allows you to
log in as any valid MySQL user with the help of cookies.
* 'http' authentication allows you to log in as any
valid MySQL user via HTTP-Auth.
* 'signon' authentication mode (``$auth_type = 'signon'``) allows you to
Expand Down Expand Up @@ -601,13 +601,23 @@ Server connection settings
column\_info table has to have the three new columns 'mimetype',
'transformation', 'transformation\_options'.

Starting with release 4.3.0, a new input-oriented transformation system
is been introduced. Also, backward compatibilty code used in the old
transformations system was removed. As a result, an update to column\_info
table is necessary for previous transformations and the new input-oriented
transformation system to work. phpMyAdmin will upgrade it automatically
for you by analyzing your current column\_info table structure.
However, if something goes wrong with the auto-upgrade then you can
use the SQL script found in ``./examples/upgrade_column_info_4_3_0+.sql``
to upgrade it manually.


To allow the usage of this functionality:

* set up :config:option:`$cfg['Servers'][$i]['pmadb']` and the phpMyAdmin configuration storage
* put the table name in :config:option:`$cfg['Servers'][$i]['column\_info']` (e.g.
``pma__column_info``)
* to update your PRE-2.5.0 Column\_comments Table use this: and
* to update your PRE-2.5.0 Column\_comments table use this: and
remember that the Variable in :file:`config.inc.php` has been renamed from
:config:option:`$cfg['Servers'][$i]['column\_comments']` to
:config:option:`$cfg['Servers'][$i]['column\_info']`
Expand All @@ -618,6 +628,8 @@ Server connection settings
ADD `mimetype` VARCHAR( 255 ) NOT NULL,
ADD `transformation` VARCHAR( 255 ) NOT NULL,
ADD `transformation_options` VARCHAR( 255 ) NOT NULL;
* to update your PRE-4.3.0 Column\_info table manually use this
``./examples/upgrade_column_info_4_3_0+.sql`` SQL script.

.. _history:
.. config:option:: $cfg['Servers'][$i]['history']
Expand Down Expand Up @@ -730,9 +742,9 @@ Server connection settings
:default: ``''``

Since release 4.3.0 you can have a central list of columns per database.
You can add/remove columns to the list as per your requirement. These columns
You can add/remove columns to the list as per your requirement. These columns
in the central list will be available to use while you create a new column for
a table or create a table itself. You can select a column from central list
a table or create a table itself. You can select a column from central list
while creating a new column, it will save you from writing the same column definition
over again or from writing different names for similar column.

Expand All @@ -748,7 +760,7 @@ Server connection settings
:type: string
:default: ``''``

Since release 4.2.0 you can save and load query-by-example searches from the Database > Query panel.
Since release 4.2.0 you can save and load query-by-example searches from the Database > Query panel.

To allow the usage of this functionality:

Expand Down Expand Up @@ -1268,7 +1280,7 @@ Cookie authentication options
choice. It will be used internally by the AES algorithm: you won’t be
prompted for this passphrase. There is no maximum length for this secret.

.. note::
.. note::

The configuration is called blowfish_secret for historical reasons as
Blowfish algorithm was originally used to do the encryption.
Expand Down
29 changes: 19 additions & 10 deletions doc/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,14 @@ Please look at your ``./examples/`` directory, where you should find a
file called *create\_tables.sql*. (If you are using a Windows server,
pay special attention to :ref:`faq1_23`).

If you already had this infrastructure and upgraded to MySQL 4.1.2 or
newer, please use :file:`examples/upgrade_tables_mysql_4_1_2+.sql`
and then create new tables by importing
:file:`examples/create_tables.sql`.
If you already had this infrastructure and:

* upgraded to MySQL 4.1.2 or newer, please use
:file:`examples/upgrade_tables_mysql_4_1_2+.sql`.
* upgraded to phpMyAdmin 4.3.0 or newer from 2.5.0 or newer (<= 4.2.x),
please use :file:`examples/upgrade_column_info_4_3_0+.sql`.

and then create new tables by importing :file:`examples/create_tables.sql`.

You can use your phpMyAdmin to create the tables for you. Please be
aware that you may need special (administrator) privileges to create
Expand Down Expand Up @@ -301,6 +305,11 @@ version 5.x or newer and if you use the phpMyAdmin configuration storage, you
should run the :term:`SQL` script found in
:file:`examples/upgrade_tables_mysql_4_1_2+.sql`.

If you have upgraded your phpMyAdmin to 4.3.0 or newer from 2.5.0 or
newer (<= 4.2.x) and if you use the phpMyAdmin configuration storage, you
should run the :term:`SQL` script found in
:file:`examples/upgrade_column_info_4_3_0+.sql`.

.. index:: Authentication mode

.. _authentication_modes:
Expand Down Expand Up @@ -361,7 +370,7 @@ Cookie authentication mode
--------------------------

* Username and password are stored in cookies during the session and password
is deleted when it ends.
is deleted when it ends.
* With this mode, the user can truly log out of phpMyAdmin and log
back in with the same username.
* If you want to allow users to enter any hostname to connect (rather than only
Expand All @@ -381,11 +390,11 @@ Signon authentication mode
application to authenticate to phpMyAdmin to implement signle signon
solution.
* The other application has to store login information into session
data (see :config:option:`$cfg['Servers'][$i]['SignonSession']`) or you
data (see :config:option:`$cfg['Servers'][$i]['SignonSession']`) or you
need to implement script to return the credentials (see
:config:option:`$cfg['Servers'][$i]['SignonScript']`).
* When no credentials are available, the user is being redirected to
:config:option:`$cfg['Servers'][$i]['SignonURL']`, where you should handle
* When no credentials are available, the user is being redirected to
:config:option:`$cfg['Servers'][$i]['SignonURL']`, where you should handle
the login process.

The very basic example of saving credentials in a session is available as
Expand All @@ -400,8 +409,8 @@ in :file:`examples/openid.php`:
.. literalinclude:: ../examples/openid.php
:language: php

If you intend to pass the credentials using some other means than, you have to
implement wrapper in PHP to get that data and set it to
If you intend to pass the credentials using some other means than, you have to
implement wrapper in PHP to get that data and set it to
:config:option:`$cfg['Servers'][$i]['SignonScript']`. There is very minimal example
in :file:`examples/signon-script.php`:

Expand Down
2 changes: 2 additions & 0 deletions examples/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ CREATE TABLE IF NOT EXISTS `pma__column_info` (
`mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default '',
`transformation` varchar(255) NOT NULL default '',
`transformation_options` varchar(255) NOT NULL default '',
`input_transformation` varchar(255) NOT NULL default '',
`input_transformation_options` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`)
)
Expand Down
2 changes: 2 additions & 0 deletions examples/create_tables_drizzle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ CREATE TABLE IF NOT EXISTS `pma__column_info` (
`mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default '',
`transformation` varchar(255) NOT NULL default '',
`transformation_options` varchar(255) NOT NULL default '',
`input_transformation` varchar(255) NOT NULL default '',
`input_transformation_options` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`)
)
Expand Down
47 changes: 47 additions & 0 deletions examples/upgrade_column_info_4_3_0+.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-- -------------------------------------------------------------
-- SQL Commands to upgrade pmadb.pma__column_info table
-- for normal phpMyAdmin operation
--
-- This file is meant for use with phpMyAdmin 4.3.0 and above!
-- For older releases, please use create_tables.sql
--
-- Please don't forget to set up the table names in config.inc.php
--

-- --------------------------------------------------------

--
-- Database : `phpmyadmin`
--
USE `phpmyadmin`;

-- --------------------------------------------------------

--
-- Update table structure for table `pma__column_info`
--
UPDATE `pma__column_info`
SET `mimetype` = REPLACE(`mimetype`, 'octet-stream', 'octetstream');
UPDATE `pma__column_info`
SET `transformation` = REPLACE(REPLACE(`transformation`, '__', '_'), 'inc.php', 'class.php');
UPDATE `pma__column_info`
SET `transformation` = ''
WHERE `transformation` = '_';
UPDATE `pma__column_info`
SET `transformation` = CONCAT('output/', `transformation`)
WHERE `transformation` IN (
'application_octetstream_download.class.php',
'application_octetstream_hex.class.php',
'image_jpeg_inline.class.php',
'image_jpeg_link.class.php',
'image_png_inline.class.php',
'text_plain_bool2text.class.php',
'text_plain_dateformat.class.php',
'text_plain_external.class.php',
'text_plain_formatted.class.php',
'text_plain_imagelink.class.php',
'text_plain_sql.class.php'
);
ALTER TABLE `pma__column_info`
ADD `input_transformation` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
ADD `input_transformation_options` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '';
4 changes: 4 additions & 0 deletions js/makegrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,10 @@ function PMA_makegrid(t, enableResize, enableReorder, enableVisib, enableGridEdi
g.isCellEdited = false;
} else {
PMA_ajaxShowMessage(data.error, false);
if (!g.saveCellsAtOnce) {
$(g.t).find('.to_be_saved')
.removeClass('to_be_saved');
}
}
}
}); // end $.ajax()
Expand Down
28 changes: 28 additions & 0 deletions js/transformations/image_upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Image upload transformations plugin js
*
* @package PhpMyAdmin
*/

AJAX.registerOnload('transformations/image_upload.js', function() {
// Change thumbnail when image file is selected
// through file upload dialog
$('input.image-upload').on('change', function(event) {
if (this.files && this.files[0]) {
var reader = new FileReader();
var $input = $(this);
reader.onload = function (e) {
$input.prevAll('img').attr('src', e.target.result);
};
reader.readAsDataURL(this.files[0]);
}
});
});

/**
* Unbind all event handlers before tearing down a page
*/
AJAX.registerTeardown('transformations/image_upload.js', function() {
$('input.image-upload').off('change');
});
2 changes: 1 addition & 1 deletion libraries/DatabaseInterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,7 @@ public function nextResult($link = null)
if ($link === false) {
return false;
}
return $this->_extension->nextResult($link = null);
return $this->_extension->nextResult($link);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions libraries/DisplayResults.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2523,7 +2523,10 @@ private function _addClass(
$classes[] = 'truncated';
}

if ($transformation_plugin != $default_function) {
$mime_map = $this->__get('mime_map');
if ($transformation_plugin != $default_function
|| !empty($mime_map[$meta->name]['input_transformation'])
) {
$classes[] = 'transformed';
}

Expand Down Expand Up @@ -2866,7 +2869,7 @@ private function _getRowValues(
if (file_exists($include_file)) {

include_once $include_file;
$class_name = str_replace('.class.php', '', $file);
$class_name = PMA_getTransformationClassName($file);
// todo add $plugin_manager
$plugin_manager = null;
$transformation_plugin = new $class_name(
Expand Down
16 changes: 16 additions & 0 deletions libraries/Scripts.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ public function addFile($filename, $conditional_ie = false)
);
}

/**
* Add new files to the list of scripts
*
* @param array $filelist The array of file names
* @param bool $conditional_ie Whether to wrap the script tag in
* conditional comments for IE
*
* @return void
*/
public function addFiles($filelist, $conditional_ie = false)
{
foreach ($filelist as $filename) {
$this->addFile($filename, $conditional_ie);
}
}

/**
* Determines whether to fire up an onload event for a file
*
Expand Down
2 changes: 1 addition & 1 deletion libraries/Util.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ public static function getMessage(
$retval .= '</div>';
}

if ($cfg['ShowSQL'] == true && ! empty($sql_query)) {
if ($cfg['ShowSQL'] == true && ! empty($sql_query) && $sql_query !== ';') {
// Html format the query to be displayed
// If we want to show some sql code it is easiest to create it here
/* SQL-Parser-Analyzer */
Expand Down
14 changes: 10 additions & 4 deletions libraries/dbi/DBIDummy.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,21 @@
),
array(
'query' => 'SELECT `column_name`, `mimetype`, `transformation`,'
. ' `transformation_options` FROM `pmadb`.`column_info`'
. ' `transformation_options`, `input_transformation`,'
. ' `input_transformation_options`'
. ' FROM `pmadb`.`column_info`'
. ' WHERE `db_name` = \'pma_test\' AND `table_name` = \'table1\''
. ' AND ( `mimetype` != \'\' OR `transformation` != \'\''
. ' OR `transformation_options` != \'\')',
. ' OR `transformation_options` != \'\''
. ' OR `input_transformation` != \'\''
. ' OR `input_transformation_options` != \'\')',
'columns' => array(
'column_name', 'mimetype', 'transformation', 'transformation_options'
'column_name', 'mimetype', 'transformation', 'transformation_options',
'input_transformation', 'input_transformation_options'
),
'result' => array(
array('o', 'text/plain', 'sql'),
array('o', 'text/plain', 'sql', '', 'regex', '/pma/i'),
array('col', 't', 'o/p', '', 'i/p', '')
)
),
array(
Expand Down
Loading

0 comments on commit 1f324be

Please sign in to comment.