From 841636e2ed51a00948a07b5e9312aac40cc45c38 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 7 May 2012 22:25:53 +0530 Subject: [PATCH 1/5] Fix indentation --- libraries/auth/config.auth.lib.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/auth/config.auth.lib.php b/libraries/auth/config.auth.lib.php index 187fa16217..50eabb1c2e 100644 --- a/libraries/auth/config.auth.lib.php +++ b/libraries/auth/config.auth.lib.php @@ -102,13 +102,13 @@ function PMA_auth_fails() if ($GLOBALS['PMA_Config']->source_mtime == 0) { echo '

' . sprintf(__('You probably did not create a configuration file. You might want to use the %1$ssetup script%2$s to create one.'), '', '') . '

' . "\n"; } elseif (!isset($GLOBALS['errno']) || (isset($GLOBALS['errno']) && $GLOBALS['errno'] != 2002) && $GLOBALS['errno'] != 2003) { - // if we display the "Server not responding" error, do not confuse users - // by telling them they have a settings problem - // (note: it's true that they could have a badly typed host name, but - // anyway the current message tells that the server - // rejected the connection, which is not really what happened) - // 2002 is the error given by mysqli - // 2003 is the error given by mysql + // if we display the "Server not responding" error, do not confuse users + // by telling them they have a settings problem + // (note: it's true that they could have a badly typed host name, but + // anyway the current message tells that the server + // rejected the connection, which is not really what happened) + // 2002 is the error given by mysqli + // 2003 is the error given by mysql trigger_error(__('phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.'), E_USER_WARNING); } PMA_mysqlDie($conn_error, '', true, '', false); From 9e20323c8d3dfa40314485e583689df248a7d49a Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 7 May 2012 22:42:41 +0530 Subject: [PATCH 2/5] Coding style fixes. Mostly wrapping long lines --- libraries/auth/config.auth.lib.php | 5 ++- libraries/auth/cookie.auth.lib.php | 52 +++++++++++++++++++++--------- libraries/auth/http.auth.lib.php | 8 +++-- libraries/auth/signon.auth.lib.php | 23 +++++++++---- 4 files changed, 62 insertions(+), 26 deletions(-) diff --git a/libraries/auth/config.auth.lib.php b/libraries/auth/config.auth.lib.php index 50eabb1c2e..fbe39e7c8b 100644 --- a/libraries/auth/config.auth.lib.php +++ b/libraries/auth/config.auth.lib.php @@ -101,7 +101,10 @@ function PMA_auth_fails() // Check whether user has configured something if ($GLOBALS['PMA_Config']->source_mtime == 0) { echo '

' . sprintf(__('You probably did not create a configuration file. You might want to use the %1$ssetup script%2$s to create one.'), '', '') . '

' . "\n"; - } elseif (!isset($GLOBALS['errno']) || (isset($GLOBALS['errno']) && $GLOBALS['errno'] != 2002) && $GLOBALS['errno'] != 2003) { + } elseif (! isset($GLOBALS['errno']) + || (isset($GLOBALS['errno']) && $GLOBALS['errno'] != 2002) + && $GLOBALS['errno'] != 2003 + ) { // if we display the "Server not responding" error, do not confuse users // by telling them they have a settings problem // (note: it's true that they could have a badly typed host name, but diff --git a/libraries/auth/cookie.auth.lib.php b/libraries/auth/cookie.auth.lib.php index d43859f61b..9a09a1900e 100644 --- a/libraries/auth/cookie.auth.lib.php +++ b/libraries/auth/cookie.auth.lib.php @@ -37,7 +37,9 @@ if (function_exists('mcrypt_encrypt')) { * further decryption. I don't think necessary to have one iv * per server so I don't put the server number in the cookie name. */ - if (empty($_COOKIE['pma_mcrypt_iv']) || false === ($iv = base64_decode($_COOKIE['pma_mcrypt_iv'], true))) { + if (empty($_COOKIE['pma_mcrypt_iv']) + || false === ($iv = base64_decode($_COOKIE['pma_mcrypt_iv'], true)) + ) { srand((double) microtime() * 1000000); $td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, ''); if ($td === false) { @@ -50,8 +52,8 @@ if (function_exists('mcrypt_encrypt')) { /** * Encryption using blowfish algorithm (mcrypt) * - * @param string original data - * @param string the secret + * @param string $data original data + * @param string $secret the secret * * @return string the encrypted result * @@ -61,14 +63,16 @@ if (function_exists('mcrypt_encrypt')) { function PMA_blowfish_encrypt($data, $secret) { global $iv; - return base64_encode(mcrypt_encrypt(MCRYPT_BLOWFISH, $secret, $data, MCRYPT_MODE_CBC, $iv)); + return base64_encode( + mcrypt_encrypt(MCRYPT_BLOWFISH, $secret, $data, MCRYPT_MODE_CBC, $iv) + ); } /** * Decryption using blowfish algorithm (mcrypt) * - * @param string encrypted data - * @param string the secret + * @param string $encdata encrypted data + * @param string $secret the secret * * @return string original data * @@ -135,7 +139,9 @@ function PMA_auth() } /* No recall if blowfish secret is not configured as it would produce garbage */ - if ($GLOBALS['cfg']['LoginCookieRecall'] && !empty($GLOBALS['cfg']['blowfish_secret'])) { + if ($GLOBALS['cfg']['LoginCookieRecall'] + && ! empty($GLOBALS['cfg']['blowfish_secret']) + ) { $default_user = $GLOBALS['PHP_AUTH_USER']; $default_server = $GLOBALS['pma_auth_server']; $autocomplete = ''; @@ -171,10 +177,12 @@ function PMA_auth()

@@ -388,8 +396,12 @@ function PMA_auth_check() if (! empty($_REQUEST['pma_username'])) { // The user just logged in $GLOBALS['PHP_AUTH_USER'] = $_REQUEST['pma_username']; - $GLOBALS['PHP_AUTH_PW'] = empty($_REQUEST['pma_password']) ? '' : $_REQUEST['pma_password']; - if ($GLOBALS['cfg']['AllowArbitraryServer'] && isset($_REQUEST['pma_servername'])) { + $GLOBALS['PHP_AUTH_PW'] = empty($_REQUEST['pma_password']) + ? '' + : $_REQUEST['pma_password']; + if ($GLOBALS['cfg']['AllowArbitraryServer'] + && isset($_REQUEST['pma_servername']) + ) { $GLOBALS['pma_auth_server'] = $_REQUEST['pma_servername']; } return true; @@ -536,10 +548,15 @@ function PMA_auth_set_user() if ($GLOBALS['cfg']['AllowArbitraryServer']) { if (! empty($GLOBALS['pma_auth_server'])) { // Duration = one month for servername - $GLOBALS['PMA_Config']->setCookie('pmaServer-' . $GLOBALS['server'], $cfg['Server']['host']); + $GLOBALS['PMA_Config']->setCookie( + 'pmaServer-' . $GLOBALS['server'], + $cfg['Server']['host'] + ); } else { // Delete servername cookie - $GLOBALS['PMA_Config']->removeCookie('pmaServer-' . $GLOBALS['server']); + $GLOBALS['PMA_Config']->removeCookie( + 'pmaServer-' . $GLOBALS['server'] + ); } } @@ -569,7 +586,9 @@ function PMA_auth_set_user() */ PMA_clearUserCache(); - PMA_sendHeaderLocation($redirect_url . PMA_generate_common_url($url_params, '&')); + PMA_sendHeaderLocation( + $redirect_url . PMA_generate_common_url($url_params, '&') + ); exit(); } // end if @@ -610,7 +629,8 @@ function PMA_auth_fails() } } } elseif (PMA_DBI_getError()) { - $conn_error = '#' . $GLOBALS['errno'] . ' ' . __('Cannot log in to the MySQL server'); + $conn_error = '#' . $GLOBALS['errno'] . ' ' + . __('Cannot log in to the MySQL server'); } else { $conn_error = __('Cannot log in to the MySQL server'); } diff --git a/libraries/auth/http.auth.lib.php b/libraries/auth/http.auth.lib.php index 921fa34438..7881750544 100644 --- a/libraries/auth/http.auth.lib.php +++ b/libraries/auth/http.auth.lib.php @@ -23,7 +23,9 @@ function PMA_auth() { /* Perform logout to custom URL */ - if (!empty($_REQUEST['old_usr']) && !empty($GLOBALS['cfg']['Server']['LogoutURL'])) { + if (! empty($_REQUEST['old_usr']) + && ! empty($GLOBALS['cfg']['Server']['LogoutURL']) + ) { PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']); exit; } @@ -119,7 +121,9 @@ function PMA_auth_check() } elseif (PMA_getenv('AUTH_USER')) { // WebSite Professional $PHP_AUTH_USER = PMA_getenv('AUTH_USER'); - } elseif (PMA_getenv('HTTP_AUTHORIZATION') && false === strpos(PMA_getenv('HTTP_AUTHORIZATION'), '<')) { + } elseif (PMA_getenv('HTTP_AUTHORIZATION') + && false === strpos(PMA_getenv('HTTP_AUTHORIZATION'), '<') + ) { // IIS, might be encoded, see below; also prevent XSS $PHP_AUTH_USER = PMA_getenv('HTTP_AUTHORIZATION'); } elseif (PMA_getenv('Authorization')) { diff --git a/libraries/auth/signon.auth.lib.php b/libraries/auth/signon.auth.lib.php index 400e17039e..332ead3dc3 100644 --- a/libraries/auth/signon.auth.lib.php +++ b/libraries/auth/signon.auth.lib.php @@ -24,7 +24,9 @@ function PMA_auth() unset($_SESSION['LAST_SIGNON_URL']); if (empty($GLOBALS['cfg']['Server']['SignonURL'])) { PMA_fatalError('You must set SignonURL!'); - } elseif (!empty($_REQUEST['old_usr']) && !empty($GLOBALS['cfg']['Server']['LogoutURL'])) { + } elseif (! empty($_REQUEST['old_usr']) + && ! empty($GLOBALS['cfg']['Server']['LogoutURL']) + ) { /* Perform logout to custom URL */ PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']); } else { @@ -58,7 +60,9 @@ function PMA_auth_check() global $PHP_AUTH_USER, $PHP_AUTH_PW; /* Check if we're using same sigon server */ - if (isset($_SESSION['LAST_SIGNON_URL']) && $_SESSION['LAST_SIGNON_URL'] != $GLOBALS['cfg']['Server']['SignonURL']) { + if (isset($_SESSION['LAST_SIGNON_URL']) + && $_SESSION['LAST_SIGNON_URL'] != $GLOBALS['cfg']['Server']['SignonURL'] + ) { return false; } @@ -86,14 +90,16 @@ function PMA_auth_check() /* Handle script based auth */ if (!empty($script_name)) { if (! file_exists($script_name)) { - PMA_fatalError(__('Can not find signon authentication script:') . ' ' . $script_name); + PMA_fatalError( + __('Can not find signon authentication script:') . ' ' . $script_name + ); } include $script_name; - list ($PHP_AUTH_USER, $PHP_AUTH_PW) = get_login_credentials($cfg['Server']['user']); + list ($PHP_AUTH_USER, $PHP_AUTH_PW) + = get_login_credentials($cfg['Server']['user']); - /* Does session exist? */ - } elseif (isset($_COOKIE[$session_name])) { + } elseif (isset($_COOKIE[$session_name])) { /* Does session exist? */ /* End current session */ $old_session = session_name(); $old_id = session_id(); @@ -158,7 +164,10 @@ function PMA_auth_check() $GLOBALS['cfg']['Server']['port'] = $single_signon_port; /* Configuration update */ - $GLOBALS['cfg']['Server'] = array_merge($GLOBALS['cfg']['Server'], $single_signon_cfgupdate); + $GLOBALS['cfg']['Server'] = array_merge( + $GLOBALS['cfg']['Server'], + $single_signon_cfgupdate + ); /* Restore our token */ if (!empty($pma_token)) { From 79c54fb2c8361ad8444cc691ad79dfa3a86c35e2 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 7 May 2012 22:46:21 +0530 Subject: [PATCH 3/5] Fix indentation --- libraries/config/FormDisplay.tpl.php | 100 +++++++++++++-------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/libraries/config/FormDisplay.tpl.php b/libraries/config/FormDisplay.tpl.php index fa81e1e7a8..6002012512 100644 --- a/libraries/config/FormDisplay.tpl.php +++ b/libraries/config/FormDisplay.tpl.php @@ -217,57 +217,57 @@ function display_input($path, $name, $description = '', $type, $value, $value_is '; - break; - case 'short_text': - echo ''; - break; - case 'number_text': - echo ''; - break; - case 'checkbox': - echo ''; - break; - case 'select': - echo ''; + break; + case 'short_text': + echo ''; + break; + case 'number_text': + echo ''; + break; + case 'checkbox': + echo ''; + break; + case 'select': + echo ''; - break; - case 'list': - echo ''; - break; + // escape if necessary + if ($escape) { + $display = htmlspecialchars($opt_value); + $display_value = htmlspecialchars($opt_value_key); + } else { + $display = $opt_value; + $display_value = $opt_value_key; + } + // compare with selected value + // boolean values are cast to integers when used as array keys + $selected = is_bool($value) + ? (int) $value === $opt_value_key + : $opt_value_key === $value; + echo ''; + } + echo ''; + break; + case 'list': + echo ''; + break; } if (isset($opts['comment']) && $opts['comment']) { $class = 'field-comment-mark'; From bdc6714c759ac424b6b9d4aabe6557700c9213fd Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 7 May 2012 22:53:08 +0530 Subject: [PATCH 4/5] Coding style improvements --- libraries/config/FormDisplay.tpl.php | 45 +++++++++++++-------- libraries/config/user_preferences.forms.php | 3 +- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/libraries/config/FormDisplay.tpl.php b/libraries/config/FormDisplay.tpl.php index 6002012512..9d009dd115 100644 --- a/libraries/config/FormDisplay.tpl.php +++ b/libraries/config/FormDisplay.tpl.php @@ -9,9 +9,11 @@ /** * Displays top part of the form * - * @param string $action default: $_SERVER['REQUEST_URI'] - * @param string $method 'post' or 'get' - * @param array $hidden_fields array of form hidden fields (key: field name) + * @param string $action default: $_SERVER['REQUEST_URI'] + * @param string $method 'post' or 'get' + * @param array $hidden_fields array of form hidden fields (key: field name) + * + * @return void */ function display_form_top($action = null, $method = 'post', $hidden_fields = null) { @@ -42,7 +44,9 @@ function display_form_top($action = null, $method = 'post', $hidden_fields = nul * Displays form tabs which are given by an array indexed by fieldset id * ({@link display_fieldset_top}), with values being tab titles. * - * @param array $tabs + * @param array $tabs tab names + * + * @return void */ function display_tabs_top($tabs) { @@ -66,8 +70,9 @@ function display_tabs_top($tabs) * @param array $errors * @param array $attributes */ -function display_fieldset_top($title = '', $description = '', $errors = null, $attributes = array()) -{ +function display_fieldset_top($title = '', $description = '', $errors = null, + $attributes = array() +) { global $_FormDisplayGroup; $_FormDisplayGroup = 0; @@ -103,11 +108,12 @@ function display_fieldset_top($title = '', $description = '', $errors = null, $a * o errors - error array * o setvalue - (string) shows button allowing to set poredefined value * o show_restore_default - (boolean) whether show "restore default" button - * o userprefs_allow - whether user preferences are enabled for this field (null - no support, - * true/false - enabled/disabled) + * o userprefs_allow - whether user preferences are enabled for this field + * (null - no support, true/false - enabled/disabled) * o userprefs_comment - (string) field comment * o values - key - value paris for