From 9398f99503902ea7d8775c0eceb389cc273edd46 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 2 Jun 2012 22:41:39 +0530 Subject: [PATCH 01/10] Various coding style improvements --- libraries/header.inc.php | 4 ++- libraries/iconv_wrapper.lib.php | 20 ++++++------ libraries/import.lib.php | 56 +++++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/libraries/header.inc.php b/libraries/header.inc.php index 4f66d1256f..be455590a3 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -15,8 +15,10 @@ require_once 'libraries/Menu.class.php'; /** * Add recently used table and reload the navigation. * - * @param string $db Database name where the table is located. + * @param string $db Database name where the table is located. * @param string $table The table name + * + * @return void */ function PMA_addRecentTable($db, $table) { diff --git a/libraries/iconv_wrapper.lib.php b/libraries/iconv_wrapper.lib.php index ef2bd0d2ef..9bacffa82e 100644 --- a/libraries/iconv_wrapper.lib.php +++ b/libraries/iconv_wrapper.lib.php @@ -69,20 +69,20 @@ function PMA_aix_iconv_wrapper($in_charset, $out_charset, $str) : $out_charset); // Transform name of input character set (if found) - if (array_key_exists( - strtolower($in_charset), - $gnu_iconv_to_aix_iconv_codepage_map - ) - ) { + $in_charset_exisits = array_key_exists( + strtolower($in_charset), + $gnu_iconv_to_aix_iconv_codepage_map + ); + if ($in_charset_exisits) { $in_charset = $gnu_iconv_to_aix_iconv_codepage_map[strtolower($in_charset)]; } // Transform name of "plain" output character set (if found) - if (array_key_exists( - strtolower($out_charset_plain), - $gnu_iconv_to_aix_iconv_codepage_map - ) - ) { + $out_charset_plain_exists = array_key_exists( + strtolower($out_charset_plain), + $gnu_iconv_to_aix_iconv_codepage_map + ); + if ($out_charset_plain_exists) { $out_charset_plain = $gnu_iconv_to_aix_iconv_codepage_map[ strtolower($out_charset_plain)]; } diff --git a/libraries/import.lib.php b/libraries/import.lib.php index 1213881671..bdc396f0ed 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -20,7 +20,7 @@ require_once './libraries/check_user_privileges.lib.php'; define('PMA_CHK_DROP', 1); /** - * Check whether timeout is getting close + * Checks whether timeout is getting close * * @return boolean true if timeout is close * @access public @@ -42,7 +42,7 @@ function PMA_checkTimeout() } /** - * Detects what compression filse uses + * Detects what compression filse uses * * @param string $filepath filename to check * @@ -78,6 +78,7 @@ function PMA_detectCompression($filepath) * @param string $full query to display, this might be commented * @param bool $controluser whether to use control user for queries * + * @return void * @access public */ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) @@ -268,7 +269,8 @@ function PMA_importGetNextChunk($size = 32768) } if ($GLOBALS['import_file'] == 'none') { - // Well this is not yet supported and tested, but should return content of textarea + // Well this is not yet supported and tested, + // but should return content of textarea if (strlen($GLOBALS['import_text']) < $size) { $GLOBALS['finished'] = true; return $GLOBALS['import_text']; @@ -316,7 +318,9 @@ function PMA_importGetNextChunk($size = 32768) if (strncmp($result, "\xEF\xBB\xBF", 3) == 0) { $result = substr($result, 3); // UTF-16 BE, LE - } elseif (strncmp($result, "\xFE\xFF", 2) == 0 || strncmp($result, "\xFF\xFE", 2) == 0) { + } elseif (strncmp($result, "\xFE\xFF", 2) == 0 + || strncmp($result, "\xFF\xFE", 2) == 0 + ) { $result = substr($result, 2); } } @@ -792,7 +796,12 @@ function PMA_analyzeTable(&$table) /* Determine type of the current cell */ $curr_type = PMA_detectType($types[$i], $table[ROWS][$j][$i]); /* Determine size of the current cell */ - $sizes[$i] = PMA_detectSize($sizes[$i], $types[$i], $curr_type, $table[ROWS][$j][$i]); + $sizes[$i] = PMA_detectSize( + $sizes[$i], + $types[$i], + $curr_type, + $table[ROWS][$j][$i] + ); /** * If a type for this column has already been declared, @@ -810,7 +819,10 @@ function PMA_analyzeTable(&$table) $types[$i] = BIGINT; } } else if ($curr_type == INT) { - if ($types[$i] != VARCHAR && $types[$i] != DECIMAL && $types[$i] != BIGINT) { + if ($types[$i] != VARCHAR + && $types[$i] != DECIMAL + && $types[$i] != BIGINT + ) { $types[$i] = INT; } } @@ -855,8 +867,9 @@ $import_notice = null; * * @link http://wiki.phpmyadmin.net/pma/Import */ -function PMA_buildSQL($db_name, &$tables, &$analyses = null, &$additional_sql = null, $options = null) -{ +function PMA_buildSQL($db_name, &$tables, &$analyses = null, + &$additional_sql = null, $options = null +) { /* Take care of the options */ if (isset($options['db_collation'])&& ! is_null($options['db_collation'])) { $collation = $options['db_collation']; @@ -881,9 +894,11 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = null, &$additional_sql = if ($create_db) { if (PMA_DRIZZLE) { - $sql[] = "CREATE DATABASE IF NOT EXISTS " . PMA_backquote($db_name) . " COLLATE " . $collation; + $sql[] = "CREATE DATABASE IF NOT EXISTS " . PMA_backquote($db_name) + . " COLLATE " . $collation; } else { - $sql[] = "CREATE DATABASE IF NOT EXISTS " . PMA_backquote($db_name) . " DEFAULT CHARACTER SET " . $charset . " COLLATE " . $collation; + $sql[] = "CREATE DATABASE IF NOT EXISTS " . PMA_backquote($db_name) + . " DEFAULT CHARACTER SET " . $charset . " COLLATE " . $collation; } } @@ -922,9 +937,15 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = null, &$additional_sql = $pattern = '/CREATE [^`]*(TABLE)/'; $replacement = 'CREATE \\1 IF NOT EXISTS'; - /* Change CREATE statements to CREATE IF NOT EXISTS to support inserting into existing structures */ + /* Change CREATE statements to CREATE IF NOT EXISTS to support + * inserting into existing structures + */ for ($i = 0; $i < $additional_sql_len; ++$i) { - $additional_sql[$i] = preg_replace($pattern, $replacement, $additional_sql[$i]); + $additional_sql[$i] = preg_replace( + $pattern, + $replacement, + $additional_sql[$i] + ); /* Execute the resulting statements */ PMA_importRunQuery($additional_sql[$i], $additional_sql[$i]); } @@ -993,7 +1014,8 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = null, &$additional_sql = $num_cols = count($tables[$i][COL_NAMES]); $num_rows = count($tables[$i][ROWS]); - $tempSQLStr = "INSERT INTO " . PMA_backquote($db_name) . '.' . PMA_backquote($tables[$i][TBL_NAME]) . " ("; + $tempSQLStr = "INSERT INTO " . PMA_backquote($db_name) . '.' + . PMA_backquote($tables[$i][TBL_NAME]) . " ("; for ($m = 0; $m < $num_cols; ++$m) { $tempSQLStr .= PMA_backquote($tables[$i][COL_NAMES][$m]); @@ -1009,7 +1031,8 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = null, &$additional_sql = $tempSQLStr .= "("; for ($k = 0; $k < $num_cols; ++$k) { - // If fully formatted SQL, no need to enclose with aphostrophes, add shalshes etc. + // If fully formatted SQL, no need to enclose + // with aphostrophes, add shalshes etc. if ($analyses != null && isset($analyses[$i][FORMATTEDSQL][$col_count]) && $analyses[$i][FORMATTEDSQL][$col_count] == true @@ -1074,8 +1097,9 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = null, &$additional_sql = * A work in progress */ - /* Add the viewable structures from $additional_sql to $tables so they are also displayed */ - + /* Add the viewable structures from $additional_sql + * to $tables so they are also displayed + */ $view_pattern = '@VIEW `[^`]+`\.`([^`]+)@'; $table_pattern = '@CREATE TABLE IF NOT EXISTS `([^`]+)`@'; /* Check a third pattern to make sure its not a "USE `db_name`;" statement */ From 8ccb0953076bef8660566134393d7ed35ca4557e Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 2 Jun 2012 22:45:03 +0530 Subject: [PATCH 02/10] Wrap some long lines --- libraries/import.lib.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libraries/import.lib.php b/libraries/import.lib.php index bdc396f0ed..05aed11a83 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -333,16 +333,20 @@ function PMA_importGetNextChunk($size = 32768) * * This functions uses recursion to build the Excel column name. * - * The column number (1-26) is converted to the responding ASCII character (A-Z) and returned. + * The column number (1-26) is converted to the responding + * ASCII character (A-Z) and returned. * * If the column number is bigger than 26 (= num of letters in alfabet), - * an extra character needs to be added. To find this extra character, the number is divided by 26 - * and this value is passed to another instance of the same function (hence recursion). - * In that new instance the number is evaluated again, and if it is still bigger than 26, it is divided again - * and passed to another instance of the same function. This continues until the number is smaller than 26. - * Then the last called function returns the corresponding ASCII character to the function that called it. + * an extra character needs to be added. To find this extra character, + * the number is divided by 26 and this value is passed to another instance + * of the same function (hence recursion). In that new instance the number is + * evaluated again, and if it is still bigger than 26, it is divided again + * and passed to another instance of the same function. This continues until + * the number is smaller than 26. Then the last called function returns + * the corresponding ASCII character to the function that called it. * Each time a called function ends an extra character is added to the column name. - * When the first function is reached, the last character is addded and the complete column name is returned. + * When the first function is reached, the last character is addded and the complete + * column name is returned. * * @access public * @@ -1098,7 +1102,7 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = null, */ /* Add the viewable structures from $additional_sql - * to $tables so they are also displayed + * to $tables so they are also displayed */ $view_pattern = '@VIEW `[^`]+`\.`([^`]+)@'; $table_pattern = '@CREATE TABLE IF NOT EXISTS `([^`]+)`@'; From e0e21d8bfb3a7ef52f615e3fde61428cf7cb8317 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 2 Jun 2012 22:48:34 +0530 Subject: [PATCH 03/10] Fix docs --- libraries/import.lib.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/import.lib.php b/libraries/import.lib.php index 05aed11a83..6cf043ff55 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -348,11 +348,10 @@ function PMA_importGetNextChunk($size = 32768) * When the first function is reached, the last character is addded and the complete * column name is returned. * - * @access public - * - * @param int $num + * @param int $num the column number * * @return string The column's "Excel" name + * @access public */ function PMA_getColumnAlphaName($num) { From 92c3f58fe4c048b6eb868dabb7e45ae4f1d1c675 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 2 Jun 2012 22:55:58 +0530 Subject: [PATCH 04/10] Wrap some more long lines --- libraries/import.lib.php | 50 ++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/libraries/import.lib.php b/libraries/import.lib.php index 6cf043ff55..9cd0296563 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -94,7 +94,9 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) if ($skip_queries > 0) { $skip_queries--; } else { - if (!empty($import_run_buffer['sql']) && trim($import_run_buffer['sql']) != '') { + if (!empty($import_run_buffer['sql']) + && trim($import_run_buffer['sql']) != '' + ) { $max_sql_len = max($max_sql_len, strlen($import_run_buffer['sql'])); if (!$sql_query_disabled) { $sql_query .= $import_run_buffer['full']; @@ -124,11 +126,18 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) $display_query = ''; } $sql_query = $import_run_buffer['sql']; - // If a 'USE ' SQL-clause was found, set our current $db to the new one - list($db, $reload) = PMA_lookForUse($import_run_buffer['sql'], $db, $reload); + // If a 'USE ' SQL-clause was found, + // set our current $db to the new one + list($db, $reload) = PMA_lookForUse( + $import_run_buffer['sql'], + $db, + $reload + ); } elseif ($run_query) { if ($controluser) { - $result = PMA_query_as_controluser($import_run_buffer['sql']); + $result = PMA_query_as_controluser( + $import_run_buffer['sql'] + ); } else { $result = PMA_DBI_try_query($import_run_buffer['sql']); } @@ -137,7 +146,10 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) if (! isset($my_die)) { $my_die = array(); } - $my_die[] = array('sql' => $import_run_buffer['full'], 'error' => PMA_DBI_getError()); + $my_die[] = array( + 'sql' => $import_run_buffer['full'], + 'error' => PMA_DBI_getError() + ); $msg .= __('Error'); @@ -162,9 +174,14 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) $sql_query .= $msg . "\n"; } - // If a 'USE ' SQL-clause was found and the query succeeded, set our current $db to the new one + // If a 'USE ' SQL-clause was found and the query + // succeeded, set our current $db to the new one if ($result != false) { - list($db, $reload) = PMA_lookForUse($import_run_buffer['sql'], $db, $reload); + list($db, $reload) = PMA_lookForUse( + $import_run_buffer['sql'], + $db, + $reload + ); } if ($result != false @@ -190,7 +207,10 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) // the complete query in the textarea) if (! $go_sql && $run_query) { if (! empty($sql_query)) { - if (strlen($sql_query) > 50000 || $executed_queries > 50 || $max_sql_len > 1000) { + if (strlen($sql_query) > 50000 + || $executed_queries > 50 + || $max_sql_len > 1000 + ) { $sql_query = ''; $sql_query_disabled = true; } @@ -521,8 +541,9 @@ function PMA_getDecimalSize(&$cell) * * @todo Handle the error cases more elegantly */ -function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type, &$cell) -{ +function PMA_detectSize($last_cumulative_size, $last_cumulative_type, + $curr_type, &$cell +) { $curr_size = strlen((string)$cell); /** @@ -1054,7 +1075,9 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = null, } $tempSQLStr .= (($is_varchar) ? "'" : ""); - $tempSQLStr .= PMA_sqlAddSlashes((string)$tables[$i][ROWS][$j][$k]); + $tempSQLStr .= PMA_sqlAddSlashes( + (string) $tables[$i][ROWS][$j][$k] + ); $tempSQLStr .= (($is_varchar) ? "'" : ""); } @@ -1161,7 +1184,10 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = null, $num_tables = count($tables); for ($i = 0; $i < $num_tables; ++$i) { - $params = array('db' => (string)$db_name, 'table' => (string)$tables[$i][TBL_NAME]); + $params = array( + 'db' => (string) $db_name, + 'table' => (string) $tables[$i][TBL_NAME] + ); $tbl_url = 'sql.php' . PMA_generate_common_url($params); $tbl_struct_url = 'tbl_structure.php' . PMA_generate_common_url($params); $tbl_ops_url = 'tbl_operations.php' . PMA_generate_common_url($params); From 5018efbe86e4a5ff1fdfb7a9ff9fbddd69986ec7 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 2 Jun 2012 22:58:45 +0530 Subject: [PATCH 05/10] Space after exclamation mark to improve readability --- libraries/import.lib.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libraries/import.lib.php b/libraries/import.lib.php index 9cd0296563..028bd4af8f 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -52,7 +52,7 @@ function PMA_checkTimeout() function PMA_detectCompression($filepath) { $file = @fopen($filepath, 'rb'); - if (!$file) { + if (! $file) { return false; } $test = fread($file, 4); @@ -94,15 +94,15 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) if ($skip_queries > 0) { $skip_queries--; } else { - if (!empty($import_run_buffer['sql']) + if (! empty($import_run_buffer['sql']) && trim($import_run_buffer['sql']) != '' ) { $max_sql_len = max($max_sql_len, strlen($import_run_buffer['sql'])); - if (!$sql_query_disabled) { + if (! $sql_query_disabled) { $sql_query .= $import_run_buffer['full']; } - if (!$cfg['AllowUserDropDatabase'] - && !$is_superuser + if (! $cfg['AllowUserDropDatabase'] + && ! $is_superuser && preg_match('@^[[:space:]]*DROP[[:space:]]+(IF EXISTS[[:space:]]+)?DATABASE @i', $import_run_buffer['sql']) ) { $GLOBALS['message'] = PMA_Message::error(__('"DROP DATABASE" statements are disabled.')); @@ -112,13 +112,13 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) if ($run_query && $GLOBALS['finished'] && empty($sql) - && !$error - && ((!empty($import_run_buffer['sql']) + && ! $error + && ((! empty($import_run_buffer['sql']) && preg_match('/^[\s]*(SELECT|SHOW|HANDLER)/i', $import_run_buffer['sql'])) || ($executed_queries == 1)) ) { $go_sql = true; - if (!$sql_query_disabled) { + if (! $sql_query_disabled) { $complete_query = $sql_query; $display_query = $sql_query; } else { @@ -153,7 +153,7 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) $msg .= __('Error'); - if (!$cfg['IgnoreMultiSubmitErrors']) { + if (! $cfg['IgnoreMultiSubmitErrors']) { $error = true; return; } @@ -170,7 +170,7 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) $msg .= __('MySQL returned an empty result set (i.e. zero rows).'); } } - if (!$sql_query_disabled) { + if (! $sql_query_disabled) { $sql_query .= $msg . "\n"; } @@ -192,12 +192,12 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) } // end run query } // end if not DROP DATABASE // end non empty query - } elseif (!empty($import_run_buffer['full'])) { + } elseif (! empty($import_run_buffer['full'])) { if ($go_sql) { $complete_query .= $import_run_buffer['full']; $display_query .= $import_run_buffer['full']; } else { - if (!$sql_query_disabled) { + if (! $sql_query_disabled) { $sql_query .= $import_run_buffer['full']; } } @@ -220,7 +220,7 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) } // end buffer exists // Do we have something to push into buffer? - if (!empty($sql) || !empty($full)) { + if (! empty($sql) || ! empty($full)) { $import_run_buffer = array('sql' => $sql, 'full' => $full); } else { unset($GLOBALS['import_run_buffer']); @@ -422,7 +422,7 @@ function PMA_getColumnAlphaName($num) */ function PMA_getColumnNumberFromName($name) { - if (!empty($name)) { + if (! empty($name)) { $name = strtoupper($name); $num_chars = strlen($name); $column_number = 0; @@ -1066,7 +1066,7 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = null, if ($analyses != null) { $is_varchar = ($analyses[$i][TYPES][$col_count] === VARCHAR); } else { - $is_varchar = !is_numeric($tables[$i][ROWS][$j][$k]); + $is_varchar = ! is_numeric($tables[$i][ROWS][$j][$k]); } /* Don't put quotes around NULL fields */ @@ -1144,13 +1144,13 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = null, if (count($regs)) { for ($n = 0; $n < $num_tables; ++$n) { - if (!strcmp($regs[1], $tables[$n][TBL_NAME])) { + if (! strcmp($regs[1], $tables[$n][TBL_NAME])) { $inTables = true; break; } } - if (!$inTables) { + if (! $inTables) { $tables[] = array(TBL_NAME => $regs[1]); } } From fce68140bc37230d6d5957cb2d26697aca955116 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 2 Jun 2012 23:09:00 +0530 Subject: [PATCH 06/10] Protected variables should not be prefixed with underscore --- libraries/List_Database.class.php | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/libraries/List_Database.class.php b/libraries/List_Database.class.php index 56c9859e4f..f8a2ec0bea 100644 --- a/libraries/List_Database.class.php +++ b/libraries/List_Database.class.php @@ -34,31 +34,31 @@ class PMA_List_Database extends PMA_List * @var mixed database link resource|object to be used * @access protected */ - protected $_db_link = null; + protected $db_link = null; /** * @var mixed user database link resource|object * @access protected */ - protected $_db_link_user = null; + protected $db_link_user = null; /** * @var mixed controluser database link resource|object * @access protected */ - protected $_db_link_control = null; + protected $db_link_control = null; /** * @var boolean whether SHOW DATABASES is disabled or not * @access protected */ - protected $_show_databases_disabled = false; + protected $show_databases_disabled = false; /** * @var string command to retrieve databases from server * @access protected */ - protected $_command = null; + protected $command = null; /** * Constructor @@ -70,9 +70,9 @@ class PMA_List_Database extends PMA_List */ public function __construct($db_link_user = null, $db_link_control = null) { - $this->_db_link = $db_link_user; - $this->_db_link_user = $db_link_user; - $this->_db_link_control = $db_link_control; + $this->db_link = $db_link_user; + $this->db_link_user = $db_link_user; + $this->db_link_control = $db_link_control; parent::__construct(); $this->build(); @@ -106,31 +106,31 @@ class PMA_List_Database extends PMA_List */ protected function _retrieve($like_db_name = null) { - if ($this->_show_databases_disabled) { + if ($this->show_databases_disabled) { return array(); } if (null !== $like_db_name) { $command = "SHOW DATABASES LIKE '" . $like_db_name . "'"; - } elseif (null === $this->_command) { + } elseif (null === $this->command) { $command = str_replace( '#user#', $GLOBALS['cfg']['Server']['user'], $GLOBALS['cfg']['Server']['ShowDatabasesCommand'] ); - $this->_command = $command; + $this->command = $command; } else { - $command = $this->_command; + $command = $this->command; } - $database_list = PMA_DBI_fetch_result($command, null, null, $this->_db_link); + $database_list = PMA_DBI_fetch_result($command, null, null, $this->db_link); PMA_DBI_getError(); if ($GLOBALS['errno'] !== 0) { // failed to get database list, try the control user // (hopefully there is one and he has SHOW DATABASES right) - $this->_db_link = $this->_db_link_control; + $this->db_link = $this->db_link_control; $database_list = PMA_DBI_fetch_result( - $command, null, null, $this->_db_link + $command, null, null, $this->db_link ); PMA_DBI_getError(); @@ -140,7 +140,7 @@ class PMA_List_Database extends PMA_List // retrieve database list, the admin has to setup a control user or // allow SHOW DATABASES $GLOBALS['error_showdatabases'] = true; - $this->_show_databases_disabled = true; + $this->show_databases_disabled = true; } } @@ -192,7 +192,7 @@ class PMA_List_Database extends PMA_List $items = array(); foreach ($GLOBALS['cfg']['Server']['only_db'] as $each_only_db) { - if ($each_only_db === '*' && ! $this->_show_databases_disabled) { + if ($each_only_db === '*' && ! $this->show_databases_disabled) { // append all not already listed dbs to the list $items = array_merge( $items, array_diff($this->_retrieve(), $items) @@ -209,7 +209,7 @@ class PMA_List_Database extends PMA_List continue; } - if (! $this->_show_databases_disabled) { + if (! $this->show_databases_disabled) { $items = array_merge($items, $this->_retrieve($each_only_db)); continue; } From 5a64005dc8ffee01262cfcc81f589c8d9cce830a Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 2 Jun 2012 23:15:15 +0530 Subject: [PATCH 07/10] Protected methods should not be prefixed with underscore --- libraries/List_Database.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/List_Database.class.php b/libraries/List_Database.class.php index f8a2ec0bea..e95c74c648 100644 --- a/libraries/List_Database.class.php +++ b/libraries/List_Database.class.php @@ -83,7 +83,7 @@ class PMA_List_Database extends PMA_List * * @return void */ - protected function _checkHideDatabase() + protected function checkHideDatabase() { if (empty($GLOBALS['cfg']['Server']['hide_db'])) { return; @@ -104,7 +104,7 @@ class PMA_List_Database extends PMA_List * @return array * @todo we could also search mysql tables if all fail? */ - protected function _retrieve($like_db_name = null) + protected function retrieve($like_db_name = null) { if ($this->show_databases_disabled) { return array(); @@ -162,12 +162,12 @@ class PMA_List_Database extends PMA_List */ public function build() { - if (! $this->_checkOnlyDatabase()) { - $items = $this->_retrieve(); + if (! $this->checkOnlyDatabase()) { + $items = $this->retrieve(); $this->exchangeArray($items); } - $this->_checkHideDatabase(); + $this->checkHideDatabase(); } /** @@ -175,7 +175,7 @@ class PMA_List_Database extends PMA_List * * @return boolean false if there is no only_db, otherwise true */ - protected function _checkOnlyDatabase() + protected function checkOnlyDatabase() { if (is_string($GLOBALS['cfg']['Server']['only_db']) && strlen($GLOBALS['cfg']['Server']['only_db']) @@ -195,7 +195,7 @@ class PMA_List_Database extends PMA_List if ($each_only_db === '*' && ! $this->show_databases_disabled) { // append all not already listed dbs to the list $items = array_merge( - $items, array_diff($this->_retrieve(), $items) + $items, array_diff($this->retrieve(), $items) ); // there can only be one '*', and this can only be last break; @@ -210,7 +210,7 @@ class PMA_List_Database extends PMA_List } if (! $this->show_databases_disabled) { - $items = array_merge($items, $this->_retrieve($each_only_db)); + $items = array_merge($items, $this->retrieve($each_only_db)); continue; } @@ -441,7 +441,7 @@ class PMA_List_Database extends PMA_List * @deprecated * @return void */ - protected function _checkAgainstPrivTables() + protected function checkAgainstPrivTables() { // 1. get allowed dbs from the "mysql.db" table // User can be blank (anonymous user) From 955ad7c695ad53e5e18c1a0ca50c99dda44b2f67 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 2 Jun 2012 23:21:00 +0530 Subject: [PATCH 08/10] Fix docs --- libraries/List.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/List.class.php b/libraries/List.class.php index c707042b18..f87c89dfff 100644 --- a/libraries/List.class.php +++ b/libraries/List.class.php @@ -114,6 +114,7 @@ abstract class PMA_List extends ArrayObject /** * builds up the list * + * @return void */ abstract public function build(); } From bff981f893aa9537f11e530b547761c965ddda42 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 2 Jun 2012 23:30:57 +0530 Subject: [PATCH 09/10] Wrap some long lines --- libraries/transformations.lib.php | 35 +++++++++++++++++++----------- libraries/user_preferences.inc.php | 4 +++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/libraries/transformations.lib.php b/libraries/transformations.lib.php index e187d44757..a6517df8ce 100644 --- a/libraries/transformations.lib.php +++ b/libraries/transformations.lib.php @@ -6,10 +6,12 @@ * This file also provides basic functions to use in other plungins! * These are declared in the 'GLOBAL Plugin functions' section * - * Please use short and expressive names. For now, special characters which aren't allowed in + * Please use short and expressive names. + * For now, special characters which aren't allowed in * filenames or functions should not be used. * - * Please provide a comment for your function, what it does and what parameters are available. + * Please provide a comment for your function, + * what it does and what parameters are available. * * @package PhpMyAdmin */ @@ -18,7 +20,8 @@ if (! defined('PHPMYADMIN')) { } /** - * returns array of options from string with options separated by comma, removes quotes + * Returns array of options from string with options separated by comma, + * removes quotes * * * PMA_transformation_getOptions("'option ,, quoted',abd,'2,3',"); @@ -187,7 +190,9 @@ function PMA_getMIME($db, $table, $strict = false) AND ( `mimetype` != \'\'' . (!$strict ? ' OR `transformation` != \'\' OR `transformation_options` != \'\'' : '') . ')'; - return PMA_DBI_fetch_result($com_qry, 'column_name', null, $GLOBALS['controllink']); + return PMA_DBI_fetch_result( + $com_qry, 'column_name', null, $GLOBALS['controllink'] + ); } // end of the 'PMA_getMIME()' function /** @@ -275,14 +280,14 @@ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, * in $buffer, after performing a regular expression search and replace on * $buffer using $options['regex'] and $options['regex_replace']. * - * @param string $buffer text that will be replaced in $options['string'], - * after being formatted - * @param array $options the options required to format $buffer - * = array ( - * 'string' => 'string', // text containing "[__BUFFER__]" - * 'regex' => 'mixed', // the pattern to search for - * 'regex_replace' => 'mixed', // string or array of strings to replace with - * ); + * @param string $buffer text that will be replaced in $options['string'], + * after being formatted + * @param array $options the options required to format $buffer + * = array ( + * 'string' => 'string', // text containing "[__BUFFER__]" + * 'regex' => 'mixed', // the pattern to search for + * 'regex_replace' => 'mixed', // string or array of strings to replace with + * ); * * @return string containing the text with all the replacements */ @@ -293,7 +298,11 @@ function PMA_transformation_global_html_replace($buffer, $options = array()) } if (isset($options['regex']) && isset($options['regex_replace'])) { - $buffer = preg_replace('@' . str_replace('@', '\@', $options['regex']) . '@si', $options['regex_replace'], $buffer); + $buffer = preg_replace( + '@' . str_replace('@', '\@', $options['regex']) . '@si', + $options['regex_replace'], + $buffer + ); } // Replace occurences of [__BUFFER__] with actual text diff --git a/libraries/user_preferences.inc.php b/libraries/user_preferences.inc.php index be6f97a11e..50398ceac9 100644 --- a/libraries/user_preferences.inc.php +++ b/libraries/user_preferences.inc.php @@ -65,6 +65,8 @@ $msg->display(); $cfgRelation = PMA_getRelationsParam(); if (! $cfgRelation['userconfigwork']) { $msg = __('Your preferences will be saved for current session only. Storing them permanently requires %sphpMyAdmin configuration storage%s.'); - $msg = PMA_sanitize(sprintf($msg, '[a@./Documentation.html#linked-tables@_blank]', '[/a]')); + $msg = PMA_sanitize( + sprintf($msg, '[a@./Documentation.html#linked-tables@_blank]', '[/a]') + ); PMA_Message::notice($msg)->display(); } From 8fe94907282a157e3e5d3b63faebfa9df98b5420 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 2 Jun 2012 23:57:20 +0530 Subject: [PATCH 10/10] Various coding style fixes --- libraries/StorageEngine.class.php | 3 +- libraries/Theme_Manager.class.php | 9 ++++- libraries/sqlvalidator.lib.php | 11 +++-- libraries/tbl_replace_fields.inc.php | 4 +- libraries/tbl_select.lib.php | 60 ++++++++++++++-------------- 5 files changed, 50 insertions(+), 37 deletions(-) diff --git a/libraries/StorageEngine.class.php b/libraries/StorageEngine.class.php index 41d582e87f..d4e51dae6b 100644 --- a/libraries/StorageEngine.class.php +++ b/libraries/StorageEngine.class.php @@ -252,7 +252,8 @@ class PMA_StorageEngine if (isset($variables[$row['Variable_name']])) { $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']]; } elseif (! $like - && strpos(strtolower($row['Variable_name']), strtolower($this->engine)) !== 0) { + && strpos(strtolower($row['Variable_name']), strtolower($this->engine)) !== 0 + ) { continue; } $mysql_vars[$row['Variable_name']]['value'] = $row['Value']; diff --git a/libraries/Theme_Manager.class.php b/libraries/Theme_Manager.class.php index 0a83f42bd2..3aa286c119 100644 --- a/libraries/Theme_Manager.class.php +++ b/libraries/Theme_Manager.class.php @@ -293,13 +293,18 @@ class PMA_Theme_Manager // check for themes directory while (false !== ($PMA_Theme = readdir($handleThemes))) { // Skip non dirs, . and .. - if ($PMA_Theme == '.' || $PMA_Theme == '..' || ! is_dir($this->getThemesPath() . '/' . $PMA_Theme)) { + if ($PMA_Theme == '.' + || $PMA_Theme == '..' + || ! is_dir($this->getThemesPath() . '/' . $PMA_Theme) + ) { continue; } if (array_key_exists($PMA_Theme, $this->themes)) { continue; } - $new_theme = PMA_Theme::load($this->getThemesPath() . '/' . $PMA_Theme); + $new_theme = PMA_Theme::load( + $this->getThemesPath() . '/' . $PMA_Theme + ); if ($new_theme) { $new_theme->setId($PMA_Theme); $this->themes[$PMA_Theme] = $new_theme; diff --git a/libraries/sqlvalidator.lib.php b/libraries/sqlvalidator.lib.php index 0f5ed9e112..e6d6d5c992 100644 --- a/libraries/sqlvalidator.lib.php +++ b/libraries/sqlvalidator.lib.php @@ -49,11 +49,11 @@ if ($cfg['SQLValidator']['use'] == true) { * * * - * @param string SQL query to validate + * @param string $sql SQL query to validate * - * @return string Validator result string + * @return string Validator result string * - * @global array The PMA configuration array + * @global array The PMA configuration array */ function PMA_validateSQL($sql) { @@ -74,7 +74,10 @@ function PMA_validateSQL($sql) // The class defaults to anonymous with an empty password // automatically if ($cfg['SQLValidator']['username'] != '') { - $srv->setCredentials($cfg['SQLValidator']['username'], $cfg['SQLValidator']['password']); + $srv->setCredentials( + $cfg['SQLValidator']['username'], + $cfg['SQLValidator']['password'] + ); } // Identify ourselves to the server properly... diff --git a/libraries/tbl_replace_fields.inc.php b/libraries/tbl_replace_fields.inc.php index e5a33d4654..e410dbff0e 100644 --- a/libraries/tbl_replace_fields.inc.php +++ b/libraries/tbl_replace_fields.inc.php @@ -51,7 +51,9 @@ if (false !== $possibly_uploaded_val) { // $key contains the md5() of the fieldname if ($type != 'protected' && $type != 'set' && 0 === strlen($val)) { // best way to avoid problems in strict mode (works also in non-strict mode) - if (isset($multi_edit_auto_increment) && isset($multi_edit_auto_increment[$key])) { + if (isset($multi_edit_auto_increment) + && isset($multi_edit_auto_increment[$key]) + ) { $val = 'NULL'; } else { $val = "''"; diff --git a/libraries/tbl_select.lib.php b/libraries/tbl_select.lib.php index ae94346cde..757b94970c 100644 --- a/libraries/tbl_select.lib.php +++ b/libraries/tbl_select.lib.php @@ -414,18 +414,18 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, /** * Builds the sql search query from the post parameters * - * @param string $table Selected table - * @param array $fields Entered values of the columns - * @param array $criteriaColumnNames Names of all columns - * @param array $criteriaColumnTypes Types of all columns - * @param array $criteriaColumnCollations Collations of all columns - * @param array $criteriaColumnOperators Operators for given column type + * @param string $table Selected table + * @param array $fields Entered values of the columns + * @param array $criteriaColumnNames Names of all columns + * @param array $criteriaColumnTypes Types of all columns + * @param array $criteriaColumnCollations Collations of all columns + * @param array $criteriaColumnOperators Operators for given column type * * @return string the generated SQL query */ function PMA_tblSearchBuildSqlQuery($table, $fields, $criteriaColumnNames, - $criteriaColumnTypes, $criteriaColumnCollations, $criteriaColumnOperators) -{ + $criteriaColumnTypes, $criteriaColumnCollations, $criteriaColumnOperators +) { $sql_query = 'SELECT '; // If only distinct values are needed @@ -449,7 +449,7 @@ function PMA_tblSearchBuildSqlQuery($table, $fields, $criteriaColumnNames, $criteriaColumnCollations, $criteriaColumnOperators ); $sql_query .= $whereClause; - + // if the search results are to be ordered if ($_POST['orderByColumn'] != '--nil--') { $sql_query .= ' ORDER BY ' . PMA_backquote($_POST['orderByColumn']) @@ -461,17 +461,17 @@ function PMA_tblSearchBuildSqlQuery($table, $fields, $criteriaColumnNames, /** * Generates the where clause for the SQL search query to be executed * - * @param array $fields Entered values of the columns - * @param array $criteriaColumnNames Names of all columns - * @param array $criteriaColumnTypes Types of all columns - * @param array $criteriaColumnCollations Collations of all columns - * @param array $criteriaColumnOperators Operators for given column type + * @param array $fields Entered values of the columns + * @param array $criteriaColumnNames Names of all columns + * @param array $criteriaColumnTypes Types of all columns + * @param array $criteriaColumnCollations Collations of all columns + * @param array $criteriaColumnOperators Operators for given column type * * @return string the generated where clause */ function PMA_tblSearchGenerateWhereClause($fields, $criteriaColumnNames, - $criteriaColumnTypes, $criteriaColumnCollations, $criteriaColumnOperators) -{ + $criteriaColumnTypes, $criteriaColumnCollations, $criteriaColumnOperators +) { $fullWhereClause = ''; if (trim($_POST['customWhereClause']) != '') { @@ -520,8 +520,8 @@ function PMA_tblSearchGenerateWhereClause($fields, $criteriaColumnNames, * @return string the generated HTML */ function PMA_tblSearchGetGeomFuncHtml($geomColumnFlag, $columnTypes, -$geom_types, $column_index) -{ + $geom_types, $column_index +) { $html_output = ''; // return if geometrical column is not present if (! $geomColumnFlag) { @@ -530,7 +530,7 @@ $geom_types, $column_index) /** * Displays 'Function' column if it is present - */ + */ $html_output .= ''; // if a geometry column is present if (in_array($columnTypes[$column_index], $geom_types)) { @@ -563,7 +563,7 @@ $geom_types, $column_index) * @return string the generated HTML */ function PMA_tblSearchGetOptions($columnNames, $columnCount) -{ +{ $html_output = ''; $html_output .= PMA_getDivForSliderEffect('searchoptions', __('Options')); /** @@ -619,7 +619,9 @@ function PMA_tblSearchGetOptions($columnNames, $columnCount) 'ASC' => __('Ascending'), 'DESC' => __('Descending') ); - $html_output .= PMA_getRadioFields('order', $choices, 'ASC', false, true, "formelement"); + $html_output .= PMA_getRadioFields( + 'order', $choices, 'ASC', false, true, "formelement" + ); unset($choices); $html_output .= '
'; @@ -642,9 +644,9 @@ function PMA_tblSearchGetOptions($columnNames, $columnCount) * @return string the generated HTML */ function PMA_tblSearchGetFieldsTableHtml($columnNames, $columnTypes, -$columnCollations, $columnNullFlags, $geomColumnFlag, $columnCount, -$foreigners, $db, $table) -{ + $columnCollations, $columnNullFlags, $geomColumnFlag, $columnCount, + $foreigners, $db, $table +) { $html_output = ''; $html_output .= ''; $html_output .= PMA_tbl_setTableHeader($geomColumnFlag) . ''; @@ -704,7 +706,7 @@ $foreigners, $db, $table) /** * Generates the table search form under table search tab * - * @param string $goto Goto URL + * @param string $goto Goto URL * @param array $columnNames Names of columns in the table * @param array $columnTypes Types of columns in the table * @param array $columnCollations Collation of all columns @@ -718,9 +720,9 @@ $foreigners, $db, $table) * @return string the generated HTML for table search form */ function PMA_tblSearchGetSelectionForm($goto, $columnNames, $columnTypes, -$columnCollations, $columnNullFlags, $geomColumnFlag, $columnCount, -$foreigners, $db, $table) -{ + $columnCollations, $columnNullFlags, $geomColumnFlag, $columnCount, + $foreigners, $db, $table +) { $html_output = ''; $html_output .= '
'; $url_params = array(); @@ -742,7 +744,7 @@ $foreigners, $db, $table) */ $html_output .= PMA_tblSearchGetFieldsTableHtml( $columnNames, $columnTypes, $columnCollations, $columnNullFlags, - $geomColumnFlag, $columnCount, $foreigners, $db, $table + $geomColumnFlag, $columnCount, $foreigners, $db, $table ); $html_output .= '
'