From d8233fcbb96ab2b897ba87a6ccc4cbbf2576d44e Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Mon, 16 Jul 2012 18:00:39 +0530 Subject: [PATCH] improve coding style --- libraries/server_privileges.lib.php | 166 ++++++++++++++++++++-------- 1 file changed, 117 insertions(+), 49 deletions(-) diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index ed737b5d8a..6c71446ed1 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -1119,14 +1119,20 @@ function PMA_getMessageForUpdatePassword($pma_pw, $pma_pw2, $err_url, $username, if (empty($message)) { $common_functions = PMA_CommonFunctions::getInstance(); - $hashing_function = (! empty($_REQUEST['pw_hash']) && $_REQUEST['pw_hash'] == 'old' ? 'OLD_' : '') - . 'PASSWORD'; + $hashing_function = + (! empty($_REQUEST['pw_hash']) && $_REQUEST['pw_hash'] == 'old' + ? 'OLD_' + : '' + ) + . 'PASSWORD'; // in $sql_query which will be displayed, hide the password $sql_query = 'SET PASSWORD FOR \'' . $common_functions->sqlAddSlashes($username) . '\'@\'' . $common_functions->sqlAddSlashes($hostname) . '\' = ' - . (($pma_pw == '') ? '\'\'' : $hashing_function . '(\'' . preg_replace('@.@s', '*', $pma_pw) . '\')'); + . (($pma_pw == '') + ? '\'\'' + : $hashing_function . '(\'' . preg_replace('@.@s', '*', $pma_pw) . '\')'); $local_query = 'SET PASSWORD FOR \'' . $common_functions->sqlAddSlashes($username) @@ -1137,7 +1143,9 @@ function PMA_getMessageForUpdatePassword($pma_pw, $pma_pw2, $err_url, $username, PMA_DBI_try_query($local_query) or $common_functions->mysqlDie(PMA_DBI_getError(), $sql_query, false, $err_url); $message = PMA_Message::success(__('The password for %s was changed successfully.')); - $message->addParam('\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\''); + $message->addParam( + '\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'' + ); } return $message; } @@ -1158,7 +1166,8 @@ function PMA_getMessageAndSqlQueryForPrivilegesRevoke($db_and_table, $dbname, $db_and_table = PMA_wildcardEscapeForGrant($dbname, $tablename); $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table - . ' FROM \'' . PMA_CommonFunctions::getInstance()->sqlAddSlashes($username) . '\'@\'' + . ' FROM \'' + . PMA_CommonFunctions::getInstance()->sqlAddSlashes($username) . '\'@\'' . PMA_CommonFunctions::getInstance()->sqlAddSlashes($hostname) . '\';'; $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table @@ -1172,7 +1181,9 @@ function PMA_getMessageAndSqlQueryForPrivilegesRevoke($db_and_table, $dbname, } $sql_query = $sql_query0 . ' ' . $sql_query1; $message = PMA_Message::success(__('You have revoked the privileges for %s')); - $message->addParam('\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\''); + $message->addParam( + '\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'' + ); return array($message, $sql_query); } @@ -1223,7 +1234,8 @@ function PMA_getHtmlForAddUser($random_n, $dbname) $html_output = '

' . "\n" . $common_functions->getIcon('b_usradd.png') . __('Add user') . "\n" . '

' . "\n" - . '
' . "\n" + . '' . "\n" . PMA_generate_common_hidden_inputs('', '') . PMA_getHtmlForDisplayLoginInformationFields('new'); @@ -1340,7 +1352,8 @@ function PMA_getHtmlForSpecificDbPrivileges($dbToCheck, $link_edit, $conditional . ' ' . sprintf( __('Users having access to "%s"'), - '' . htmlspecialchars($dbToCheck) . '' + '' + . htmlspecialchars($dbToCheck) . '' ) . "\n" . '' . "\n"; @@ -1456,17 +1469,21 @@ function PMA_getHtmlTableBodyForSpecificDbPrivs($found, $row, $odd_row, $link_ed . ' '; if (! isset($current['Db']) || $current['Db'] == '*') { $html_output .= __('global'); - } elseif ($current['Db'] == PMA_CommonFunctions::getInstance()->escapeMysqlWildcards($dbToCheck)) { + } elseif ( + $current['Db'] == PMA_CommonFunctions::getInstance()->escapeMysqlWildcards($dbToCheck) + ) { $html_output .= __('database-specific'); } else { - $html_output .= __('wildcard'). ': ' . htmlspecialchars($current['Db']) . ''; + $html_output .= __('wildcard'). ': ' + . '' . htmlspecialchars($current['Db']) . ''; } $html_output .= "\n" . '' . "\n"; $html_output .='' . "\n" . '' . "\n" - . '' . join(',' . "\n" . ' ', PMA_extractPrivInfo($current, true)) . "\n" + . '' + . join(',' . "\n" . ' ', PMA_extractPrivInfo($current, true)) . "\n" . '' . "\n" . '' . "\n"; @@ -1478,7 +1495,9 @@ function PMA_getHtmlTableBodyForSpecificDbPrivs($found, $row, $odd_row, $link_ed $link_edit, urlencode($current_user), urlencode($current_host), - urlencode(! isset($current['Db']) || $current['Db'] == '*' ? '' : $current['Db']), + urlencode( + ! isset($current['Db']) || $current['Db'] == '*' ? '' : $current['Db'] + ), '' ); $html_output .= '' . "\n" @@ -1517,7 +1536,8 @@ function PMA_getStandardLinks($conditional_class) $common_functions = PMA_CommonFunctions::getInstance(); $link_edit = ''; $link_revoke = ''; $link_export = ''; $link_export_all = ' ' + . htmlspecialchars($_REQUEST['username']) + . '' . htmlspecialchars($_REQUEST['hostname']) . '" />' . '' . "\n" . '' . $new_user_initial . ''; + . $GLOBALS['url_query'] . '&initial=' . $new_user_initial .'">' + . $new_user_initial . ''; $extra_data['new_user_initial'] = $new_user_initial; $extra_data['new_user_initial_string'] = $new_user_initial_string; } @@ -1668,16 +1695,22 @@ function PMA_getChangeLoginInformationHtmlForm($username, $hostname) '2' => __('... revoke all active privileges from the old one and delete it afterwards.'), '3' => __('... delete the old one from the user tables and reload the privileges afterwards.')); - $html_output = '' . "\n" + $html_output = '' . "\n" . PMA_generate_common_hidden_inputs('', '') - . '' . "\n" - . '' . "\n" + . '' . "\n" + . '' . "\n" . '
' . "\n" - . '' . __('Change Login Information / Copy User') . '' . "\n" + . '' . __('Change Login Information / Copy User') + . '' . "\n" . PMA_getHtmlForDisplayLoginInformationFields('change'); $html_output .= '
' . "\n" - . ' ' . __('Create a new user with the same privileges and ...') . '' . "\n"; + . ' ' + . __('Create a new user with the same privileges and ...') + . '' . "\n"; $html_output .= PMA_CommonFunctions::getInstance()->getRadioFields( 'mode', $choices, '4', true ); @@ -1707,13 +1740,16 @@ function PMA_getLinkToDbAndTable($url_dbname, $dbname, $tablename) . ' ' . htmlspecialchars($dbname) . ': ' - . PMA_CommonFunctions::getInstance()->getTitleForTarget($GLOBALS['cfg']['DefaultTabDatabase']) + . PMA_CommonFunctions::getInstance()->getTitleForTarget( + $GLOBALS['cfg']['DefaultTabDatabase'] + ) . " ]\n"; if (strlen($tablename)) { $html_output .= ' [ ' . __('Table') . ' ' . htmlspecialchars($tablename) . ': ' . PMA_CommonFunctions::getInstance()->getTitleForTarget( $GLOBALS['cfg']['DefaultTabTable'] @@ -1746,7 +1782,8 @@ function PMA_getUserSpecificRights($tables, $user_host_condition, $dbname) } else { $user_host_condition .= ' AND `Db`' - .' LIKE \'' . $common_functions->sqlAddSlashes($dbname, true) . "'"; + .' LIKE \'' + . $common_functions->sqlAddSlashes($dbname, true) . "'"; $tables_to_search_for_users = array('columns_priv',); $dbOrTableName = 'Table_name'; } @@ -1792,7 +1829,8 @@ function PMA_getUserSpecificRights($tables, $user_host_condition, $dbname) PMA_DBI_free_result($db_rights_result); if (! strlen($dbname)) { - $sql_query = 'SELECT * FROM `mysql`.`db`' . $user_host_condition . ' ORDER BY `Db` ASC'; + $sql_query = 'SELECT * FROM `mysql`.`db`' + . $user_host_condition . ' ORDER BY `Db` ASC'; } else { $sql_query = 'SELECT `Table_name`,' .' `Table_priv`,' @@ -1808,7 +1846,8 @@ function PMA_getUserSpecificRights($tables, $user_host_condition, $dbname) while ($row = PMA_DBI_fetch_assoc($result)) { if (isset($db_rights[$row[$dbOrTableName]])) { - $db_rights[$row[$dbOrTableName]] = array_merge($db_rights[$row[$dbOrTableName]], $row); + $db_rights[$row[$dbOrTableName]] + = array_merge($db_rights[$row[$dbOrTableName]], $row); } else { $db_rights[$row[$dbOrTableName]] = $row; } @@ -1856,7 +1895,8 @@ function PMA_getHtmlForDisplayUserRightsInRows($db_rights, $link_edit, $dbname, : $row['Table_name']) . '' . "\n" . '' . "\n" - . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row, true)) . "\n" + . ' ' + . join(',' . "\n" . ' ', PMA_extractPrivInfo($row, true)) . "\n" . '' . "\n" . '' . ((((! strlen($dbname)) && $row['Grant_priv'] == 'Y') @@ -1917,19 +1957,29 @@ function PMA_getTableForDisplayAllTableSpecificRights($username, $hostname ) { // table header $html_output = PMA_generate_common_hidden_inputs('', '') - . '' . "\n" - . '' . "\n" + . '' . "\n" + . '' . "\n" . '
' . "\n" . '' - . (! strlen($dbname) ? __('Database-specific privileges') : __('Table-specific privileges')) + . (! strlen($dbname) + ? __('Database-specific privileges') + : __('Table-specific privileges') + ) . '' . "\n" . '' . "\n" . '' . "\n" - . '' . "\n" + . '' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" @@ -2015,8 +2065,10 @@ function PMA_displayTablesInEditPrivs($dbname, $found_rows) { $common_functions = PMA_CommonFunctions::getInstance(); - $html_output = '' . "\n" - . '' . "\n"; + $html_output = '' . "\n" + $html_output .= '' . "\n"; $result = @PMA_DBI_try_query( 'SHOW TABLES FROM ' . $common_functions->backquote( @@ -2113,11 +2165,15 @@ function PMA_getUsersOverview($result, $db_rights, $link_edit, $pmaThemeImage, 'submit_mult', 'mult_submit', 'submit_mult_export', __('Export'), 'b_tblexport.png', 'export' ); - $html_output .= ''; + $html_output .= ''; $html_output .= '' . '
' . '
' - . sprintf($link_export_all, urlencode('%'), urlencode('%'), (isset($_GET['initial']) ? $_GET['initial'] : '')); + . sprintf($link_export_all, + urlencode('%'), urlencode('%'), + (isset($_GET['initial']) ? $_GET['initial'] : '') + ); $html_output .= '
' . '' . '
'; @@ -2151,7 +2207,9 @@ function PMA_getTableBodyForUserRightsTable($db_rights, $link_edit, $link_export foreach ($user as $host) { $index_checkbox++; $html_output .= '' . "\n"; - $html_output .= '' . "\n" - . '' . "\n" + . '' . "\n" . '
' . (! strlen($dbname) ? __('Database') : __('Table')) . '
' + . (! strlen($dbname) ? __('Database') : __('Table')) + . '' . __('Privileges') . '' . __('Grant') . '' - . (! strlen($dbname) ? __('Table-specific privileges') : __('Column-specific privileges')) + . (! strlen($dbname) + ? __('Table-specific privileges') + : __('Column-specific privileges') + ) . '' . __('Action') . '
' . ($host['Grant_priv'] == 'Y' ? __('Yes') : __('No')) . '' + . ($host['Grant_priv'] == 'Y' ? __('Yes') : __('No')) + . '' . sprintf($link_edit, urlencode($host['User']), urlencode($host['Host']), '', '' @@ -2496,7 +2556,8 @@ function PMA_getHtmlForExportUserDefinition($username, $hostname) } } else { // export privileges for a single user - $title = __('User') . ' `' . htmlspecialchars($username) . '`@`' . htmlspecialchars($hostname) . '`'; + $title = __('User') . ' `' . htmlspecialchars($username) + . '`@`' . htmlspecialchars($hostname) . '`'; $export .= PMA_getGrants($username, $hostname); } // remove trailing whitespace @@ -2645,10 +2706,14 @@ function PMA_getHtmlForDisplayUserOverviewPage($link_edit, $pmaThemeImage, * Display the user overview * (if less than 50 users, display them immediately) */ - if (isset($_REQUEST['initial']) || isset($_REQUEST['showall']) || PMA_DBI_num_rows($res) < 50) { - $html_output .= PMA_getUsersOverview($res, $db_rights, $link_edit,$pmaThemeImage, - $text_dir, $conditional_class, $link_export, $link_export_all - ); + if (isset($_REQUEST['initial']) + || isset($_REQUEST['showall']) + || PMA_DBI_num_rows($res) < 50 + ) { + $html_output .= PMA_getUsersOverview($res, $db_rights, + $link_edit,$pmaThemeImage, $text_dir, $conditional_class, + $link_export, $link_export_all + ); } else { $html_output .= PMA_getAddUserHtmlFieldset($conditional_class); } // end if (display overview) @@ -2734,7 +2799,8 @@ function PMA_getHtmlForDisplayUserProperties($dbname_is_wildcard,$url_dbname, // no table name was given, display all table specific rights // but only if $dbname contains no wildcards - $html_output .= '' . "\n"; + $html_output .= '' . "\n"; list($html_rightsTable, $found_rows) = PMA_getTableForDisplayAllTableSpecificRights( $username, $hostname, $link_edit, $link_revoke, $dbname @@ -2947,7 +3013,8 @@ function PMA_addUserAndCreateDatabase($_error, $real_sql_query, $sql_query, $use // Grant all privileges on wildcard name (username\_%) $q = 'GRANT ALL PRIVILEGES ON ' . $common_functions->backquote($common_functions->sqlAddSlashes($username) . '\_%') . '.* TO \'' - . $common_functions->sqlAddSlashes($username) . '\'@\'' . $common_functions->sqlAddSlashes($hostname) . '\';'; + . $common_functions->sqlAddSlashes($username) + . '\'@\'' . $common_functions->sqlAddSlashes($hostname) . '\';'; $sql_query .= $q; if (! PMA_DBI_try_query($q)) { $message = PMA_Message::rawError(PMA_DBI_getError()); @@ -2958,7 +3025,8 @@ function PMA_addUserAndCreateDatabase($_error, $real_sql_query, $sql_query, $use // Grant all privileges on the specified database to the new user $q = 'GRANT ALL PRIVILEGES ON ' . $common_functions->backquote($common_functions->sqlAddSlashes($dbname)) . '.* TO \'' - . $common_functions->sqlAddSlashes($username) . '\'@\'' . $common_functions->sqlAddSlashes($hostname) . '\';'; + . $common_functions->sqlAddSlashes($username) + . '\'@\'' . $common_functions->sqlAddSlashes($hostname) . '\';'; $sql_query .= $q; if (! PMA_DBI_try_query($q)) { $message = PMA_Message::rawError(PMA_DBI_getError());