diff --git a/libraries/classes/Database/Search.php b/libraries/classes/Database/Search.php
index a7c088936e..151fb12351 100644
--- a/libraries/classes/Database/Search.php
+++ b/libraries/classes/Database/Search.php
@@ -7,8 +7,7 @@
*/
namespace PhpMyAdmin\Database;
-use PhpMyAdmin\Sanitize;
-use PhpMyAdmin\Url;
+use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
/**
@@ -24,56 +23,63 @@ class Search
* @access private
* @var string
*/
- private $_db;
+ private $db;
+
/**
* Table Names
*
* @access private
* @var array
*/
- private $_tables_names_only;
+ private $tablesNamesOnly;
+
/**
* Type of search
*
* @access private
* @var array
*/
- private $_searchTypes;
+ private $searchTypes;
+
/**
* Already set search type
*
* @access private
* @var integer
*/
- private $_criteriaSearchType;
+ private $criteriaSearchType;
+
/**
* Already set search type's description
*
* @access private
* @var string
*/
- private $_searchTypeDescription;
+ private $searchTypeDescription;
+
/**
* Search string/regexp
*
* @access private
* @var string
*/
- private $_criteriaSearchString;
+ private $criteriaSearchString;
+
/**
* Criteria Tables to search in
*
* @access private
* @var array
*/
- private $_criteriaTables;
+ private $criteriaTables;
+
/**
* Restrict the search to this column
*
* @access private
* @var string
*/
- private $_criteriaColumnName;
+ private $criteriaColumnName;
/**
* Public Constructor
@@ -82,8 +88,8 @@ class Search
*/
public function __construct($db)
{
- $this->_db = $db;
- $this->_searchTypes = array(
+ $this->db = $db;
+ $this->searchTypes = array(
'1' => __('at least one of the words'),
'2' => __('all of the words'),
'3' => __('the exact phrase as substring'),
@@ -91,7 +97,7 @@ class Search
'5' => __('as regular expression'),
);
// Sets criteria parameters
- $this->_setSearchParams();
+ $this->setSearchParams();
}
/**
@@ -99,51 +105,51 @@ class Search
*
* @return void
*/
- private function _setSearchParams()
+ private function setSearchParams()
{
- $this->_tables_names_only = $GLOBALS['dbi']->getTables($this->_db);
+ $this->tablesNamesOnly = $GLOBALS['dbi']->getTables($this->db);
if (empty($_REQUEST['criteriaSearchType'])
|| ! is_string($_REQUEST['criteriaSearchType'])
|| ! array_key_exists(
$_REQUEST['criteriaSearchType'],
- $this->_searchTypes
+ $this->searchTypes
)
) {
- $this->_criteriaSearchType = 1;
+ $this->criteriaSearchType = 1;
unset($_REQUEST['submit_search']);
} else {
- $this->_criteriaSearchType = (int) $_REQUEST['criteriaSearchType'];
- $this->_searchTypeDescription
- = $this->_searchTypes[$_REQUEST['criteriaSearchType']];
+ $this->criteriaSearchType = (int) $_REQUEST['criteriaSearchType'];
+ $this->searchTypeDescription
+ = $this->searchTypes[$_REQUEST['criteriaSearchType']];
}
if (empty($_REQUEST['criteriaSearchString'])
|| ! is_string($_REQUEST['criteriaSearchString'])
) {
- $this->_criteriaSearchString = '';
+ $this->criteriaSearchString = '';
unset($_REQUEST['submit_search']);
} else {
- $this->_criteriaSearchString = $_REQUEST['criteriaSearchString'];
+ $this->criteriaSearchString = $_REQUEST['criteriaSearchString'];
}
- $this->_criteriaTables = array();
+ $this->criteriaTables = array();
if (empty($_REQUEST['criteriaTables'])
|| ! is_array($_REQUEST['criteriaTables'])
) {
unset($_REQUEST['submit_search']);
} else {
- $this->_criteriaTables = array_intersect(
- $_REQUEST['criteriaTables'], $this->_tables_names_only
+ $this->criteriaTables = array_intersect(
+ $_REQUEST['criteriaTables'], $this->tablesNamesOnly
);
}
if (empty($_REQUEST['criteriaColumnName'])
|| ! is_string($_REQUEST['criteriaColumnName'])
) {
- unset($this->_criteriaColumnName);
+ unset($this->criteriaColumnName);
} else {
- $this->_criteriaColumnName = $GLOBALS['dbi']->escapeString(
+ $this->criteriaColumnName = $GLOBALS['dbi']->escapeString(
$_REQUEST['criteriaColumnName']
);
}
@@ -165,7 +171,7 @@ class Search
* count
* strlen
*/
- private function _getSearchSqls($table)
+ private function getSearchSqls($table)
{
// Statement types
$sqlstr_select = 'SELECT';
@@ -175,7 +181,7 @@ class Search
. Util::backquote($GLOBALS['db']) . '.'
. Util::backquote($table);
// Gets where clause for the query
- $where_clause = $this->_getWhereClause($table);
+ $where_clause = $this->getWhereClause($table);
// Builds complete queries
$sql = array();
$sql['select_columns'] = $sqlstr_select . ' * ' . $sqlstr_from
@@ -196,22 +202,22 @@ class Search
*
* @return string The generated where clause
*/
- private function _getWhereClause($table)
+ private function getWhereClause($table)
{
// Columns to select
$allColumns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $table);
$likeClauses = array();
// Based on search type, decide like/regex & '%'/''
- $like_or_regex = (($this->_criteriaSearchType == 5) ? 'REGEXP' : 'LIKE');
- $automatic_wildcard = (($this->_criteriaSearchType < 4) ? '%' : '');
+ $like_or_regex = (($this->criteriaSearchType == 5) ? 'REGEXP' : 'LIKE');
+ $automatic_wildcard = (($this->criteriaSearchType < 4) ? '%' : '');
// For "as regular expression" (search option 5), LIKE won't be used
// Usage example: If user is searching for a literal $ in a regexp search,
// he should enter \$ as the value.
$criteriaSearchStringEscaped = $GLOBALS['dbi']->escapeString(
- $this->_criteriaSearchString
+ $this->criteriaSearchString
);
// Extract search words or pattern
- $search_words = (($this->_criteriaSearchType > 2)
+ $search_words = (($this->criteriaSearchType > 2)
? array($criteriaSearchStringEscaped)
: explode(' ', $criteriaSearchStringEscaped));
@@ -223,9 +229,9 @@ class Search
$likeClausesPerColumn = array();
// for each column in the table
foreach ($allColumns as $column) {
- if (! isset($this->_criteriaColumnName)
- || strlen($this->_criteriaColumnName) === 0
- || $column['Field'] == $this->_criteriaColumnName
+ if (! isset($this->criteriaColumnName)
+ || strlen($this->criteriaColumnName) === 0
+ || $column['Field'] == $this->criteriaColumnName
) {
$column = 'CONVERT(' . Util::backquote($column['Field'])
. ' USING utf8)';
@@ -240,7 +246,7 @@ class Search
}
} // end for
// Use 'OR' if 'at least one word' is to be searched, else use 'AND'
- $implode_str = ($this->_criteriaSearchType == 1 ? ' OR ' : ' AND ');
+ $implode_str = ($this->criteriaSearchType == 1 ? ' OR ' : ' AND ');
if (empty($likeClauses)) {
// this could happen when the "inside column" does not exist
// in any selected tables
@@ -260,104 +266,33 @@ class Search
*/
public function getSearchResults()
{
- $html_output = '';
- // Displays search string
- $html_output .= '
'
- . '
'; - $html_output .= sprintf( - _ngettext( - 'Total: %s match', - 'Total: %s matches', - $num_search_result_total - ), - $num_search_result_total - ); - $html_output .= '
'; + $rows[] = [ + 'table' => $eachTable, + 'new_search_sqls' => $newSearchSqls, + 'result_count' => $resultCount, + ]; } - return $html_output; - } - /** - * Provides search results row with browse/delete links. - * (for a table) - * - * @param string $each_table One of the tables on which search was performed - * @param array $newsearchsqls Contains SQL queries - * @param integer $res_cnt Number of results found - * - * @return string HTML row - */ - private function _getResultsRow($each_table, array $newsearchsqls, $res_cnt) - { - $this_url_params = array( - 'db' => $GLOBALS['db'], - 'table' => $each_table, - 'goto' => 'db_sql.php', - 'pos' => 0, - 'is_js_confirmed' => 0, - ); - // Start forming search results row - $html_output = '| + {% set result_message %} + {% trans %} + %1$s match in %2$s + {% plural row.result_count %} + %1$s matches in %2$s + {% endtrans %} + {% endset %} + {{ result_message|format(row.result_count, row.table)|raw }} + | + {% if row.result_count > 0 %} + {% set url_params = { + 'db': db, + 'table': row.table, + 'goto': 'db_sql.php', + 'pos': 0, + 'is_js_confirmed': 0 + } %} ++ + {% trans 'Browse' %} + + | ++ + {% trans 'Delete' %} + + | + {% else %} ++ | + {% endif %} + |
+ {% trans %} + Total: {{ count }} match + {% plural result_total %} + Total: {{ count }} matches + {% endtrans %} +
+{% endif %} diff --git a/templates/database/search/selection_form.twig b/templates/database/search/selection_form.twig new file mode 100644 index 0000000000..5ae4256b53 --- /dev/null +++ b/templates/database/search/selection_form.twig @@ -0,0 +1,70 @@ + + + diff --git a/test/classes/Database/SearchTest.php b/test/classes/Database/SearchTest.php index d2da90c801..93dfd3c5a0 100644 --- a/test/classes/Database/SearchTest.php +++ b/test/classes/Database/SearchTest.php @@ -76,7 +76,7 @@ class SearchTest extends PmaTestCase * * @return the output from the protected method. */ - private function _callProtectedFunction($name, $params) + private function callProtectedFunction($name, $params) { $class = new ReflectionClass(Search::class); $method = $class->getMethod($name); @@ -97,8 +97,8 @@ class SearchTest extends PmaTestCase $this->object = new Search('pma_test'); $this->assertEquals( $expected, - $this->_callProtectedFunction( - '_getWhereClause', + $this->callProtectedFunction( + 'getWhereClause', array('table1') ) ); @@ -149,8 +149,8 @@ class SearchTest extends PmaTestCase 'WHERE FALSE', 'delete' => 'DELETE FROM `pma`.`table1` WHERE FALSE' ), - $this->_callProtectedFunction( - '_getSearchSqls', + $this->callProtectedFunction( + 'getSearchSqls', array('table1') ) ); @@ -163,72 +163,12 @@ class SearchTest extends PmaTestCase */ public function testGetSearchResults() { - $this->assertEquals( - '