From bfb6dec7e6b08e774393b93da73b47aa899cd76c Mon Sep 17 00:00:00 2001 From: xmujay Date: Sat, 8 Jun 2013 00:02:45 +0800 Subject: [PATCH] fix the issues: 1. replace tab with space in server_bin_log.lib.php 2. move $bin_log to server_binlog.php 3. add server common function file server_common.lib.php --- libraries/server_bin_log.lib.php | 380 +++++++++++++++---------------- libraries/server_common.inc.php | 35 +-- libraries/server_common.lib.php | 36 +++ server_binlog.php | 14 +- 4 files changed, 241 insertions(+), 224 deletions(-) create mode 100644 libraries/server_common.lib.php diff --git a/libraries/server_bin_log.lib.php b/libraries/server_bin_log.lib.php index 6adf498cd7..a1dcdfc585 100644 --- a/libraries/server_bin_log.lib.php +++ b/libraries/server_bin_log.lib.php @@ -23,48 +23,48 @@ if (! defined('PHPMYADMIN')) { */ function PMA_getLogSelector($binary_log_file_names, $url_params) { - $html = ""; - if (count($binary_log_file_names) > 1) { - $html .= '
'; - $html .= PMA_generate_common_hidden_inputs($url_params); - $html .= '
'; - $html .= __('Select binary log to view'); - $html .= ''; - $html .= '
'; - $html .= '
'; - } - - return $html; + $html = ""; + if (count($binary_log_file_names) > 1) { + $html .= '
'; + $html .= PMA_generate_common_hidden_inputs($url_params); + $html .= '
'; + $html .= __('Select binary log to view'); + $html .= ''; + $html .= '
'; + $html .= '
'; + } + + return $html; } /** @@ -78,74 +78,74 @@ function PMA_getLogSelector($binary_log_file_names, $url_params) */ function PMA_getLogInfo($binary_log_file_names, $url_params) { - /** - * Need to find the real end of rows? - */ - if (! isset($_REQUEST['pos'])) { - $pos = 0; - } else { - /* We need this to be a integer */ - $pos = (int) $_REQUEST['pos']; - } - - $sql_query = 'SHOW BINLOG EVENTS'; - if (! empty($_REQUEST['log'])) { - $sql_query .= ' IN \'' . $_REQUEST['log'] . '\''; - } - if ($GLOBALS['cfg']['MaxRows'] !== 'all') { - $sql_query .= ' LIMIT ' . $pos . ', ' . (int) $GLOBALS['cfg']['MaxRows']; - } - - /** - * Sends the query - */ - $result = $GLOBALS['dbi']->query($sql_query); - - /** - * prepare some vars for displaying the result table - */ - // Gets the list of fields properties - if (isset($result) && $result) { - $num_rows = $GLOBALS['dbi']->numRows($result); - } else { - $num_rows = 0; - } - - if (empty($_REQUEST['dontlimitchars'])) { - $dontlimitchars = false; - } else { - $dontlimitchars = true; - $url_params['dontlimitchars'] = 1; - } + /** + * Need to find the real end of rows? + */ + if (! isset($_REQUEST['pos'])) { + $pos = 0; + } else { + /* We need this to be a integer */ + $pos = (int) $_REQUEST['pos']; + } + + $sql_query = 'SHOW BINLOG EVENTS'; + if (! empty($_REQUEST['log'])) { + $sql_query .= ' IN \'' . $_REQUEST['log'] . '\''; + } + if ($GLOBALS['cfg']['MaxRows'] !== 'all') { + $sql_query .= ' LIMIT ' . $pos . ', ' . (int) $GLOBALS['cfg']['MaxRows']; + } + + /** + * Sends the query + */ + $result = $GLOBALS['dbi']->query($sql_query); + + /** + * prepare some vars for displaying the result table + */ + // Gets the list of fields properties + if (isset($result) && $result) { + $num_rows = $GLOBALS['dbi']->numRows($result); + } else { + $num_rows = 0; + } + + if (empty($_REQUEST['dontlimitchars'])) { + $dontlimitchars = false; + } else { + $dontlimitchars = true; + $url_params['dontlimitchars'] = 1; + } - //html output - $html = PMA_Util::getMessage(PMA_Message::success(), $sql_query); - $html .= '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . ''; - - $html .= PMA_getAllLogItemInfo($result, $dontlimitchars); - - $html .= '' - . '
'; - - $html .= PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars); - - $html .= '
' . __('Log name') . '' . __('Position') . '' . __('Event type') . '' . __('Server ID') . '' . __('Original position') . '' . __('Information') . '
'; - - return $html; + //html output + $html = PMA_Util::getMessage(PMA_Message::success(), $sql_query); + $html .= '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . ''; + + $html .= PMA_getAllLogItemInfo($result, $dontlimitchars); + + $html .= '' + . '
'; + + $html .= PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars); + + $html .= '
' . __('Log name') . '' . __('Position') . '' . __('Event type') . '' . __('Server ID') . '' . __('Original position') . '' . __('Information') . '
'; + + return $html; } /** @@ -163,60 +163,60 @@ function PMA_getLogInfo($binary_log_file_names, $url_params) */ function PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars) { - $html = ""; - // we do not know how much rows are in the binlog - // so we can just force 'NEXT' button - if ($pos > 0) { - $this_url_params = $url_params; - if ($pos > $GLOBALS['cfg']['MaxRows']) { - $this_url_params['pos'] = $pos - $GLOBALS['cfg']['MaxRows']; - } - - $html .= ''; - } else { - $html .= '>' . _pgettext('Previous page', 'Previous'); - } // end if... else... - $html .= ' < - '; - } - - $this_url_params = $url_params; - if ($pos > 0) { - $this_url_params['pos'] = $pos; - } - if ($dontlimitchars) { - unset($this_url_params['dontlimitchars']); - $tempTitle = __('Truncate Shown Queries'); - $tempImgMode = 'partial'; - } else { - $this_url_params['dontlimitchars'] = 1; - $tempTitle = __('Show Full Queries'); - $tempImgMode = 'full'; - } - $html .= '' - . ''; - - // we do not now how much rows are in the binlog - // so we can just force 'NEXT' button - if ($num_rows >= $GLOBALS['cfg']['MaxRows']) { - $this_url_params = $url_params; - $this_url_params['pos'] = $pos + $GLOBALS['cfg']['MaxRows']; - $html .= ' - '; - } else { - $html .= '>' . _pgettext('Next page', 'Next'); - } // end if... else... - $html .= ' > '; - } - - return $html; + $html = ""; + // we do not know how much rows are in the binlog + // so we can just force 'NEXT' button + if ($pos > 0) { + $this_url_params = $url_params; + if ($pos > $GLOBALS['cfg']['MaxRows']) { + $this_url_params['pos'] = $pos - $GLOBALS['cfg']['MaxRows']; + } + + $html .= ''; + } else { + $html .= '>' . _pgettext('Previous page', 'Previous'); + } // end if... else... + $html .= ' < - '; + } + + $this_url_params = $url_params; + if ($pos > 0) { + $this_url_params['pos'] = $pos; + } + if ($dontlimitchars) { + unset($this_url_params['dontlimitchars']); + $tempTitle = __('Truncate Shown Queries'); + $tempImgMode = 'partial'; + } else { + $this_url_params['dontlimitchars'] = 1; + $tempTitle = __('Show Full Queries'); + $tempImgMode = 'full'; + } + $html .= '' + . ''; + + // we do not now how much rows are in the binlog + // so we can just force 'NEXT' button + if ($num_rows >= $GLOBALS['cfg']['MaxRows']) { + $this_url_params = $url_params; + $this_url_params['pos'] = $pos + $GLOBALS['cfg']['MaxRows']; + $html .= ' - '; + } else { + $html .= '>' . _pgettext('Next page', 'Next'); + } // end if... else... + $html .= ' > '; + } + + return $html; } /** @@ -230,33 +230,33 @@ function PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars) */ function PMA_getAllLogItemInfo($result, $dontlimitchars) { - $html = ""; - $odd_row = true; - while ($value = $GLOBALS['dbi']->fetchAssoc($result)) { - if (! $dontlimitchars - && PMA_strlen($value['Info']) > $GLOBALS['cfg']['LimitChars'] - ) { - $value['Info'] = PMA_substr( - $value['Info'], 0, $GLOBALS['cfg']['LimitChars'] - ) . '...'; - } - - $html .= '' - . ' ' . $value['Log_name'] . ' ' - . ' ' . $value['Pos'] . ' ' - . ' ' . $value['Event_type'] . ' ' - . ' ' . $value['Server_id'] . ' ' - . ' ' - . (isset($value['Orig_log_pos']) - ? $value['Orig_log_pos'] : $value['End_log_pos']) - . ' ' - . '
 ' . htmlspecialchars($value['Info'])
-	        . ' 
' - . ''; - - $odd_row = !$odd_row; - } - return $html; + $html = ""; + $odd_row = true; + while ($value = $GLOBALS['dbi']->fetchAssoc($result)) { + if (! $dontlimitchars + && PMA_strlen($value['Info']) > $GLOBALS['cfg']['LimitChars'] + ) { + $value['Info'] = PMA_substr( + $value['Info'], 0, $GLOBALS['cfg']['LimitChars'] + ) . '...'; + } + + $html .= '' + . ' ' . $value['Log_name'] . ' ' + . ' ' . $value['Pos'] . ' ' + . ' ' . $value['Event_type'] . ' ' + . ' ' . $value['Server_id'] . ' ' + . ' ' + . (isset($value['Orig_log_pos']) + ? $value['Orig_log_pos'] : $value['End_log_pos']) + . ' ' + . '
 ' . htmlspecialchars($value['Info'])
+            . ' 
' + . ''; + + $odd_row = !$odd_row; + } + return $html; } ?> diff --git a/libraries/server_common.inc.php b/libraries/server_common.inc.php index 485c7bc579..ad6caa203f 100644 --- a/libraries/server_common.inc.php +++ b/libraries/server_common.inc.php @@ -39,44 +39,13 @@ if ($is_superuser && ! PMA_DRIZZLE) { $GLOBALS['dbi']->selectDb('mysql', $userlink); } -/** - * @global array binary log files - */ -$binary_logs = PMA_DRIZZLE - ? null - : $GLOBALS['dbi']->fetchResult( - 'SHOW MASTER LOGS', - 'Log_name', - null, - null, - PMA_DatabaseInterface::QUERY_STORE - ); - PMA_Util::checkParameters( array('is_superuser', 'url_query'), false ); /** - * Returns the html for the sub-page heading - * - * @param string $type Sub page type - * - * @return string + * shared functions for server page */ -function PMA_getSubPageHeader($type) -{ - $res = array(); +require_once './libraries/server_common.lib.php'; - $res['plugins']['icon'] = 'b_engine.png'; - $res['plugins']['text'] = __('Plugins'); - - $res['binlog']['icon'] = 's_tbl.png'; - $res['binlog']['text'] = __('Binary log'); - - $html = '

' . "\n" - . PMA_Util::getImage($res[$type]['icon']) - . ' ' . $res[$type]['text'] . "\n" - . '

' . "\n"; - return $html; -} ?> diff --git a/libraries/server_common.lib.php b/libraries/server_common.lib.php new file mode 100644 index 0000000000..1b99c3c623 --- /dev/null +++ b/libraries/server_common.lib.php @@ -0,0 +1,36 @@ +' . "\n" + . PMA_Util::getImage($res[$type]['icon']) + . ' ' . $res[$type]['text'] . "\n" + . '' . "\n"; + return $html; +} + +?> diff --git a/server_binlog.php b/server_binlog.php index 022697f5f5..45d08494fa 100644 --- a/server_binlog.php +++ b/server_binlog.php @@ -12,12 +12,24 @@ require_once 'libraries/common.inc.php'; /** - * Does the common work, provides $binary_logs + * Does the common work */ require_once 'libraries/server_common.inc.php'; require_once 'libraries/server_bin_log.lib.php'; +/** + * array binary log files + */ +$binary_logs = PMA_DRIZZLE + ? null + : $GLOBALS['dbi']->fetchResult( + 'SHOW MASTER LOGS', + 'Log_name', + null, + null, + PMA_DatabaseInterface::QUERY_STORE + ); if (! isset($_REQUEST['log']) || ! array_key_exists($_REQUEST['log'], $binary_logs)