From 46262835b6eb88290fbe32eec53c71b2568360a4 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Fri, 19 Aug 2011 10:03:35 +0530 Subject: [PATCH 01/32] Only non-empty search values should go into where clause --- libraries/tbl_select.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/tbl_select.lib.php b/libraries/tbl_select.lib.php index af97aa434e..bec997f871 100644 --- a/libraries/tbl_select.lib.php +++ b/libraries/tbl_select.lib.php @@ -342,7 +342,7 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $fu $fields = ''; $w = $backquoted_name . ' ' . $func_type; - } elseif (in_array($types, PMA_getGISDatatypes())) { + } elseif (in_array($types, PMA_getGISDatatypes()) && ! empty($fields)) { // create gis data from the string $gis_data = PMA_createGISData($fields); $w = $backquoted_name . ' ' . $func_type . ' ' . $gis_data; From 2d4a4427ef861373065b8630d5d6b6377c425eb3 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Fri, 19 Aug 2011 10:42:57 +0530 Subject: [PATCH 02/32] Fix doc blocks --- libraries/tbl_select.lib.php | 137 +++++++++++++---------------------- 1 file changed, 51 insertions(+), 86 deletions(-) diff --git a/libraries/tbl_select.lib.php b/libraries/tbl_select.lib.php index bec997f871..d97c12cb1e 100644 --- a/libraries/tbl_select.lib.php +++ b/libraries/tbl_select.lib.php @@ -11,15 +11,14 @@ require_once 'url_generating.lib.php'; - /** - * PMA_tbl_setTitle() sets the title for foreign keys display link +/** + * Sets the title for foreign keys display link. * - * @param $propertiesIconic Type of icon property - * @param $themeImage Icon Image - * @return string $str Value of the Title + * @param mixed $propertiesIconic Type of icon property + * @param string $pmaThemeImage Icon Image * + * @return string $str Value of the Title */ - function PMA_tbl_setTitle($propertiesIconic,$pmaThemeImage){ if ($propertiesIconic == true) { $str = '' . __('Browse foreign values') . ''; + .'b_browse.png" alt="' . __('Browse foreign values') . '" title="' + . __('Browse foreign values') . '" />'; - if ($propertiesIconic === 'both') { - $str .= __('Browse foreign values'); + if ($propertiesIconic === 'both') { + $str .= __('Browse foreign values'); return $str; - } - } else { - return __('Browse foreign values'); - } + } + } else { + return __('Browse foreign values'); + } } /** @@ -113,7 +113,7 @@ return ' ' . __('Collation') . ' ' . __('Operator') . ' ' . __('Value') . ' - + '; @@ -184,19 +184,19 @@ function PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fie } elseif ($foreignData['foreign_link'] == true) { if(isset($fields[$i]) && is_string($fields[$i])){ - $str .= '' ; + $str .= '' ; } else{ - $str .= '' ; + $str .= '' ; } ?> - '; + '; // ' . str_replace("'", "\'", $titles['Browse']) . ''; From 4f438c33170e44f16282156540a1a6ab0b097035 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Fri, 19 Aug 2011 11:07:11 +0530 Subject: [PATCH 04/32] Coding style corrections --- libraries/tbl_select.lib.php | 40 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/libraries/tbl_select.lib.php b/libraries/tbl_select.lib.php index d14db6cc21..4aaddc0bc7 100644 --- a/libraries/tbl_select.lib.php +++ b/libraries/tbl_select.lib.php @@ -19,14 +19,15 @@ require_once 'url_generating.lib.php'; * * @return string $str Value of the Title */ -function PMA_tbl_setTitle($propertiesIconic,$pmaThemeImage){ +function PMA_tbl_setTitle($propertiesIconic,$pmaThemeImage) +{ if ($propertiesIconic == true) { $str = '' . __('Browse foreign values') . ''; - if ($propertiesIconic === 'both') { - $str .= __('Browse foreign values'); + if ($propertiesIconic === 'both') { + $str .= __('Browse foreign values'); return $str; } } else { @@ -44,28 +45,33 @@ function PMA_tbl_setTitle($propertiesIconic,$pmaThemeImage){ * @return array Array containing the field list, field types, collations * and null constraint */ -function PMA_tbl_getFields($table,$db) { - +function PMA_tbl_getFields($table,$db) +{ // Gets the list and number of fields - - $result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_query( + 'SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';', + null, PMA_DBI_QUERY_STORE + ); $fields_cnt = PMA_DBI_num_rows($result); $fields_list = $fields_null = $fields_type = $fields_collation = array(); $geom_column_present = false; $geom_types = PMA_getGISDatatypes(); + while ($row = PMA_DBI_fetch_assoc($result)) { $fields_list[] = $row['Field']; $type = $row['Type']; + // check whether table contains geometric columns if (in_array($type, $geom_types)) { $geom_column_present = true; } + // reformat mysql query output if (strncasecmp($type, 'set', 3) == 0 - || strncasecmp($type, 'enum', 4) == 0) { + || strncasecmp($type, 'enum', 4) == 0 + ) { $type = str_replace(',', ', ', $type); } else { - // strip the "BINARY" attribute, except if we find "BINARY(" because // this would be a BINARY or VARBINARY field type if (!preg_match('@BINARY[\(]@i', $type)) { @@ -81,7 +87,7 @@ function PMA_tbl_getFields($table,$db) { } $fields_null[] = $row['Null']; $fields_type[] = $type; - $fields_collation[] = !empty($row['Collation']) && $row['Collation'] != 'NULL' + $fields_collation[] = ! empty($row['Collation']) && $row['Collation'] != 'NULL' ? $row['Collation'] : ''; } // end while @@ -99,21 +105,21 @@ function PMA_tbl_getFields($table,$db) { * * @return HTML content, the tags and content for table header */ -function PMA_tbl_setTableHeader($geom_column_present = false){ - +function PMA_tbl_setTableHeader($geom_column_present = false) +{ // Display the Function column only if there is alteast one geomety colum $func = ''; if ($geom_column_present) { $func = '' . __('Function') . ''; } -return ' + return ' ' . $func . '' . __('Column') . ' ' . __('Type') . ' ' . __('Collation') . ' ' . __('Operator') . ' ' . __('Value') . ' - + '; @@ -126,10 +132,9 @@ return ' * @return array Array containing configuration (icon, text, link, id, args) * of sub-tabs for Table Search and Zoom search */ -function PMA_tbl_getSubTabs(){ - +function PMA_tbl_getSubTabs() +{ $subtabs = array(); - $subtabs['search']['icon'] = 'b_search.png'; $subtabs['search']['text'] = __('Table Search'); $subtabs['search']['link'] = 'tbl_select.php'; @@ -142,7 +147,6 @@ function PMA_tbl_getSubTabs(){ $subtabs['zoom']['id'] = 'zoom_search_id'; return $subtabs; - } /** From 77b2b7627d714f2621c5d320b5cfe5450229b7a5 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Fri, 19 Aug 2011 11:21:21 +0530 Subject: [PATCH 05/32] Adhere to PEAR coding standards --- libraries/tbl_select.lib.php | 69 +++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/libraries/tbl_select.lib.php b/libraries/tbl_select.lib.php index 4aaddc0bc7..b2eb0b0e57 100644 --- a/libraries/tbl_select.lib.php +++ b/libraries/tbl_select.lib.php @@ -88,13 +88,13 @@ function PMA_tbl_getFields($table,$db) $fields_null[] = $row['Null']; $fields_type[] = $type; $fields_collation[] = ! empty($row['Collation']) && $row['Collation'] != 'NULL' - ? $row['Collation'] - : ''; + ? $row['Collation'] + : ''; } // end while PMA_DBI_free_result($result); unset($result, $type); - return array($fields_list,$fields_type,$fields_collation,$fields_null, $geom_column_present); + return array($fields_list, $fields_type, $fields_collation, $fields_null, $geom_column_present); } @@ -121,8 +121,6 @@ function PMA_tbl_setTableHeader($geom_column_present = false) ' . __('Value') . ' '; - - } /** @@ -286,7 +284,6 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $fu ); $w = ''; - // If geometry function is set apply it to the field name if ($geom_func != null && trim($geom_func) != '') { // Get details about the geometry fucntions @@ -295,8 +292,8 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $fu // If the function takes a single parameter if ($geom_funcs[$geom_func]['params'] == 1) { $backquoted_name = $geom_func . '(' . PMA_backquote($names) . ')'; - // If the function takes two parameters } else { + // If the function takes two parameters // create gis data from the string $gis_data = PMA_createGISData($fields); @@ -307,7 +304,7 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $fu // New output type is the output type of the function being applied $types = $geom_funcs[$geom_func]['type']; - // If the intended where clause is something like 'IsEmpty(`spatial_col_name`)' + // If the where clause is something like 'IsEmpty(`spatial_col_name`)' if (isset($geom_unary_functions[$geom_func]) && trim($fields) == '') { $w = $backquoted_name; return $w; @@ -316,9 +313,9 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $fu $backquoted_name = PMA_backquote($names); } - if($unaryFlag){ + if ($unaryFlag) { $fields = ''; - $w = $backquoted_name . ' ' . $func_type; + $w = $backquoted_name . ' ' . $func_type; } elseif (in_array($types, PMA_getGISDatatypes()) && ! empty($fields)) { // create gis data from the string @@ -341,23 +338,25 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $fu $parens_open = '('; $parens_close = ')'; - } else { - $parens_open = ''; - $parens_close = ''; - } - $enum_where = '\'' . PMA_sqlAddslashes($fields[0]) . '\''; - for ($e = 1; $e < $enum_selected_count; $e++) { - $enum_where .= ', \'' . PMA_sqlAddslashes($fields[$e]) . '\''; - } + } else { + $parens_open = ''; + $parens_close = ''; + } + $enum_where = '\'' . PMA_sqlAddslashes($fields[0]) . '\''; + for ($e = 1; $e < $enum_selected_count; $e++) { + $enum_where .= ', \'' . PMA_sqlAddslashes($fields[$e]) . '\''; + } - $w = $backquoted_name . ' ' . $func_type . ' ' . $parens_open . $enum_where . $parens_close; + $w = $backquoted_name . ' ' . $func_type . ' ' . $parens_open . $enum_where . $parens_close; } } elseif ($fields != '') { // For these types we quote the value. Even if it's another type (like INT), // for a LIKE we always quote the value. MySQL converts strings to numbers // and numbers to strings as necessary during the comparison - if (preg_match('@char|binary|blob|text|set|date|time|year@i', $types) || strpos(' ' . $func_type, 'LIKE')) { + if (preg_match('@char|binary|blob|text|set|date|time|year@i', $types) + || strpos(' ' . $func_type, 'LIKE') + ) { $quot = '\''; } else { $quot = ''; @@ -373,23 +372,28 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $fu $fields = '^' . $fields . '$'; } - if ($func_type == 'IN (...)' || $func_type == 'NOT IN (...)' || $func_type == 'BETWEEN' || $func_type == 'NOT BETWEEN') { + if ($func_type == 'IN (...)' + || $func_type == 'NOT IN (...)' + || $func_type == 'BETWEEN' + || $func_type == 'NOT BETWEEN' + ) { $func_type = str_replace(' (...)', '', $func_type); - // quote values one by one - $values = explode(',', $fields); - foreach ($values as &$value) - $value = $quot . PMA_sqlAddslashes(trim($value)) . $quot; + // quote values one by one + $values = explode(',', $fields); + foreach ($values as &$value) { + $value = $quot . PMA_sqlAddslashes(trim($value)) . $quot; + } - if ($func_type == 'BETWEEN' || $func_type == 'NOT BETWEEN') - $w = $backquoted_name . ' ' . $func_type . ' ' . (isset($values[0]) ? $values[0] : '') . ' AND ' . (isset($values[1]) ? $values[1] : ''); - else + if ($func_type == 'BETWEEN' || $func_type == 'NOT BETWEEN') { + $w = $backquoted_name . ' ' . $func_type . ' ' . (isset($values[0]) ? $values[0] : '') + . ' AND ' . (isset($values[1]) ? $values[1] : ''); + } else { $w = $backquoted_name . ' ' . $func_type . ' (' . implode(',', $values) . ')'; - } - else { + } + } else { $w = $backquoted_name . ' ' . $func_type . ' ' . $quot . PMA_sqlAddslashes($fields) . $quot;; } - } // end if return $w; @@ -405,7 +409,7 @@ function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $fu */ function PMA_SVG_scatter_plot($data, &$settings) { - require_once './libraries/svg_plot/pma_scatter_plot.php'; + include_once './libraries/svg_plot/pma_scatter_plot.php'; if (empty($data)) { // empty data @@ -422,6 +426,5 @@ function PMA_SVG_scatter_plot($data, &$settings) } return $scatter_plot->asSVG(); } - } ?> From c5b393665ca77d719bc67290cc4ddd003354cf4a Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Fri, 19 Aug 2011 13:36:28 +0530 Subject: [PATCH 06/32] More code style corrections --- libraries/tbl_select.lib.php | 82 +++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/libraries/tbl_select.lib.php b/libraries/tbl_select.lib.php index b2eb0b0e57..bcfe96caaa 100644 --- a/libraries/tbl_select.lib.php +++ b/libraries/tbl_select.lib.php @@ -95,7 +95,6 @@ function PMA_tbl_getFields($table,$db) unset($result, $type); return array($fields_list, $fields_type, $fields_collation, $fields_null, $geom_column_present); - } /** @@ -167,24 +166,23 @@ function PMA_tbl_getSubTabs() * @return string HTML content for viewing foreing data and elements * for search criteria input. */ -function PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i, $db, $table, $titles, $foreignMaxLimit, $fields, $in_fbs = false){ - +function PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i, $db, $table, $titles, $foreignMaxLimit, $fields, $in_fbs = false) +{ $str = ''; - if ($foreigners && isset($foreigners[$field]) && is_array($foreignData['disp_row'])) { // f o r e i g n k e y s - $str .= ' ' . "\n"; // go back to first row // here, the 4th parameter is empty because there is no current // value of data for the dropdown (the search page initial values // are displayed empty) - $str .= PMA_foreignDropdown($foreignData['disp_row'], - $foreignData['foreign_field'], - $foreignData['foreign_display'], - '', $foreignMaxLimit); - $str .= ' ' . "\n"; - } - elseif ($foreignData['foreign_link'] == true) { + $str .= PMA_foreignDropdown( + $foreignData['disp_row'], $foreignData['foreign_field'], + $foreignData['foreign_display'], '', $foreignMaxLimit + ); + $str .= '' . "\n"; + + } elseif ($foreignData['foreign_link'] == true) { if(isset($fields[$i]) && is_string($fields[$i])){ $str .= '' . str_replace("'", "\'", $titles['Browse']) . ''; // ]] $str .= ''; + } elseif (in_array($tbl_fields_type[$i], PMA_getGISDatatypes())) { // g e o m e t r y $str .= '' . "\n"; - for ($j = 0; $j < $cnt_enum_value; $j++) { - if(isset($fields[$i]) && is_array($fields[$i]) && in_array($enum_value[$j],$fields[$i])){ - $str .= ' '; - } - else{ - $str .= ' '; - } - } // end for - $str .= ' ' . "\n"; - } - else { + .' multiple="multiple" size="' . min(3, $cnt_enum_value) . '">' . "\n"; + + for ($j = 0; $j < $cnt_enum_value; $j++) { + if (isset($fields[$i]) + && is_array($fields[$i]) + && in_array($enum_value[$j], $fields[$i]) + ) { + $str .= ''; + } else { + $str .= ''; + } + } // end for + $str .= '' . "\n"; + + } else { // o t h e r c a s e s $the_class = 'textfield'; $type = $tbl_fields_type[$i]; + if ($type == 'date') { $the_class .= ' datefield'; } elseif ($type == 'datetime' || substr($type, 0, 9) == 'timestamp') { $the_class .= ' datetimefield'; } - if(isset($fields[$i]) && is_string($fields[$i])){ - $str .= ' ' . "\n"; - } - else{ - $str .= ' ' . "\n"; - } - }; - return $str; + if (isset($fields[$i]) && is_string($fields[$i])) { + $str .= '' . "\n"; + } else { + $str .= '' . "\n"; + } + } + return $str; } - /** * Return the where clause for query generation based on the inputs provided. * @@ -271,8 +275,8 @@ EOT; * @return string HTML content for viewing foreing data and elements * for search criteria input. */ -function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $func_type, $unaryFlag, $geom_func = null){ - +function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $func_type, $unaryFlag, $geom_func = null) +{ /** * @todo move this to a more apropriate place */ From d2df35108eb6fb98199cde72b4b9fbf00f9e1fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:33:13 +0200 Subject: [PATCH 07/32] Wrap some long lines --- libraries/core.lib.php | 3 ++- server_status.php | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libraries/core.lib.php b/libraries/core.lib.php index dcc5208bc6..909f5db66f 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -708,7 +708,8 @@ function PMA_includeJS($url) } /** - * Adds JS code snippets to be displayed by header.inc.php. Adds a newline to each snippet. + * Adds JS code snippets to be displayed by header.inc.php. Adds a + * newline to each snippet. * * @param string $str Js code to be added (e.g. "token=1234;") * diff --git a/server_status.php b/server_status.php index 7c2f30a658..4e215a445a 100644 --- a/server_status.php +++ b/server_status.php @@ -620,7 +620,8 @@ $links['innodb']['doc'] = 'innodb'; // Variable to contain all com_ variables $used_queries = array(); -// Variable to map variable names to their respective section name (used for js category filtering) +// Variable to map variable names to their respective section name +// (used for js category filtering) $allocationMap = array(); // sort vars into arrays @@ -637,10 +638,15 @@ foreach ($server_status as $name => $value) { } if(PMA_DRIZZLE) { - $used_queries = PMA_DBI_fetch_result('SELECT * FROM data_dictionary.global_statements', 0, 1); + $used_queries = PMA_DBI_fetch_result( + 'SELECT * FROM data_dictionary.global_statements', + 0, + 1 + ); unset($used_queries['admin_commands']); } else { - // admin commands are not queries (e.g. they include COM_PING, which is excluded from $server_status['Questions']) + // admin commands are not queries (e.g. they include COM_PING, + // which is excluded from $server_status['Questions']) unset($used_queries['Com_admin_commands']); } From 17f4b82821695fba5317cb98dc86a692ccc11015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:35:00 +0200 Subject: [PATCH 08/32] Factor out code escaping from echo --- libraries/js_escape.lib.php | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/libraries/js_escape.lib.php b/libraries/js_escape.lib.php index 656794f819..25fb5bfbc7 100644 --- a/libraries/js_escape.lib.php +++ b/libraries/js_escape.lib.php @@ -56,25 +56,42 @@ function PMA_escapeJsString($string) "\r" => '\r'))); } +/** + * Formats an javascript assignment with proper escaping of a value + * and support for assigning array of strings. + * + * @param string $key Name of value to set + * @param mixed $value Value to set, can be either string or array of strings + * + * @return string Javascript code. + */ +function PMA_getJsValue($key, $value) +{ + $result = $key . ' = '; + if (is_array($value)) { + $result .= '['; + foreach ($value as $id => $val) { + $result .= "'" . PMA_escapeJsString($val) . "',"; + } + $result .= "];\n"; + } else { + $result .= "'" . PMA_escapeJsString($value) . "';\n"; + } + return $result; +} + /** * Prints an javascript assignment with proper escaping of a value * and support for assigning array of strings. * * @param string $key Name of value to set * @param mixed $value Value to set, can be either string or array of strings + * + * @return nothing */ function PMA_printJsValue($key, $value) { - echo $key . ' = '; - if (is_array($value)) { - echo '['; - foreach ($value as $id => $val) { - echo "'" . PMA_escapeJsString($val) . "',"; - } - echo "];\n"; - } else { - echo "'" . PMA_escapeJsString($value) . "';\n"; - } + echo PMA_getJsValue($key, $value); } ?> From 4b5ae952dd6486735ed066b69e22962af72f80c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:36:22 +0200 Subject: [PATCH 09/32] Function for setting variable --- libraries/core.lib.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/core.lib.php b/libraries/core.lib.php index 909f5db66f..a277f29629 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -714,8 +714,21 @@ function PMA_includeJS($url) * @param string $str Js code to be added (e.g. "token=1234;") * */ -function PMA_AddJSCode($str) { +function PMA_AddJSCode($str) +{ $GLOBALS['js_script'][] = $str; } +/** + * Adds JS code snippet for variable assignment to be displayed by header.inc.php. + * + * @param string $key Name of value to set + * @param mixed $value Value to set, can be either string or array of strings + * + */ +function PMA_AddJSVar($key, $value) +{ + PMA_AddJsCode(PMA_getJsValue($key, $value)); +} + ?> From 1b45290d5551a5619dcd1e29cd8956e30aeb690f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:38:51 +0200 Subject: [PATCH 10/32] Use PMA_AddJSVar --- server_status.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server_status.php b/server_status.php index 4e215a445a..30c3c5a850 100644 --- a/server_status.php +++ b/server_status.php @@ -673,14 +673,14 @@ $server_db_isLocal = strtolower($cfg['Server']['host']) == 'localhost' || $cfg['Server']['host'] == '127.0.0.1' || $cfg['Server']['host'] == '::1'; -PMA_AddJSCode('pma_token = \'' . $_SESSION[' PMA_token '] . "';\n" . - 'url_query = \'' . str_replace('&', '&', PMA_generate_common_url($db)) . "';\n" . - 'server_time_diff = new Date().getTime() - ' . (microtime(true) * 1000) . ";\n" . - 'server_os = \'' . PHP_OS . "';\n" . - 'is_superuser = ' . (PMA_isSuperuser() ? 'true' : 'false') . ";\n" . - 'server_db_isLocal = ' . ($server_db_isLocal ? 'true' : 'false') . ";\n" . - 'profiling_docu = \'' . PMA_showMySQLDocu('general-thread-states', 'general-thread-states') . "';\n" . - 'explain_docu = \'' . PMA_showMySQLDocu('explain-output', 'explain-output') . ";'\n"); +PMA_AddJSVar('pma_token', $_SESSION[' PMA_token ']); +PMA_AddJSVar('url_query', str_replace('&', '&', PMA_generate_common_url($db))); +PMA_AddJSVar('server_time_diff', 'new Date().getTime() - ' . (microtime(true) * 1000)); +PMA_AddJSVar('server_os', PHP_OS); +PMA_AddJSVar('is_superuser', PMA_isSuperuser() ? true : false); +PMA_AddJSVar('server_db_isLocal', $server_db_isLocal ? true : false); +PMA_AddJSVar('profiling_docu', PMA_showMySQLDocu('general-thread-states', 'general-thread-states')); +PMA_AddJSVar('explain_docu', PMA_showMySQLDocu('explain-output', 'explain-output')); /** * start output From 38e8365e5d502120534b8fa60a22d210eb8b1760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:39:45 +0200 Subject: [PATCH 11/32] Use PMA_AddJSVar --- server_variables.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server_variables.php b/server_variables.php index 4c2086ab89..af47f1fe83 100644 --- a/server_variables.php +++ b/server_variables.php @@ -16,9 +16,9 @@ require_once './libraries/common.inc.php'; $GLOBALS['js_include'][] = 'server_variables.js'; -PMA_AddJSCode('pma_token = \'' . $_SESSION[' PMA_token '] . "';\n" . - 'is_superuser = ' . (PMA_isSuperuser() ? 'true' : 'false') . ";\n" . - 'url_query = \'' . str_replace('&', '&', PMA_generate_common_url($db)) . "';\n"); +PMA_AddJSVar('pma_token', $_SESSION[' PMA_token ']); +PMA_AddJSVar('url_query', str_replace('&', '&', PMA_generate_common_url($db))); +PMA_AddJSVar('is_superuser', PMA_isSuperuser() ? true : false); /** @@ -179,4 +179,4 @@ function formatVariable($name,$value) */ require './libraries/footer.inc.php'; -?> \ No newline at end of file +?> From fb1c4bd9ee35e3b873bf0cb28a11ca860a09384e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:43:08 +0200 Subject: [PATCH 12/32] Handle more types in js variable formatting --- libraries/js_escape.lib.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libraries/js_escape.lib.php b/libraries/js_escape.lib.php index 25fb5bfbc7..85b62e1e53 100644 --- a/libraries/js_escape.lib.php +++ b/libraries/js_escape.lib.php @@ -56,6 +56,27 @@ function PMA_escapeJsString($string) "\r" => '\r'))); } +/** + * Formats a value for javascript code. + * + * @param string $value String to be formatted. + * + * @retrun string formatted value. + */ +function PMA_formatJsVal($value) +{ + if (is_bool($value)) { + if ($value) { + return 'true'; + } else { + return 'false'; + } else if (is_int($value)) { + return int($value); + } else { + return '"' . PMA_escapeJsString($value) . '"'; + } +} + /** * Formats an javascript assignment with proper escaping of a value * and support for assigning array of strings. @@ -71,11 +92,11 @@ function PMA_getJsValue($key, $value) if (is_array($value)) { $result .= '['; foreach ($value as $id => $val) { - $result .= "'" . PMA_escapeJsString($val) . "',"; + $result .= PMA_formatJsVal($value) . ","; } $result .= "];\n"; } else { - $result .= "'" . PMA_escapeJsString($value) . "';\n"; + $result .= PMA_formatJsVal($value) . ";\n"; } return $result; } From e479f1c8431eb3a1b138d7812a1ab0f6d1020188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:47:45 +0200 Subject: [PATCH 13/32] Add test for js escaping --- test/libraries/js_escape_test.php | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/libraries/js_escape_test.php diff --git a/test/libraries/js_escape_test.php b/test/libraries/js_escape_test.php new file mode 100644 index 0000000000..d29fcff743 --- /dev/null +++ b/test/libraries/js_escape_test.php @@ -0,0 +1,37 @@ +assertEquals($expected, PMA_getJsValue($key, $value)); + } + + public function variables() { + return array( + array('foo', true, "foo = true;\n"), + array('foo', false, "foo = false;\n"), + array('foo', 100, "foo = 100;\n"), + array('foo', 0, "foo = 0;\n"), + array('foo', 'text', "foo = \"text\";\n"), + array('foo', 'quote"', "foo = \"quote\\\"\";\n"), + array('foo', 'apostroph\'', "foo = \"apostroph\\'\";\n"), + ); + } +} +?> From c289045dcde84ccad43b6ce6641edf36b3fc6c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:49:58 +0200 Subject: [PATCH 14/32] Fix typo --- libraries/js_escape.lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/js_escape.lib.php b/libraries/js_escape.lib.php index 85b62e1e53..0c795ec23c 100644 --- a/libraries/js_escape.lib.php +++ b/libraries/js_escape.lib.php @@ -70,7 +70,8 @@ function PMA_formatJsVal($value) return 'true'; } else { return 'false'; - } else if (is_int($value)) { + } + } elseif (is_int($value)) { return int($value); } else { return '"' . PMA_escapeJsString($value) . '"'; From 3ab9bdf5e371dd4b5f11545da64619da22701229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:52:09 +0200 Subject: [PATCH 15/32] Remove stray code --- test/libraries/js_escape_test.php | 1 - 1 file changed, 1 deletion(-) diff --git a/test/libraries/js_escape_test.php b/test/libraries/js_escape_test.php index d29fcff743..41d96d3939 100644 --- a/test/libraries/js_escape_test.php +++ b/test/libraries/js_escape_test.php @@ -18,7 +18,6 @@ class PMA_File_test extends PHPUnit_Framework_TestCase */ public function testFormat($key, $value, $expected) { - $arr = new PMA_File($file); $this->assertEquals($expected, PMA_getJsValue($key, $value)); } From 381b593e5997899184e1fc7f3522f4d83bd5f025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:52:32 +0200 Subject: [PATCH 16/32] Fix typecasting --- libraries/js_escape.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/js_escape.lib.php b/libraries/js_escape.lib.php index 0c795ec23c..87d88552a6 100644 --- a/libraries/js_escape.lib.php +++ b/libraries/js_escape.lib.php @@ -72,7 +72,7 @@ function PMA_formatJsVal($value) return 'false'; } } elseif (is_int($value)) { - return int($value); + return (int)$value; } else { return '"' . PMA_escapeJsString($value) . '"'; } From b0afa4d8bc904393d7c9902c95c24dd46ae88d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:54:59 +0200 Subject: [PATCH 17/32] Wrap long lines --- server_status.php | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/server_status.php b/server_status.php index 30c3c5a850..1dd4852369 100644 --- a/server_status.php +++ b/server_status.php @@ -673,14 +673,38 @@ $server_db_isLocal = strtolower($cfg['Server']['host']) == 'localhost' || $cfg['Server']['host'] == '127.0.0.1' || $cfg['Server']['host'] == '::1'; -PMA_AddJSVar('pma_token', $_SESSION[' PMA_token ']); -PMA_AddJSVar('url_query', str_replace('&', '&', PMA_generate_common_url($db))); -PMA_AddJSVar('server_time_diff', 'new Date().getTime() - ' . (microtime(true) * 1000)); -PMA_AddJSVar('server_os', PHP_OS); -PMA_AddJSVar('is_superuser', PMA_isSuperuser() ? true : false); -PMA_AddJSVar('server_db_isLocal', $server_db_isLocal ? true : false); -PMA_AddJSVar('profiling_docu', PMA_showMySQLDocu('general-thread-states', 'general-thread-states')); -PMA_AddJSVar('explain_docu', PMA_showMySQLDocu('explain-output', 'explain-output')); +PMA_AddJSVar( + 'pma_token', + $_SESSION[' PMA_token '] +); +PMA_AddJSVar( + 'url_query', + str_replace('&', '&', PMA_generate_common_url($db)) +); +PMA_AddJSVar( + 'server_time_diff', + 'new Date().getTime() - ' . (microtime(true) * 1000) +); +PMA_AddJSVar( + 'server_os', + PHP_OS +); +PMA_AddJSVar( + 'is_superuser', + PMA_isSuperuser() +); +PMA_AddJSVar( + 'server_db_isLocal', + $server_db_isLocal +); +PMA_AddJSVar( + 'profiling_docu', + PMA_showMySQLDocu('general-thread-states', 'general-thread-states') +); +PMA_AddJSVar( + 'explain_docu', + PMA_showMySQLDocu('explain-output', 'explain-output') +); /** * start output From a05eb3ebcde7b04d5f742b73b9a768b3f3a5d7d9 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Fri, 19 Aug 2011 14:27:25 +0530 Subject: [PATCH 18/32] Should return results when $propertiesIconic == true --- libraries/tbl_select.lib.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/tbl_select.lib.php b/libraries/tbl_select.lib.php index bcfe96caaa..d93ad56529 100644 --- a/libraries/tbl_select.lib.php +++ b/libraries/tbl_select.lib.php @@ -19,7 +19,7 @@ require_once 'url_generating.lib.php'; * * @return string $str Value of the Title */ -function PMA_tbl_setTitle($propertiesIconic,$pmaThemeImage) +function PMA_tbl_setTitle($propertiesIconic, $pmaThemeImage) { if ($propertiesIconic == true) { $str = '' . $table . '' . "\n"; + echo '

' . htmlspecialchars($table) . '

' . "\n"; /** * Gets table informations From 599c9b5e1bacc01a9c9bb6621ec1ed3279c4104a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 11:56:38 +0200 Subject: [PATCH 23/32] More of missing escaping --- db_datadict.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db_datadict.php b/db_datadict.php index 938ebf7a1a..6981462972 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -249,9 +249,9 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) { ' . $field_name . ''; + echo '' . htmlspecialchars($field_name) . ''; } else { - echo $field_name; + echo htmlspecialchars($field_name); } ?> From f6fd4323381cb0e8c041e8d7f1b3cfc13302bb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 11:57:44 +0200 Subject: [PATCH 24/32] Use PMA_DBI_get_tables instead of own query --- db_datadict.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db_datadict.php b/db_datadict.php index 0331e4bda3..e9a8c551f0 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -55,10 +55,10 @@ if ($cfgRelation['commwork']) { * Selects the database and gets tables names */ PMA_DBI_select_db($db); -$rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE); +$tables = PMA_DBI_get_tables($db); $count = 0; -while ($row = PMA_DBI_fetch_row($rowset)) { +foreach($tables as $row) { $table = $row[0]; $comments = PMA_getComments($db, $table); From 889ea0afb047b255e81ebb1fe54f5bb825a804ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 12:05:15 +0200 Subject: [PATCH 25/32] Fix getting tables --- db_datadict.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db_datadict.php b/db_datadict.php index e9a8c551f0..e74524d09d 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -58,8 +58,7 @@ PMA_DBI_select_db($db); $tables = PMA_DBI_get_tables($db); $count = 0; -foreach($tables as $row) { - $table = $row[0]; +foreach($tables as $table) { $comments = PMA_getComments($db, $table); echo '
' . "\n"; From 414363d38d788c1c126d0aafc4eda69c0a8157c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 12:06:04 +0200 Subject: [PATCH 26/32] Revert "More of missing escaping" This reverts commit 599c9b5e1bacc01a9c9bb6621ec1ed3279c4104a. --- db_datadict.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db_datadict.php b/db_datadict.php index 6981462972..938ebf7a1a 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -249,9 +249,9 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) { ' . htmlspecialchars($field_name) . ''; + echo '' . $field_name . ''; } else { - echo htmlspecialchars($field_name); + echo $field_name; } ?> From 8cec4ac91ce0da8e73d8b8313cdb5c34d03bdb4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 12:07:32 +0200 Subject: [PATCH 27/32] Revert "Revert "More of missing escaping"" This reverts commit 414363d38d788c1c126d0aafc4eda69c0a8157c8. Okay, it needs to be escaped here, but not escaped above. --- db_datadict.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db_datadict.php b/db_datadict.php index 938ebf7a1a..6981462972 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -249,9 +249,9 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) { ' . $field_name . ''; + echo '' . htmlspecialchars($field_name) . ''; } else { - echo $field_name; + echo htmlspecialchars($field_name); } ?> From da6e51d00780dd941f4b496c69ae15d0d09bd3a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 12:08:07 +0200 Subject: [PATCH 28/32] Do not escape field here, it is used as index to vairous arrays --- db_datadict.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db_datadict.php b/db_datadict.php index 6981462972..b910c761ae 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -227,7 +227,7 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) { } else { $row['Default'] = htmlspecialchars($row['Default']); } - $field_name = htmlspecialchars($row['Field']); + $field_name = $row['Field']; if (PMA_MYSQL_INT_VERSION < 50025 && ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type']) From 679814416f4842f8e0e189c054772edf2d20ddef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 12:11:31 +0200 Subject: [PATCH 29/32] Format --- server_privileges.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server_privileges.php b/server_privileges.php index 78e4f06933..a1b7acb839 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -2353,7 +2353,9 @@ if (empty($_REQUEST['adduser']) && (! isset($checkprivs) || ! strlen($checkprivs . ' ' . ($current['Grant_priv'] == 'Y' ? __('Yes') : __('No')) . "\n" . ' ' . "\n" . ' ' . "\n"; - $user_form .= sprintf($link_edit, urlencode($current_user), + $user_form .= sprintf( + $link_edit, + urlencode($current_user), urlencode($current_host), urlencode(! isset($current['Db']) || $current['Db'] == '*' ? '' : $current['Db']), ''); From 7b54504cc0981821619ffd3f0759766448e6b879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 12:16:59 +0200 Subject: [PATCH 30/32] Fix handling of tables with something what gets urlencoded --- server_privileges.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server_privileges.php b/server_privileges.php index a1b7acb839..685b81726d 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -1416,7 +1416,7 @@ if (isset($_REQUEST['flush_privileges'])) { /** * defines some standard links */ -$link_edit = ''; -$link_export = ' diff --git a/pmd_pdf.php b/pmd_pdf.php index adf5fac13d..2afe131a66 100644 --- a/pmd_pdf.php +++ b/pmd_pdf.php @@ -5,7 +5,7 @@ * @package phpMyAdmin-Designer */ -include_once 'pmd_common.php'; +include_once './libraries/pmd_common.php'; /** * If called directly from the designer, first save the positions diff --git a/pmd_relation_new.php b/pmd_relation_new.php index a104cc119c..fbd624631b 100644 --- a/pmd_relation_new.php +++ b/pmd_relation_new.php @@ -8,7 +8,7 @@ /** * */ -include_once 'pmd_common.php'; +include_once './libraries/pmd_common.php'; $die_save_pos = 0; include_once 'pmd_save_pos.php'; extract($_POST, EXTR_SKIP); diff --git a/pmd_relation_upd.php b/pmd_relation_upd.php index 58c9135cce..7151cf7563 100644 --- a/pmd_relation_upd.php +++ b/pmd_relation_upd.php @@ -8,7 +8,7 @@ /** * */ -include_once 'pmd_common.php'; +include_once './libraries/pmd_common.php'; extract($_POST, EXTR_SKIP); extract($_GET, EXTR_SKIP); $die_save_pos = 0; diff --git a/pmd_save_pos.php b/pmd_save_pos.php index c487ddb1ce..1a071aff8c 100644 --- a/pmd_save_pos.php +++ b/pmd_save_pos.php @@ -8,7 +8,7 @@ /** * */ -include_once 'pmd_common.php'; +include_once './libraries/pmd_common.php'; $cfgRelation = PMA_getRelationsParam(); From cd69e5bdf2081561e5d8891d72820d16a4d99266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 12:25:47 +0200 Subject: [PATCH 32/32] Include missing database tabs --- db_datadict.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db_datadict.php b/db_datadict.php index fca38b70e2..89b2bc5590 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -11,7 +11,8 @@ require_once './libraries/common.inc.php'; if (! isset($selected_tbl)) { - require_once './libraries/header.inc.php'; + require './libraries/db_common.inc.php'; + require './libraries/db_info.inc.php'; }