Links for information_schema

This commit is contained in:
Chanaka Indrajith 2012-08-01 23:29:41 +05:30
parent 9d8eed9c8f
commit 87bcfe6deb
4 changed files with 414 additions and 91 deletions

View File

@ -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
*

View File

@ -1,46 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
*
* @package PhpMyAdmin
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/**
* This global variable represent the details for generating links inside
* mysql schema.
* Major element represent a table
*
* This global variable has not modified anywhere
*/
$GLOBALS['mysql_schema_relation'] = array(
'db' => 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'
)
)
);
?>

View File

@ -52,7 +52,7 @@ abstract class TextLinkTransformationsPlugin extends TransformationsPlugin
'string' => '<a href="'
. PMA_linkURL((isset($options[0]) ? $options[0] : '') . $append_part)
. '" title="' . (isset($options[1]) ? $options[1] : '')
. '">' . (isset($options[1]) ? $options[1] : $buffer) . '</a>'
. '" target="_new">' . (isset($options[1]) ? $options[1] : $buffer) . '</a>'
);
$buffer = PMA_transformation_global_html_replace(

View File

@ -0,0 +1,323 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
*
* @package PhpMyAdmin
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/**
* This global variable represent the details for generating links inside
* special schemas like mysql, information_schema etc.
* Major element represent a schema.
* All the strings in this array represented in lower case
* This global variable has not modified anywhere
*
* Variable structure ex:
* $GLOBALS['special_schema_links'] = array(
* // Database name is the major element
* 'mysql' => 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'
)
)
)
);
?>