Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-11-09 14:32:57 +01:00
commit 61c9df5928
16 changed files with 141 additions and 49 deletions

View File

@ -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>'

View File

@ -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
)

View File

@ -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)
{

View File

@ -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)
)
);
}

View File

@ -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])
) {

View File

@ -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',

View File

@ -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'],
)
);
}

View File

@ -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>';

View File

@ -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']

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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 %}

View File

@ -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,

View File

@ -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 %}

View File

@ -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);