From 87bcfe6debe478f58db9f5e7e7ce95fafa1d758f Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Wed, 1 Aug 2012 23:29:41 +0530 Subject: [PATCH] Links for information_schema --- libraries/DisplayResults.class.php | 134 +++++--- libraries/mysql_schema_relation.lib.php | 46 --- .../TextLinkTransformationsPlugin.class.php | 2 +- libraries/special_schema_links.lib.php | 323 ++++++++++++++++++ 4 files changed, 414 insertions(+), 91 deletions(-) delete mode 100644 libraries/mysql_schema_relation.lib.php create mode 100644 libraries/special_schema_links.lib.php diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 27b6612c89..0674115400 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -67,11 +67,8 @@ class PMA_DisplayResults const ALL_ROWS = 'all'; const QUERY_TYPE_SELECT = 'SELECT'; - const MYSQL_SCHEMA = 'mysql'; - const USER_FIELD = 'user'; - const HOST_FIELD = 'host'; - const USER_TABLE = 'user'; - const DB_TABLE = 'db'; + const ROUTINE_PROCEDURE = 'procedure'; + const ROUTINE_FUNCTION = 'function'; // Declare global fields @@ -2691,8 +2688,9 @@ class PMA_DisplayResults $fields_meta = $this->__get('_fields_meta'); $highlight_columns = $this->__get('_highlight_columns'); $mime_map = $this->__get('_mime_map'); - $host = ''; - + + $row_info = $this->_getRowInfoForSpecialLinks($row, $col_order); + for ($j = 0; $j < $this->__get('_fields_cnt'); ++$j) { // assign $i with appropriate column order @@ -2816,46 +2814,14 @@ class PMA_DisplayResults } - // Check for the fields need to show as link in mysql schema - include_once 'libraries/mysql_schema_relation.lib.php'; + // Check for the predefined fields need to show as link in schemas + include_once 'libraries/special_schema_links.lib.php'; - // Host should initialize for create link to edit user privilages page - if ((strtolower($this->__get('_db')) == self::MYSQL_SCHEMA) - && (strtolower($meta->name) == self::HOST_FIELD) - ) { - $host = $row[$i]; - } - - if (isset($GLOBALS['mysql_schema_relation']) + if (isset($GLOBALS['special_schema_links']) && ($this->_isFieldNeedToLink(strtolower($meta->name))) - && (strtolower($this->__get('_db')) == self::MYSQL_SCHEMA) ) { - $linking_url_params = array(); - $link_relations = $GLOBALS['mysql_schema_relation'][strtolower($this->__get('_table'))][strtolower($meta->name)]; - - foreach ($link_relations['link_params'] as $link_param) { - - // If link param is an array, set the key and value - // from that array - if (is_array($link_param)) { - $linking_url_params[$link_param[0]] = $link_param[1]; - } else { - $linking_url_params[$link_param] = $row[$i]; - - // To create link to edit user privilages page - if ((strtolower($meta->name) == self::USER_FIELD) - && ((strtolower($this->__get('_table') == self::USER_TABLE)) - || (strtolower($this->__get('_table') == self::DB_TABLE))) - ) { - $linking_url_params['hostname'] = $host; - } - } - - } - - $linking_url = $link_relations['default_page'] - . PMA_generate_common_url($linking_url_params); + $linking_url = $this->_getSpecialLinkUrl($row[$i], $row_info, strtolower($meta->name)); include_once "libraries/plugins/transformations/Text_Plain_Link.class.php"; $transformation_plugin = new Text_Plain_Link(null); @@ -3085,13 +3051,93 @@ class PMA_DisplayResults * @return boolean */ private function _isFieldNeedToLink($field) { - if (! empty($GLOBALS['mysql_schema_relation'][strtolower($this->__get('_table'))][$field])) { + if (! empty($GLOBALS['special_schema_links'][strtolower($this->__get('_db'))][strtolower($this->__get('_table'))][$field])) { return true; } return false; } + + + /** + * Get link for display special schema links + * + * @param string $column_value column value + * @param array $row_info information about row + * @param string $field_name column name + * + * @return string generated link + */ + private function _getSpecialLinkUrl($column_value, $row_info, $field_name) + { + + $linking_url_params = array(); + $link_relations = $GLOBALS['special_schema_links'][strtolower($this->__get('_db'))][strtolower($this->__get('_table'))][$field_name]; + + if (! is_array($link_relations['link_param'])) { + $linking_url_params[$link_relations['link_param']] = $column_value; + } else { + // Consider only the case of creating link for column field + // sql query need to be pass as url param + $sql = 'SELECT `'.$column_value.'` FROM `'. $row_info[$link_relations['link_param'][1]] .'`.`'. $row_info[$link_relations['link_param'][2]] .'`'; + $linking_url_params[$link_relations['link_param'][0]] = $sql; + } + + if (! empty($link_relations['link_dependancy_params'])) { + foreach ($link_relations['link_dependancy_params'] as $new_param) { + + // If param_info is an array, set the key and value + // from that array + if (is_array($new_param['param_info'])) { + $linking_url_params[$new_param['param_info'][0]] = $new_param['param_info'][1]; + } else { + $linking_url_params[$new_param['param_info']] = $row_info[strtolower($new_param['column_name'])]; + + // Special case 1 - when executing routines, according + // to the type of the routine, url param changes + if (!empty($row_info['routine_type'])){ + if (strtolower($row_info['routine_type']) == self::ROUTINE_PROCEDURE) { + $linking_url_params['execute_routine'] = 1; + } else if (strtolower($row_info['routine_type']) == self::ROUTINE_FUNCTION) { + $linking_url_params['execute_dialog'] = 1; + } + } + } + + } + + } + + return $link_relations['default_page'] . PMA_generate_common_url($linking_url_params); + + } + + + /** + * Prepare row information for display special links + * + * @param array $row current row data + * @param array $col_order the column order + * + * @return array $row_info associative array with column nama -> value + */ + private function _getRowInfoForSpecialLinks($row, $col_order) + { + + $row_info = array(); + $fields_meta = $this->__get('_fields_meta'); + + for ($n = 0; $n < $this->__get('_fields_cnt'); ++$n) { + $m = $col_order ? $col_order[$n] : $n; + $row_info[strtolower($fields_meta[$m]->name)] = $row[$m]; + } + + return $row_info; + + } + + /** * Get url sql query without conditions to shorten URLs * diff --git a/libraries/mysql_schema_relation.lib.php b/libraries/mysql_schema_relation.lib.php deleted file mode 100644 index 3949e4ac8b..0000000000 --- a/libraries/mysql_schema_relation.lib.php +++ /dev/null @@ -1,46 +0,0 @@ - array( - 'db' => array( - 'link_params' => array('db'), - 'default_page' => 'index.php' - ), - 'user' => array( - 'link_params' => array('username'), - 'default_page' => 'server_privileges.php' - ) - - ), - 'proc' => array( - 'db' => array( - 'link_params' => array('db'), - 'default_page' => 'index.php' - ) - - ), - 'user' => array( - 'user' => array( - 'link_params' => array('username'), - 'default_page' => 'server_privileges.php' - ) - - ) -); - -?> diff --git a/libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php index 64eec4206a..947ad310f0 100644 --- a/libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php @@ -52,7 +52,7 @@ abstract class TextLinkTransformationsPlugin extends TransformationsPlugin 'string' => '' . (isset($options[1]) ? $options[1] : $buffer) . '' + . '" target="_new">' . (isset($options[1]) ? $options[1] : $buffer) . '' ); $buffer = PMA_transformation_global_html_replace( diff --git a/libraries/special_schema_links.lib.php b/libraries/special_schema_links.lib.php new file mode 100644 index 0000000000..d012f4b225 --- /dev/null +++ b/libraries/special_schema_links.lib.php @@ -0,0 +1,323 @@ + array( + * // Table name + * 'db' => array( + * // Column name + * 'user' => array( + * // Main url param (can be an array where represent sql) + * 'link_param' => 'username', + * // Other url params + * 'link_dependancy_params' => array( + * 0 => array( + * // URL parameter name + * // (can be array where url param has static value) + * 'param_info' => 'hostname', + * // Column name related to url param + * 'column_name' => 'host' + * ) + * ), + * // Page to link + * 'default_page' => 'server_privileges.php' + * ) + * ) + * ) + * ); + * + */ +$GLOBALS['special_schema_links'] = array( + 'mysql' => array( + 'db' => array( + 'db' => array( + 'link_param' => 'db', + 'default_page' => 'index.php' + ), + 'user' => array( + 'link_param' => 'username', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'hostname', + 'column_name' => 'host' + ) + ), + 'default_page' => 'server_privileges.php' + ) + ), + 'proc' => array( + 'db' => array( + 'link_param' => 'db', + 'default_page' => 'index.php' + ) + + ), + 'user' => array( + 'user' => array( + 'link_param' => 'username', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'hostname', + 'column_name' => 'host' + ) + ), + 'default_page' => 'server_privileges.php' + ) + + ) + ), + 'information_schema' => array( + 'columns' => array( + 'table_name' => array( + 'link_param' => 'table', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'table_schema' + ) + ), + 'default_page' => 'index.php' + ), + 'column_name' => array( + 'link_param' => array( + 'sql_query', + 'table_schema', + 'table_name' + ), + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'table_schema' + ), + 1 => array( + 'param_info' => 'table', + 'column_name' => 'table_name' + ) + ), + 'default_page' => 'index.php' + ) + ), + 'key_column_usage' => array( + 'table_name' => array( + 'link_param' => 'table', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'constraint_schema' + ) + ), + 'default_page' => 'index.php' + ), + 'column_name' => array( + 'link_param' => array( + 'sql_query', + 'table_schema', + 'table_name' + ), + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'table_schema' + ), + 1 => array( + 'param_info' => 'table', + 'column_name' => 'table_name' + ) + ), + 'default_page' => 'index.php' + ), + 'referenced_table_schema' => array( + 'link_param' => 'db', + 'default_page' => 'index.php' + ), + 'referenced_table_name' => array( + 'link_param' => 'table', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'referenced_table_schema' + ) + ), + 'default_page' => 'index.php' + ), + 'referenced_column_name' => array( + 'link_param' => array( + 'sql_query', + 'referenced_table_schema', + 'referenced_table_name' + ), + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'referenced_table_schema' + ), + 1 => array( + 'param_info' => 'table', + 'column_name' => 'referenced_table_name' + ) + ), + 'default_page' => 'index.php' + ) + ), + 'partitions' => array( + 'table_schema' => array( + 'link_param' => 'db', + 'default_page' => 'index.php' + ), + 'table_name' => array( + 'link_param' => 'table', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'table_schema' + ) + ), + 'default_page' => 'index.php' + ) + ), + 'processlist' => array( + 'db' => array( + 'link_param' => 'db', + 'default_page' => 'index.php' + ), + 'user' => array( + 'link_param' => 'username', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'hostname', + 'column_name' => 'host' + ) + ), + 'default_page' => 'server_privileges.php' + ) + ), + 'referential_constraints' => array( + 'constraint_schema' => array( + 'link_param' => 'db', + 'default_page' => 'index.php' + ), + 'unique_constraint_schema' => array( + 'link_param' => 'db', + 'default_page' => 'index.php' + ), + 'table_name' => array( + 'link_param' => 'table', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'constraint_schema' + ) + ), + 'default_page' => 'index.php' + ), + 'referenced_table_name' => array( + 'link_param' => 'table', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'constraint_schema' + ) + ), + 'default_page' => 'index.php' + ) + ), + 'routines' => array( + 'routine_name' => array( + 'link_param' => 'item_name', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'routine_schema' + ), + 1 => array( + 'param_info' => 'item_type', + 'column_name' => 'routine_type' + ) + ), + 'default_page' => 'db_routines.php' + ) + ), + 'schemata' => array( + 'schema_name' => array( + 'link_param' => 'db', + 'default_page' => 'index.php' + ) + ), + 'statistics' => array( + 'table_schema' => array( + 'link_param' => 'db', + 'default_page' => 'index.php' + ), + 'table_name' => array( + 'link_param' => 'table', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'table_schema' + ) + ), + 'default_page' => 'index.php' + ), + 'column_name' => array( + 'link_param' => array( + 'sql_query', + 'table_schema', + 'table_name' + ), + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'table_schema' + ), + 1 => array( + 'param_info' => 'table', + 'column_name' => 'table_name' + ) + ), + 'default_page' => 'index.php' + ) + ), + 'tables' => array( + 'table_name' => array( + 'link_param' => 'table', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'table_schema' + ) + ), + 'default_page' => 'index.php' + ) + ), + 'table_constraints' => array( + 'table_name' => array( + 'link_param' => 'table', + 'link_dependancy_params' => array( + 0 => array( + 'param_info' => 'db', + 'column_name' => 'table_schema' + ) + ), + 'default_page' => 'index.php' + ) + ) + ) +); + +?>