Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauriciofauth@gmail.com>2017-11-09 16:28:08 +0300
committerMaurício Meneghini Fauth <mauriciofauth@gmail.com>2017-11-09 16:31:42 +0300
commitcc2c4fc36d39d2abf99836d90c521914086fe2b3 (patch)
tree927efc69398499f231e038f1248e2fa8a72afa5b
parent8aa562ed993a224780964c6c85bf45ce013229ef (diff)
Replace globals with DI in Charsets class
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
-rw-r--r--index.php7
-rw-r--r--libraries/classes/CentralColumns.php6
-rw-r--r--libraries/classes/Charsets.php104
-rw-r--r--libraries/classes/Controllers/Server/ServerCollationsController.php11
-rw-r--r--libraries/classes/Controllers/Server/ServerDatabasesController.php12
-rw-r--r--libraries/classes/Display/Import.php2
-rw-r--r--libraries/classes/Normalization.php2
-rw-r--r--libraries/classes/Operations.php9
-rw-r--r--libraries/classes/Rte/Routines.php4
-rw-r--r--libraries/tbl_columns_definition_form.inc.php2
-rw-r--r--templates/columns_definitions/column_attributes.twig2
-rw-r--r--templates/columns_definitions/column_definitions_form.twig6
-rw-r--r--templates/columns_definitions/table_fields_definitions.twig4
-rw-r--r--templates/server/databases/create.twig2
-rw-r--r--templates/server/databases/index.twig4
-rw-r--r--test/classes/CharsetsTest.php13
16 files changed, 141 insertions, 49 deletions
diff --git a/index.php b/index.php
index c56b7c9cd4..d66365ce9b 100644
--- a/index.php
+++ b/index.php
@@ -225,6 +225,8 @@ if ($server > 0 || count($cfg['Servers']) > 1
. ' </label>' . "\n"
. Charsets::getCollationDropdownBox(
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS'],
'collation_connection',
'select_collation_connection',
$collation_connection,
@@ -327,7 +329,10 @@ if ($server > 0 && $GLOBALS['cfg']['ShowServerInfo']) {
echo ' ' , __('Server charset:') , ' '
. ' <span lang="en" dir="ltr">';
$unicode = Charsets::$mysql_charset_map['utf-8'];
- $charsets = Charsets::getMySQLCharsetsDescriptions();
+ $charsets = Charsets::getMySQLCharsetsDescriptions(
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS']
+ );
echo ' ' , $charsets[$unicode], ' (' . $unicode, ')';
echo ' </span>'
. ' </li>'
diff --git a/libraries/classes/CentralColumns.php b/libraries/classes/CentralColumns.php
index e62bee02c6..8a02f43bd8 100644
--- a/libraries/classes/CentralColumns.php
+++ b/libraries/classes/CentralColumns.php
@@ -1033,6 +1033,8 @@ class CentralColumns
'<td name="collation" class="nowrap">'
. '<span>' . htmlspecialchars($row['col_collation']) . '</span>'
. Charsets::getCollationDropdownBox(
+ $dbi,
+ $GLOBALS['cfg']['Server']['DisableIS'],
'field_collation[' . $row_num . ']',
'field_' . $row_num . '_4', $row['col_collation'], false
)
@@ -1182,6 +1184,8 @@ class CentralColumns
$tableHtml .=
'<td name="collation" class="nowrap">'
. Charsets::getCollationDropdownBox(
+ $dbi,
+ $GLOBALS['cfg']['Server']['DisableIS'],
'field_collation[' . $row_num . ']',
'field_' . $row_num . '_4', $row['col_collation'], false
)
@@ -1445,6 +1449,8 @@ class CentralColumns
. '</td>'
. '<td name="collation" class="nowrap">'
. Charsets::getCollationDropdownBox(
+ $dbi,
+ $GLOBALS['cfg']['Server']['DisableIS'],
'field_collation[0]',
'field_0_4', null, false
)
diff --git a/libraries/classes/Charsets.php b/libraries/classes/Charsets.php
index 72deb9d158..4f73e0eed8 100644
--- a/libraries/classes/Charsets.php
+++ b/libraries/classes/Charsets.php
@@ -7,6 +7,7 @@
*/
namespace PhpMyAdmin;
+use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Util;
/**
@@ -16,7 +17,6 @@ use PhpMyAdmin\Util;
*/
class Charsets
{
-
/**
* MySQL charsets map
*
@@ -56,31 +56,34 @@ class Charsets
/**
* Loads charset data from the MySQL server.
*
+ * @param DatabaseInterface $dbi DatabaseInterface instance
+ * @param boolean $disableIs Disable use of INFORMATION_SCHEMA
+ *
* @return void
*/
- public static function loadCharsets()
+ private static function loadCharsets(DatabaseInterface $dbi, $disableIs)
{
/* Data already loaded */
if (count(self::$_charsets) > 0) {
return;
}
- if ($GLOBALS['cfg']['Server']['DisableIS']) {
+ if ($disableIs) {
$sql = 'SHOW CHARACTER SET';
} else {
$sql = 'SELECT `CHARACTER_SET_NAME` AS `Charset`,'
. ' `DESCRIPTION` AS `Description`'
. ' FROM `information_schema`.`CHARACTER_SETS`';
}
- $res = $GLOBALS['dbi']->query($sql);
+ $res = $dbi->query($sql);
self::$_charsets = array();
- while ($row = $GLOBALS['dbi']->fetchAssoc($res)) {
+ while ($row = $dbi->fetchAssoc($res)) {
$name = $row['Charset'];
self::$_charsets[] = $name;
self::$_charsets_descriptions[$name] = $row['Description'];
}
- $GLOBALS['dbi']->freeResult($res);
+ $dbi->freeResult($res);
sort(self::$_charsets, SORT_STRING);
}
@@ -88,16 +91,19 @@ class Charsets
/**
* Loads collation data from the MySQL server.
*
+ * @param DatabaseInterface $dbi DatabaseInterface instance
+ * @param boolean $disableIs Disable use of INFORMATION_SCHEMA
+ *
* @return void
*/
- public static function loadCollations()
+ private static function loadCollations(DatabaseInterface $dbi, $disableIs)
{
/* Data already loaded */
if (count(self::$_collations) > 0) {
return;
}
- if ($GLOBALS['cfg']['Server']['DisableIS']) {
+ if ($disableIs) {
$sql = 'SHOW COLLATION';
} else {
$sql = 'SELECT `CHARACTER_SET_NAME` AS `Charset`,'
@@ -105,8 +111,8 @@ class Charsets
. ' FROM `information_schema`.`COLLATIONS`';
}
- $res = $GLOBALS['dbi']->query($sql);
- while ($row = $GLOBALS['dbi']->fetchAssoc($res)) {
+ $res = $dbi->query($sql);
+ while ($row = $dbi->fetchAssoc($res)) {
$char_set_name = $row['Charset'];
$name = $row['Collation'];
self::$_collations[$char_set_name][] = $name;
@@ -114,7 +120,7 @@ class Charsets
self::$_default_collations[$char_set_name] = $name;
}
}
- $GLOBALS['dbi']->freeResult($res);
+ $dbi->freeResult($res);
foreach (self::$_collations as $key => $value) {
sort(self::$_collations[$key], SORT_STRING);
@@ -124,63 +130,82 @@ class Charsets
/**
* Get MySQL charsets
*
+ * @param DatabaseInterface $dbi DatabaseInterface instance
+ * @param boolean $disableIs Disable use of INFORMATION_SCHEMA
+ *
* @return array
*/
- public static function getMySQLCharsets()
+ public static function getMySQLCharsets(DatabaseInterface $dbi, $disableIs)
{
- self::loadCharsets();
+ self::loadCharsets($dbi, $disableIs);
return self::$_charsets;
}
/**
* Get MySQL charsets descriptions
*
+ * @param DatabaseInterface $dbi DatabaseInterface instance
+ * @param boolean $disableIs Disable use of INFORMATION_SCHEMA
+ *
* @return array
*/
- public static function getMySQLCharsetsDescriptions()
+ public static function getMySQLCharsetsDescriptions(DatabaseInterface $dbi, $disableIs)
{
- self::loadCharsets();
+ self::loadCharsets($dbi, $disableIs);
return self::$_charsets_descriptions;
}
/**
* Get MySQL collations
*
+ * @param DatabaseInterface $dbi DatabaseInterface instance
+ * @param boolean $disableIs Disable use of INFORMATION_SCHEMA
+ *
* @return array
*/
- public static function getMySQLCollations()
+ public static function getMySQLCollations(DatabaseInterface $dbi, $disableIs)
{
- self::loadCollations();
+ self::loadCollations($dbi, $disableIs);
return self::$_collations;
}
/**
* Get MySQL default collations
*
+ * @param DatabaseInterface $dbi DatabaseInterface instance
+ * @param boolean $disableIs Disable use of INFORMATION_SCHEMA
+ *
* @return array
*/
- public static function getMySQLCollationsDefault()
+ public static function getMySQLCollationsDefault(DatabaseInterface $dbi, $disableIs)
{
- self::loadCollations();
+ self::loadCollations($dbi, $disableIs);
return self::$_default_collations;
}
/**
* Generate charset dropdown box
*
- * @param string $name Element name
- * @param string $id Element id
- * @param null|string $default Default value
- * @param bool $label Label
- * @param bool $submitOnChange Submit on change
+ * @param DatabaseInterface $dbi DatabaseInterface instance
+ * @param boolean $disableIs Disable use of INFORMATION_SCHEMA
+ * @param string $name Element name
+ * @param string $id Element id
+ * @param null|string $default Default value
+ * @param bool $label Label
+ * @param bool $submitOnChange Submit on change
*
* @return string
*/
public static function getCharsetDropdownBox(
- $name = null, $id = null, $default = null, $label = true,
+ DatabaseInterface $dbi,
+ $disableIs,
+ $name = null,
+ $id = null,
+ $default = null,
+ $label = true,
$submitOnChange = false
) {
- self::loadCharsets();
+ self::loadCharsets($dbi, $disableIs);
if (empty($name)) {
$name = 'character_set';
}
@@ -214,20 +239,27 @@ class Charsets
/**
* Generate collation dropdown box
*
- * @param string $name Element name
- * @param string $id Element id
- * @param null|string $default Default value
- * @param bool $label Label
- * @param bool $submitOnChange Submit on change
+ * @param DatabaseInterface $dbi DatabaseInterface instance
+ * @param boolean $disableIs Disable use of INFORMATION_SCHEMA
+ * @param string $name Element name
+ * @param string $id Element id
+ * @param null|string $default Default value
+ * @param bool $label Label
+ * @param bool $submitOnChange Submit on change
*
* @return string
*/
public static function getCollationDropdownBox(
- $name = null, $id = null, $default = null, $label = true,
+ DatabaseInterface $dbi,
+ $disableIs,
+ $name = null,
+ $id = null,
+ $default = null,
+ $label = true,
$submitOnChange = false
) {
- self::loadCharsets();
- self::loadCollations();
+ self::loadCharsets($dbi, $disableIs);
+ self::loadCollations($dbi, $disableIs);
if (empty($name)) {
$name = 'collation';
}
@@ -265,11 +297,11 @@ class Charsets
}
/**
- * returns description for given collation
+ * Returns description for given collation
*
* @param string $collation MySQL collation string
*
- * @return string collation description
+ * @return string collation description
*/
public static function getCollationDescr($collation)
{
diff --git a/libraries/classes/Controllers/Server/ServerCollationsController.php b/libraries/classes/Controllers/Server/ServerCollationsController.php
index 6063d0bd7b..cead8ab1ef 100644
--- a/libraries/classes/Controllers/Server/ServerCollationsController.php
+++ b/libraries/classes/Controllers/Server/ServerCollationsController.php
@@ -28,6 +28,9 @@ class ServerCollationsController extends Controller
*/
public function indexAction()
{
+ $dbi = $GLOBALS['dbi'];
+ $disableIs = $GLOBALS['cfg']['Server']['DisableIS'];
+
/**
* Does the common work
*/
@@ -40,10 +43,10 @@ class ServerCollationsController extends Controller
);
$this->response->addHTML(
$this->_getHtmlForCharsets(
- Charsets::getMySQLCharsets(),
- Charsets::getMySQLCollations(),
- Charsets::getMySQLCharsetsDescriptions(),
- Charsets::getMySQLCollationsDefault()
+ Charsets::getMySQLCharsets($dbi, $disableIs),
+ Charsets::getMySQLCollations($dbi, $disableIs),
+ Charsets::getMySQLCharsetsDescriptions($dbi, $disableIs),
+ Charsets::getMySQLCollationsDefault($dbi, $disableIs)
)
);
}
diff --git a/libraries/classes/Controllers/Server/ServerDatabasesController.php b/libraries/classes/Controllers/Server/ServerDatabasesController.php
index e9f621560b..52bdb9ae5f 100644
--- a/libraries/classes/Controllers/Server/ServerDatabasesController.php
+++ b/libraries/classes/Controllers/Server/ServerDatabasesController.php
@@ -113,6 +113,8 @@ class ServerDatabasesController extends Controller
'db_to_create' => $GLOBALS['db_to_create'],
'server_collation' => $GLOBALS['dbi']->getServerCollation(),
'databases' => isset($databases) ? $databases : null,
+ 'dbi' => $GLOBALS['dbi'],
+ 'disable_is' => $GLOBALS['cfg']['Server']['DisableIS'],
]));
}
@@ -129,8 +131,14 @@ class ServerDatabasesController extends Controller
$sql_query = 'CREATE DATABASE ' . Util::backquote($_POST['new_db']);
if (! empty($_POST['db_collation'])) {
list($db_charset) = explode('_', $_POST['db_collation']);
- $charsets = Charsets::getMySQLCharsets();
- $collations = Charsets::getMySQLCollations();
+ $charsets = Charsets::getMySQLCharsets(
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS']
+ );
+ $collations = Charsets::getMySQLCollations(
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS']
+ );
if (in_array($db_charset, $charsets)
&& in_array($_POST['db_collation'], $collations[$db_charset])
) {
diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php
index 3fcbf21890..e3beff76bd 100644
--- a/libraries/classes/Display/Import.php
+++ b/libraries/classes/Display/Import.php
@@ -205,6 +205,8 @@ class Import
$html .= '<label for="charset_of_file">' . __('Character set of the file:')
. '</label>' . "\n";
$html .= Charsets::getCharsetDropdownBox(
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS'],
'charset_of_file',
'charset_of_file',
'utf8',
diff --git a/libraries/classes/Normalization.php b/libraries/classes/Normalization.php
index fbc99546fb..53be690025 100644
--- a/libraries/classes/Normalization.php
+++ b/libraries/classes/Normalization.php
@@ -132,6 +132,8 @@ class Normalization
'attribute_types' => $GLOBALS['dbi']->types->getAttributes(),
'privs_available' => $GLOBALS['col_priv'] && $GLOBALS['is_reload_priv'],
'max_length' => $GLOBALS['dbi']->getVersion() >= 50503 ? 1024 : 255,
+ 'dbi' => $GLOBALS['dbi'],
+ 'disable_is' => $GLOBALS['cfg']['Server']['DisableIS'],
)
);
}
diff --git a/libraries/classes/Operations.php b/libraries/classes/Operations.php
index a9e71cc0c3..b8b3e3069f 100644
--- a/libraries/classes/Operations.php
+++ b/libraries/classes/Operations.php
@@ -299,6 +299,8 @@ class Operations
. '</label>' . "\n"
. '</legend>' . "\n"
. Charsets::getCollationDropdownBox(
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS'],
'db_collation',
'select_db_collation',
isset($_REQUEST['db_collation']) ? $_REQUEST['db_collation'] : '',
@@ -1066,7 +1068,12 @@ class Operations
$html_output .= '<tr><td class="vmiddle">' . __('Collation') . '</td>'
. '<td>'
. Charsets::getCollationDropdownBox(
- 'tbl_collation', null, $tbl_collation, false
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS'],
+ 'tbl_collation',
+ null,
+ $tbl_collation,
+ false
)
. '</td>'
. '</tr>';
diff --git a/libraries/classes/Rte/Routines.php b/libraries/classes/Rte/Routines.php
index f8c38ea522..91e655a87c 100644
--- a/libraries/classes/Rte/Routines.php
+++ b/libraries/classes/Rte/Routines.php
@@ -765,6 +765,8 @@ class Routines
$retval .= " <td class='hide no_len'>---</td>\n";
$retval .= " <td class='routine_param_opts_text'>\n";
$retval .= Charsets::getCharsetDropdownBox(
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS'],
"item_param_opts_text[$index]",
null,
$routine['item_param_opts_text'][$i]
@@ -982,6 +984,8 @@ class Routines
$retval .= " <td>" . __('Return options') . "</td>";
$retval .= " <td><div>";
$retval .= Charsets::getCharsetDropdownBox(
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS'],
"item_returnopts_text",
null,
$routine['item_returnopts_text']
diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php
index e7bf4375c9..3fb1bc4d43 100644
--- a/libraries/tbl_columns_definition_form.inc.php
+++ b/libraries/tbl_columns_definition_form.inc.php
@@ -423,6 +423,8 @@ $html = Template::get('columns_definitions/column_definitions_form')->render([
),
'max_length' => $GLOBALS['dbi']->getVersion() >= 50503 ? 1024 : 255,
'have_partitioning' => Partition::havePartitioning(),
+ 'dbi' => $GLOBALS['dbi'],
+ 'disable_is' => $GLOBALS['cfg']['Server']['DisableIS'],
]);
unset($form_params);
diff --git a/templates/columns_definitions/column_attributes.twig b/templates/columns_definitions/column_attributes.twig
index fc00cb3f32..93e856d7e9 100644
--- a/templates/columns_definitions/column_attributes.twig
+++ b/templates/columns_definitions/column_attributes.twig
@@ -54,6 +54,8 @@
<td class="center">
{# column collation #}
{{ Charsets_getCollationDropdownBox(
+ dbi,
+ disable_is,
'field_collation[' ~ column_number ~ ']',
'field_' ~ column_number ~ '_' ~ (ci - ci_offset),
column_meta['Collation'] is not empty ? column_meta['Collation'] : null,
diff --git a/templates/columns_definitions/column_definitions_form.twig b/templates/columns_definitions/column_definitions_form.twig
index fed520d670..dfef70fd01 100644
--- a/templates/columns_definitions/column_definitions_form.twig
+++ b/templates/columns_definitions/column_definitions_form.twig
@@ -60,7 +60,9 @@
'char_editing': char_editing,
'attribute_types': attribute_types,
'privs_available': privs_available,
- 'max_length': max_length
+ 'max_length': max_length,
+ 'dbi': dbi,
+ 'disable_is': disable_is
} only %}
{% endif %}
{% if action == 'tbl_create.php' %}
@@ -93,6 +95,8 @@
<td width="25">&nbsp;</td>
<td>
{{ Charsets_getCollationDropdownBox(
+ dbi,
+ disable_is,
'tbl_collation',
null,
tbl_collation,
diff --git a/templates/columns_definitions/table_fields_definitions.twig b/templates/columns_definitions/table_fields_definitions.twig
index 9b0e1ad482..d8dba2b571 100644
--- a/templates/columns_definitions/table_fields_definitions.twig
+++ b/templates/columns_definitions/table_fields_definitions.twig
@@ -112,7 +112,9 @@
'char_editing': char_editing,
'attribute_types': attribute_types,
'privs_available': privs_available,
- 'max_length': max_length
+ 'max_length': max_length,
+ 'dbi': dbi,
+ 'disable_is': disable_is
}) only %}
</tr>
{% endfor %}
diff --git a/templates/server/databases/create.twig b/templates/server/databases/create.twig
index 739d2c79f5..0b3717f72c 100644
--- a/templates/server/databases/create.twig
+++ b/templates/server/databases/create.twig
@@ -20,6 +20,8 @@
maxlength="64" class="textfield" id="text_create_db" required
placeholder="{% trans 'Database name' %}" />
{{ Charsets_getCollationDropdownBox(
+ dbi,
+ disable_is,
'db_collation',
null,
server_collation,
diff --git a/templates/server/databases/index.twig b/templates/server/databases/index.twig
index 9f164b3e28..7d465e2be0 100644
--- a/templates/server/databases/index.twig
+++ b/templates/server/databases/index.twig
@@ -9,7 +9,9 @@
'is_create_db_priv': is_create_db_priv,
'dbstats': dbstats,
'db_to_create': db_to_create,
- 'server_collation': server_collation
+ 'server_collation': server_collation,
+ 'dbi': dbi,
+ 'disable_is': disable_is
} only %}
{% endif %}
diff --git a/test/classes/CharsetsTest.php b/test/classes/CharsetsTest.php
index 6a92b199ca..626a99a276 100644
--- a/test/classes/CharsetsTest.php
+++ b/test/classes/CharsetsTest.php
@@ -149,7 +149,10 @@ class CharsetsTest extends TestCase
*/
public function testGetCollationDropdownBox()
{
- $result = Charsets::getCollationDropdownBox();
+ $result = Charsets::getCollationDropdownBox(
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS']
+ );
$this->assertContains('name="collation"', $result);
$this->assertNotContains('id="', $result);
@@ -172,7 +175,13 @@ class CharsetsTest extends TestCase
public function testGetCharsetDropdownBox()
{
$result = Charsets::getCharsetDropdownBox(
- null, "test_id", "latin1", false, true
+ $GLOBALS['dbi'],
+ $GLOBALS['cfg']['Server']['DisableIS'],
+ null,
+ "test_id",
+ "latin1",
+ false,
+ true
);
$this->assertContains('name="character_set"', $result);
$this->assertNotContains('Charset</option>', $result);