From ec42cfb96a61c8bbd0f106ef439a19c3b46a1c60 Mon Sep 17 00:00:00 2001 From: Willian Gustavo Veiga Date: Tue, 1 May 2012 14:49:04 -0300 Subject: [PATCH 1/6] Some phpcs warnings fixed --- browse_foreigners.php | 60 +++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/browse_foreigners.php b/browse_foreigners.php index 53871854bd..f6378dd962 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -36,7 +36,10 @@ if (isset($foreign_navig) && $foreign_navig == __('Show all')) { unset($foreign_limit); } -$foreignData = PMA_getForeignData($foreigners, $field, $override_total, isset($foreign_filter) ? $foreign_filter : '', $foreign_limit); +$foreignData = PMA_getForeignData( + $foreigners, $field, $override_total, + isset($foreign_filter) ? $foreign_filter : '', $foreign_limit +); if (isset($rownumber)) { $rownumber_param = '&rownumber=' . urlencode($rownumber); @@ -49,8 +52,11 @@ $showall = ''; if (is_array($foreignData['disp_row'])) { - if ($cfg['ShowAll'] && ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])) { - $showall = ''; + if ($cfg['ShowAll'] + && ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows']) + ) { + $showall = ''; } $session_max_rows = $GLOBALS['cfg']['MaxRows']; @@ -72,8 +78,11 @@ if (is_array($foreignData['disp_row'])) { } } ?> + - + phpMyAdmin @@ -236,7 +245,8 @@ if (is_array($foreignData['disp_row'])) { $val_ordered_current_row++; if (PMA_strlen($val_ordered_current_val) <= $cfg['LimitChars']) { - $val_ordered_current_val = htmlspecialchars($val_ordered_current_val); + $val_ordered_current_val + = htmlspecialchars($val_ordered_current_val); $val_ordered_current_val_title = ''; } else { $val_ordered_current_val_title @@ -247,14 +257,16 @@ if (is_array($foreignData['disp_row'])) { ); } if (PMA_strlen($key_ordered_current_val) <= $cfg['LimitChars']) { - $key_ordered_current_val = htmlspecialchars($key_ordered_current_val); + $key_ordered_current_val + = htmlspecialchars($key_ordered_current_val); $key_ordered_current_val_title = ''; } else { $key_ordered_current_val_title = htmlspecialchars($key_ordered_current_val); $key_ordered_current_val = htmlspecialchars( - PMA_substr($key_ordered_current_val, 0, $cfg['LimitChars']) . '...' + PMA_substr($key_ordered_current_val, 0, $cfg['LimitChars']) + . '...' ); } @@ -268,19 +280,24 @@ if (is_array($foreignData['disp_row'])) { ' : '') - .'' - .htmlspecialchars($key_ordered_current_key) . '' . ($key_ordered_current_equals_data ? '' : ''); + . htmlspecialchars($key_ordered_current_key) + . '' . ($key_ordered_current_equals_data ? '' : ''); ?> ' : '') - . '' - . $key_ordered_current_val . '' . ($key_ordered_current_equals_data ? '' : ''); + . md5($field) . '\', \'' + . PMA_jsFormat($key_ordered_current_key, false) + . '\'); return false;">' + . $key_ordered_current_val . '' + . ($key_ordered_current_equals_data ? '' : ''); ?> ' : '') - . '' - . $val_ordered_current_val . '' . ($val_ordered_current_equals_data ? '' : ''); + . '' + . $val_ordered_current_val . '' + . ($val_ordered_current_equals_data ? '' : ''); ?> ' : '') . '' . htmlspecialchars($val_ordered_current_key) + . PMA_jsFormat($val_ordered_current_key, false) . '\'); return false;">' + . htmlspecialchars($val_ordered_current_key) . '' . ($val_ordered_current_equals_data ? '' : ''); ?> From 4eabde2aee264a9fd88bc7035380202b602416fe Mon Sep 17 00:00:00 2001 From: Willian Gustavo Veiga Date: Tue, 1 May 2012 16:41:47 -0300 Subject: [PATCH 2/6] validate.lib.php - coding standards warnings fixed --- libraries/config/validate.lib.php | 112 ++++++++++++++++++++++-------- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/libraries/config/validate.lib.php b/libraries/config/validate.lib.php index cce1da8f74..7009148059 100644 --- a/libraries/config/validate.lib.php +++ b/libraries/config/validate.lib.php @@ -28,9 +28,10 @@ function PMA_config_get_validators() $cf = ConfigFile::getInstance(); $validators = $cf->getDbEntry('_validators', array()); if (!defined('PMA_SETUP')) { - // not in setup script: load additional validators for user preferences - // we need oryginal config values not overwritten by user preferences, creating a new PMA_Config - // instance is a better idea than hacking into its code + // not in setup script: load additional validators for user + // preferences we need oryginal config values not overwritten + // by user preferences, creating a new PMA_Config instance is a + // better idea than hacking into its code $org_cfg = $cf->getOrgConfigObj(); $uvs = $cf->getDbEntry('_userValidators', array()); foreach ($uvs as $field => $uv_list) { @@ -41,7 +42,9 @@ function PMA_config_get_validators() } for ($i = 1; $i < count($uv); $i++) { if (substr($uv[$i], 0, 6) == 'value:') { - $uv[$i] = PMA_array_read(substr($uv[$i], 6), $org_cfg->settings); + $uv[$i] = PMA_array_read( + substr($uv[$i], 6), $org_cfg->settings + ); } } } @@ -187,8 +190,9 @@ function test_php_errormsg($start = true) * * @return bool|array */ -function test_db_connection($extension, $connect_type, $host, $port, $socket, $user, $pass = null, $error_key = 'Server') -{ +function test_db_connection($extension, $connect_type, $host, $port, $socket, + $user, $pass = null, $error_key = 'Server' +) { // test_php_errormsg(); $socket = empty($socket) || $connect_type == 'tcp' ? null : $socket; $port = empty($port) || $connect_type == 'socket' ? null : ':' . $port; @@ -202,13 +206,16 @@ function test_db_connection($extension, $connect_type, $host, $port, $socket, $u } $conn = $socket ? @drizzle_con_add_uds($socket, $user, $pass, null, 0) - : @drizzle_con_add_tcp($drizzle, $host, $port, $user, $pass, null, 0); + : @drizzle_con_add_tcp( + $drizzle, $host, $port, $user, $pass, null, 0 + ); if (!$conn) { $error = __('Could not connect to Drizzle server'); drizzle_free($drizzle); break; } - // connection object is set up but we have to send some query to actually connect + // connection object is set up but we have to send some query + // to actually connect $res = @drizzle_query($conn, 'SELECT 1'); if (!$res) { $error = __('Could not connect to Drizzle server'); @@ -251,24 +258,50 @@ function test_db_connection($extension, $connect_type, $host, $port, $socket, $u */ function validate_server($path, $values) { - $result = array('Server' => '', 'Servers/1/user' => '', 'Servers/1/SignonSession' => '', 'Servers/1/SignonURL' => ''); + $result = array( + 'Server' => '', + 'Servers/1/user' => '', + 'Servers/1/SignonSession' => '', + 'Servers/1/SignonURL' => '' + ); $error = false; - if ($values['Servers/1/auth_type'] == 'config' && empty($values['Servers/1/user'])) { - $result['Servers/1/user'] = __('Empty username while using config authentication method'); + if ($values['Servers/1/auth_type'] == 'config' + && empty($values['Servers/1/user']) + ) { + $result['Servers/1/user'] + = __('Empty username while using config authentication method'); $error = true; } - if ($values['Servers/1/auth_type'] == 'signon' && empty($values['Servers/1/SignonSession'])) { - $result['Servers/1/SignonSession'] = __('Empty signon session name while using signon authentication method'); + if ($values['Servers/1/auth_type'] == 'signon' + && empty($values['Servers/1/SignonSession']) + ) { + $message = 'Empty signon session name while using signon ' + . 'authentication method'; + $result['Servers/1/SignonSession'] = __($message); + unset($message); $error = true; } - if ($values['Servers/1/auth_type'] == 'signon' && empty($values['Servers/1/SignonURL'])) { - $result['Servers/1/SignonURL'] = __('Empty signon URL while using signon authentication method'); + if ($values['Servers/1/auth_type'] == 'signon' + && empty($values['Servers/1/SignonURL']) + ) { + $result['Servers/1/SignonURL'] + = __('Empty signon URL while using signon authentication method'); $error = true; } if (!$error && $values['Servers/1/auth_type'] == 'config') { - $password = $values['Servers/1/nopassword'] ? null : $values['Servers/1/password']; - $test = test_db_connection($values['Servers/1/extension'], $values['Servers/1/connect_type'], $values['Servers/1/host'], $values['Servers/1/port'], $values['Servers/1/socket'], $values['Servers/1/user'], $password, 'Server'); + $password = $values['Servers/1/nopassword'] ? null + : $values['Servers/1/password']; + $test = test_db_connection( + $values['Servers/1/extension'], + $values['Servers/1/connect_type'], + $values['Servers/1/host'], + $values['Servers/1/port'], + $values['Servers/1/socket'], + $values['Servers/1/user'], + $password, + 'Server' + ); if ($test !== true) { $result = array_merge($result, $test); } @@ -286,8 +319,11 @@ function validate_server($path, $values) */ function validate_pmadb($path, $values) { - //$tables = array('Servers/1/bookmarktable', 'Servers/1/relation', 'Servers/1/table_info', 'Servers/1/table_coords', 'Servers/1/pdf_pages', 'Servers/1/column_info', 'Servers/1/history', 'Servers/1/designer_coords'); - $result = array('Server_pmadb' => '', 'Servers/1/controluser' => '', 'Servers/1/controlpass' => ''); + $result = array( + 'Server_pmadb' => '', + 'Servers/1/controluser' => '', + 'Servers/1/controlpass' => '' + ); $error = false; if ($values['Servers/1/pmadb'] == '') { @@ -296,18 +332,21 @@ function validate_pmadb($path, $values) $result = array(); if ($values['Servers/1/controluser'] == '') { - $result['Servers/1/controluser'] = __('Empty phpMyAdmin control user while using pmadb'); + $result['Servers/1/controluser'] + = __('Empty phpMyAdmin control user while using pmadb'); $error = true; } if ($values['Servers/1/controlpass'] == '') { - $result['Servers/1/controlpass'] = __('Empty phpMyAdmin control user password while using pmadb'); + $result['Servers/1/controlpass'] + = __('Empty phpMyAdmin control user password while using pmadb'); $error = true; } if (!$error) { $test = test_db_connection( $values['Servers/1/extension'], $values['Servers/1/connect_type'], - $values['Servers/1/host'], $values['Servers/1/port'], $values['Servers/1/socket'], - $values['Servers/1/controluser'], $values['Servers/1/controlpass'], 'Server_pmadb' + $values['Servers/1/host'], $values['Servers/1/port'], + $values['Servers/1/socket'], $values['Servers/1/controluser'], + $values['Servers/1/controlpass'], 'Server_pmadb' ); if ($test !== true) { $result = array_merge($result, $test); @@ -411,13 +450,18 @@ function validate_trusted_proxies($path, $values) * * @return string empty string if test is successful */ -function test_number($path, $values, $allow_neg, $allow_zero, $max_value, $error_string) -{ +function test_number($path, $values, $allow_neg, $allow_zero, $max_value, + $error_string +) { if ($values[$path] === '') { return ''; } - if (intval($values[$path]) != $values[$path] || (!$allow_neg && $values[$path] < 0) || (!$allow_zero && $values[$path] == 0) || $values[$path] > $max_value) { + if (intval($values[$path]) != $values[$path] + || (!$allow_neg && $values[$path] < 0) + || (!$allow_zero && $values[$path] == 0) + || $values[$path] > $max_value + ) { return $error_string; } @@ -434,7 +478,9 @@ function test_number($path, $values, $allow_neg, $allow_zero, $max_value, $error */ function validate_port_number($path, $values) { - return array($path => test_number($path, $values, false, false, 65535, __('Not a valid port number'))); + return array($path => test_number( + $path, $values, false, false, 65535, __('Not a valid port number') + )); } /** @@ -447,7 +493,9 @@ function validate_port_number($path, $values) */ function validate_positive_number($path, $values) { - return array($path => test_number($path, $values, false, false, PHP_INT_MAX, __('Not a positive number'))); + return array($path => test_number( + $path, $values, false, false, PHP_INT_MAX, __('Not a positive number') + )); } /** @@ -460,7 +508,10 @@ function validate_positive_number($path, $values) */ function validate_non_negative_number($path, $values) { - return array($path => test_number($path, $values, false, true, PHP_INT_MAX, __('Not a non-negative number'))); + return array($path => test_number( + $path, $values, false, true, + PHP_INT_MAX, __('Not a non-negative number') + )); } /** @@ -491,6 +542,7 @@ function validate_by_regex($path, $values, $regex) function validate_upper_bound($path, $values, $max_value) { $result = $values[$path] <= $max_value; - return array($path => ($result ? '' : sprintf(__('Value must be equal or lower than %s'), $max_value))); + return array($path => ($result ? '' + : sprintf(__('Value must be equal or lower than %s'), $max_value))); } ?> From 139877978a1e4b7600aea92db13483b36fafa963 Mon Sep 17 00:00:00 2001 From: Willian Gustavo Veiga Date: Tue, 1 May 2012 19:26:52 -0300 Subject: [PATCH 3/6] code readability improved --- browse_foreigners.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/browse_foreigners.php b/browse_foreigners.php index f6378dd962..ad158449ab 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -245,29 +245,32 @@ if (is_array($foreignData['disp_row'])) { $val_ordered_current_row++; if (PMA_strlen($val_ordered_current_val) <= $cfg['LimitChars']) { - $val_ordered_current_val - = htmlspecialchars($val_ordered_current_val); + $val_ordered_current_val = htmlspecialchars( + $val_ordered_current_val + ); $val_ordered_current_val_title = ''; } else { - $val_ordered_current_val_title - = htmlspecialchars($val_ordered_current_val); + $val_ordered_current_val_title = htmlspecialchars( + $val_ordered_current_val + ); $val_ordered_current_val = htmlspecialchars( PMA_substr($val_ordered_current_val, 0, $cfg['LimitChars']) . '...' ); } if (PMA_strlen($key_ordered_current_val) <= $cfg['LimitChars']) { - $key_ordered_current_val - = htmlspecialchars($key_ordered_current_val); + $key_ordered_current_val = htmlspecialchars( + $key_ordered_current_val + ); $key_ordered_current_val_title = ''; } else { - $key_ordered_current_val_title - = htmlspecialchars($key_ordered_current_val); - $key_ordered_current_val - = htmlspecialchars( - PMA_substr($key_ordered_current_val, 0, $cfg['LimitChars']) - . '...' - ); + $key_ordered_current_val_title = htmlspecialchars( + $key_ordered_current_val + ); + $key_ordered_current_val = htmlspecialchars( + PMA_substr($key_ordered_current_val, 0, $cfg['LimitChars']) + . '...' + ); } if (! empty($data)) { From 279d32fb3ecec5ee05b537e5d5b88cc3aca2bcab Mon Sep 17 00:00:00 2001 From: Willian Gustavo Veiga Date: Tue, 1 May 2012 19:33:32 -0300 Subject: [PATCH 4/6] code readability improved --- libraries/config/validate.lib.php | 40 +++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/libraries/config/validate.lib.php b/libraries/config/validate.lib.php index 7009148059..f335504315 100644 --- a/libraries/config/validate.lib.php +++ b/libraries/config/validate.lib.php @@ -478,9 +478,16 @@ function test_number($path, $values, $allow_neg, $allow_zero, $max_value, */ function validate_port_number($path, $values) { - return array($path => test_number( - $path, $values, false, false, 65535, __('Not a valid port number') - )); + return array( + $path => test_number( + $path, + $values, + false, + false, + 65535, + __('Not a valid port number') + ) + ); } /** @@ -493,9 +500,16 @@ function validate_port_number($path, $values) */ function validate_positive_number($path, $values) { - return array($path => test_number( - $path, $values, false, false, PHP_INT_MAX, __('Not a positive number') - )); + return array( + $path => test_number( + $path, + $values, + false, + false, + PHP_INT_MAX, + __('Not a positive number') + ) + ); } /** @@ -508,10 +522,16 @@ function validate_positive_number($path, $values) */ function validate_non_negative_number($path, $values) { - return array($path => test_number( - $path, $values, false, true, - PHP_INT_MAX, __('Not a non-negative number') - )); + return array( + $path => test_number( + $path, + $values, + false, + true, + PHP_INT_MAX, + __('Not a non-negative number') + ) + ); } /** From 9685d8d68345d2e2fdca5a5869ef2cd53073b166 Mon Sep 17 00:00:00 2001 From: Willian Gustavo Veiga Date: Thu, 3 May 2012 13:13:55 -0300 Subject: [PATCH 5/6] Each parameter on a new line --- libraries/config/validate.lib.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libraries/config/validate.lib.php b/libraries/config/validate.lib.php index f335504315..b5a1114e20 100644 --- a/libraries/config/validate.lib.php +++ b/libraries/config/validate.lib.php @@ -190,8 +190,15 @@ function test_php_errormsg($start = true) * * @return bool|array */ -function test_db_connection($extension, $connect_type, $host, $port, $socket, - $user, $pass = null, $error_key = 'Server' +function test_db_connection( + $extension, + $connect_type, + $host, + $port, + $socket, + $user, + $pass = null, + $error_key = 'Server' ) { // test_php_errormsg(); $socket = empty($socket) || $connect_type == 'tcp' ? null : $socket; @@ -450,7 +457,12 @@ function validate_trusted_proxies($path, $values) * * @return string empty string if test is successful */ -function test_number($path, $values, $allow_neg, $allow_zero, $max_value, +function test_number( + $path, + $values, + $allow_neg, + $allow_zero, + $max_value, $error_string ) { if ($values[$path] === '') { From d44db6b80afd4c22371a2185e86ddb07c499c4bf Mon Sep 17 00:00:00 2001 From: Willian Gustavo Veiga Date: Fri, 4 May 2012 08:42:03 -0300 Subject: [PATCH 6/6] Code readability improved. --- browse_foreigners.php | 5 +++-- libraries/config/validate.lib.php | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/browse_foreigners.php b/browse_foreigners.php index ad158449ab..490a06cdee 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -268,8 +268,9 @@ if (is_array($foreignData['disp_row'])) { $key_ordered_current_val ); $key_ordered_current_val = htmlspecialchars( - PMA_substr($key_ordered_current_val, 0, $cfg['LimitChars']) - . '...' + PMA_substr( + $key_ordered_current_val, 0, $cfg['LimitChars'] + ) . '...' ); } diff --git a/libraries/config/validate.lib.php b/libraries/config/validate.lib.php index b5a1114e20..763cf0aa71 100644 --- a/libraries/config/validate.lib.php +++ b/libraries/config/validate.lib.php @@ -282,10 +282,10 @@ function validate_server($path, $values) if ($values['Servers/1/auth_type'] == 'signon' && empty($values['Servers/1/SignonSession']) ) { - $message = 'Empty signon session name while using signon ' - . 'authentication method'; - $result['Servers/1/SignonSession'] = __($message); - unset($message); + $result['Servers/1/SignonSession'] = __( + 'Empty signon session name ' + . 'while using signon authentication method' + ); $error = true; } if ($values['Servers/1/auth_type'] == 'signon'