Skip to content

Commit

Permalink
Split Util class regarding the responsabilities (#15567)
Browse files Browse the repository at this point in the history
PhpMyAdmin\Util is a very huge class with a lot of responsabilities.

There is a lot of work to split it, but this may be just a small start, waiting for a more normalized code.

* Split Util class regarding the responsabilities
* Split the buttonOrImage function

Signed-off-by: Hugues Peccatte <hugues.peccatte@gmail.com>
  • Loading branch information
Tithugues authored and MauricioFauth committed Nov 21, 2019
1 parent 3b0eff7 commit 3255e4a
Show file tree
Hide file tree
Showing 124 changed files with 4,273 additions and 3,529 deletions.
5 changes: 3 additions & 2 deletions libraries/classes/CentralColumns.php
Expand Up @@ -10,6 +10,7 @@

use PhpMyAdmin\Charsets\Charset;
use PhpMyAdmin\Charsets\Collation;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Message;

/**
Expand Down Expand Up @@ -934,14 +935,14 @@ public function getTableFooter(string $pmaThemeImage, string $text_dir): string
'text_dir' => $text_dir,
'form_name' => 'tableslistcontainer',
]);
$html_output .= Util::getButtonOrImage(
$html_output .= Generator::getButtonOrImage(
'edit_central_columns',
'mult_submit change_central_columns',
__('Edit'),
'b_edit',
'edit central columns'
);
$html_output .= Util::getButtonOrImage(
$html_output .= Generator::getButtonOrImage(
'delete_central_columns',
'mult_submit',
__('Delete'),
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Config/FormDisplay.php
Expand Up @@ -16,6 +16,7 @@
namespace PhpMyAdmin\Config;

use PhpMyAdmin\Config\Forms\User\UserFormList;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Util;

Expand Down Expand Up @@ -785,7 +786,7 @@ public function getDocLink($path)
if ($test == 'Import' || $test == 'Export') {
return '';
}
return Util::getDocuLink(
return MySQLDocumentation::getDocumentationLink(
'config',
'cfg_' . $this->_getOptName($path)
);
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Config/FormDisplayTemplate.php
Expand Up @@ -9,6 +9,7 @@
namespace PhpMyAdmin\Config;

use PhpMyAdmin\Config;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
Expand Down Expand Up @@ -229,7 +230,7 @@ public function displayInput(
} else {
// In this case we just use getImage() because it's available
foreach ($iconInit as $k => $v) {
$icons[$k] = Util::getImage(
$icons[$k] = Generator::getImage(
$v[0],
$v[1]
);
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Console.php
Expand Up @@ -139,7 +139,7 @@ public function getDisplay(): string
$GLOBALS['cfg']['Server']['user']
);

$image = Util::getImage('console', __('SQL Query Console'));
$image = Html\Generator::getImage('console', __('SQL Query Console'));
$_sql_history = $this->relation->getHistory(
$GLOBALS['cfg']['Server']['user']
);
Expand Down
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Database;

use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Rte\Routines;
use PhpMyAdmin\Util;

Expand Down
63 changes: 34 additions & 29 deletions libraries/classes/Controllers/Database/StructureController.php
Expand Up @@ -13,6 +13,7 @@
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Display\CreateTable;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Message;
use PhpMyAdmin\RecentFavoriteTable;
use PhpMyAdmin\Relation;
Expand Down Expand Up @@ -97,17 +98,8 @@ public function __construct($response, $dbi, Template $template, $db, $relation,
*/
private function getDatabaseInfo(string $subPart): void
{
list(
$tables,
$numTables,
$totalNumTables,
,
$isShowStats,
$dbIsSystemSchema,
,
,
$position
) = Util::getDbInfo($this->db, $subPart);
[$tables, $numTables, $totalNumTables,, $isShowStats, $dbIsSystemSchema,,, $position]
= Util::getDbInfo($this->db, $subPart);

$this->tables = $tables;
$this->numTables = $numTables;
Expand Down Expand Up @@ -171,7 +163,7 @@ public function index(array $parameters): string
if (isset($parameters['sort_order'])) {
$urlParams['sort_order'] = $parameters['sort_order'];
}
$listNavigator = Util::getListNavigator(
$listNavigator = Generator::getListNavigator(
$this->totalNumTables,
$this->position,
$urlParams,
Expand Down Expand Up @@ -395,13 +387,20 @@ protected function displayTableList(): string
];
// do not list the previous table's size info for a view

list($current_table, $formatted_size, $unit, $formatted_overhead,
$overhead_unit, $overhead_size, $table_is_view, $sum_size)
= $this->getStuffForEngineTypeTable(
$current_table,
$sum_size,
$overhead_size
);
[
$current_table,
$formatted_size,
$unit,
$formatted_overhead,
$overhead_unit,
$overhead_size,
$table_is_view,
$sum_size,
] = $this->getStuffForEngineTypeTable(
$current_table,
$sum_size,
$overhead_size
);

$curTable = $this->dbi
->getTable($this->db, $current_table['TABLE_NAME']);
Expand Down Expand Up @@ -544,12 +543,12 @@ protected function displayTableList(): string
$structure_table_rows = [];
}

list($approx_rows, $show_superscript) = $this->isRowCountApproximated(
[$approx_rows, $show_superscript] = $this->isRowCountApproximated(
$current_table,
$table_is_view
);

list($do, $ignored) = $this->getReplicationStatus($truename);
[$do, $ignored] = $this->getReplicationStatus($truename);

$structure_table_rows[] = [
'table_name_hash' => md5($current_table['TABLE_NAME']),
Expand Down Expand Up @@ -739,7 +738,7 @@ protected function isRowCountApproximated(
&& $current_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']
) {
$approx_rows = true;
$show_superscript = Util::showHint(
$show_superscript = Generator::showHint(
Sanitize::sanitizeMessage(
sprintf(
__(
Expand Down Expand Up @@ -928,9 +927,15 @@ protected function getStuffForEngineTypeTable(
case 'ARCHIVE':
case 'Aria':
case 'Maria':
list($current_table, $formatted_size, $unit, $formatted_overhead,
$overhead_unit, $overhead_size, $sum_size)
= $this->getValuesForAriaTable(
[
$current_table,
$formatted_size,
$unit,
$formatted_overhead,
$overhead_unit,
$overhead_size,
$sum_size,
] = $this->getValuesForAriaTable(
$current_table,
$sum_size,
$overhead_size,
Expand All @@ -946,7 +951,7 @@ protected function getStuffForEngineTypeTable(
// InnoDB table: Row count is not accurate but data and index sizes are.
// PBMS table in Drizzle: TABLE_ROWS is taken from table cache,
// so it may be unavailable
list($current_table, $formatted_size, $unit, $sum_size)
[$current_table, $formatted_size, $unit, $sum_size]
= $this->getValuesForInnodbTable(
$current_table,
$sum_size
Expand Down Expand Up @@ -1033,15 +1038,15 @@ protected function getValuesForAriaTable(
$tblsize = $current_table['Data_length']
+ $current_table['Index_length'];
$sum_size += $tblsize;
list($formatted_size, $unit) = Util::formatByteDown(
[$formatted_size, $unit] = Util::formatByteDown(
$tblsize,
3,
$tblsize > 0 ? 1 : 0
);
if (isset($current_table['Data_free'])
&& $current_table['Data_free'] > 0
) {
list($formatted_overhead, $overhead_unit)
[$formatted_overhead, $overhead_unit]
= Util::formatByteDown(
$current_table['Data_free'],
3,
Expand Down Expand Up @@ -1091,7 +1096,7 @@ protected function getValuesForInnodbTable(
$tblsize = $current_table['Data_length']
+ $current_table['Index_length'];
$sum_size += $tblsize;
list($formatted_size, $unit) = Util::formatByteDown(
[$formatted_size, $unit] = Util::formatByteDown(
$tblsize,
3,
($tblsize > 0 ? 1 : 0)
Expand Down
9 changes: 5 additions & 4 deletions libraries/classes/Controllers/HomeController.php
Expand Up @@ -15,6 +15,7 @@
use PhpMyAdmin\Config;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Display\GitRevision;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\Message;
use PhpMyAdmin\RecentFavoriteTable;
Expand Down Expand Up @@ -84,7 +85,7 @@ public function index(array $params): string
$languageManager = LanguageManager::getInstance();

if (! empty($message)) {
$displayMessage = Util::getMessage($message);
$displayMessage = Generator::getMessage($message);
unset($message);
}
if (isset($_SESSION['partial_logout'])) {
Expand Down Expand Up @@ -114,7 +115,7 @@ public function index(array $params): string

if (($cfg['Server']['auth_type'] != 'config') && $cfg['ShowChgPassword']) {
$changePassword = $this->template->render('list/item', [
'content' => Util::getImage('s_passwd') . ' ' . __(
'content' => Generator::getImage('s_passwd') . ' ' . __(
'Change password'
),
'id' => 'li_change_password',
Expand Down Expand Up @@ -151,7 +152,7 @@ public function index(array $params): string
}

$userPreferences = $this->template->render('list/item', [
'content' => Util::getImage('b_tblops') . ' ' . __(
'content' => Generator::getImage('b_tblops') . ' ' . __(
'More settings'
),
'id' => 'li_user_preferences',
Expand Down Expand Up @@ -197,7 +198,7 @@ public function index(array $params): string
$databaseServer = [
'host' => $hostInfo,
'type' => Util::getServerType(),
'connection' => Util::getServerSSL(),
'connection' => Generator::getServerSSL(),
'version' => $this->dbi->getVersionString() . ' - ' . $this->dbi->getVersionComment(),
'protocol' => $this->dbi->getProtoInfo(),
'user' => $this->dbi->fetchValue('SELECT USER();'),
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Server/BinlogController.php
Expand Up @@ -10,6 +10,7 @@

use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
use PhpMyAdmin\Template;
Expand Down Expand Up @@ -112,7 +113,7 @@ public function index(array $params): string
'url_params' => $urlParams,
'binary_logs' => $this->binaryLogs,
'log' => $params['log'],
'sql_message' => Util::getMessage(Message::success(), $sqlQuery),
'sql_message' => Generator::getMessage(Message::success(), $sqlQuery),
'values' => $values,
'has_previous' => $position > 0,
'has_next' => $numRows >= $cfg['MaxRows'],
Expand Down
5 changes: 3 additions & 2 deletions libraries/classes/Controllers/Server/DatabasesController.php
Expand Up @@ -14,6 +14,7 @@
use PhpMyAdmin\CheckUserPrivileges;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
use PhpMyAdmin\Template;
Expand Down Expand Up @@ -192,7 +193,7 @@ public function create(array $params): array
*/
$sqlQuery = 'CREATE DATABASE ' . Util::backquote($params['new_db']);
if (! empty($params['db_collation'])) {
list($databaseCharset) = explode('_', $params['db_collation']);
[$databaseCharset] = explode('_', $params['db_collation']);
$charsets = Charsets::getCharsets(
$this->dbi,
$cfg['Server']['DisableIS']
Expand Down Expand Up @@ -233,7 +234,7 @@ public function create(array $params): array

$json = [
'message' => $message,
'sql_query' => Util::getMessage(null, $sqlQuery, 'success'),
'sql_query' => Generator::getMessage(null, $sqlQuery, 'success'),
'url_query' => $scriptName . Url::getCommon(
['db' => $params['new_db']],
strpos($scriptName, '?') === false ? '?' : '&'
Expand Down
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server\Status;

use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Message;
use PhpMyAdmin\Util;

Expand Down Expand Up @@ -237,7 +238,7 @@ private function getList(array $params): string
'time' => $process['Time'],
'state' => ! empty($process['State']) ? $process['State'] : '---',
'progress' => ! empty($process['Progress']) ? $process['Progress'] : '---',
'info' => ! empty($process['Info']) ? Util::formatSql(
'info' => ! empty($process['Info']) ? Generator::formatSql(
$process['Info'],
! $showFullSql
) : '---',
Expand Down
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server\Status;

use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Util;

/**
Expand Down Expand Up @@ -79,7 +80,7 @@ public function index(array $params): string
// Fields containing % are calculated,
// they can not be described in MySQL documentation
if (mb_strpos($name, '%') === false) {
$variables[$name]['doc'] = Util::linkToVarDocumentation(
$variables[$name]['doc'] = Generator::linkToVarDocumentation(
$name,
$this->dbi->isMariaDB()
);
Expand Down
11 changes: 7 additions & 4 deletions libraries/classes/Controllers/Server/VariablesController.php
Expand Up @@ -9,6 +9,7 @@
namespace PhpMyAdmin\Controllers\Server;

use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Util;
use Williamdes\MariaDBMySQLKBS\KBException;
use Williamdes\MariaDBMySQLKBS\Search as KBSearch;
Expand Down Expand Up @@ -54,15 +55,17 @@ public function index(array $params): string
foreach ($serverVars as $name => $value) {
$hasSessionValue = isset($serverVarsSession[$name])
&& $serverVarsSession[$name] !== $value;
$docLink = Util::linkToVarDocumentation(
$docLink = Generator::linkToVarDocumentation(
$name,
$this->dbi->isMariaDB(),
str_replace('_', '&nbsp;', $name)
);

list($formattedValue, $isEscaped) = $this->formatVariable($name, $value);
[$formattedValue, $isEscaped] = $this->formatVariable($name, $value);
if ($hasSessionValue) {
list($sessionFormattedValue, ) = $this->formatVariable(
[
$sessionFormattedValue,
] = $this->formatVariable(
$name,
$serverVarsSession[$name]
);
Expand Down Expand Up @@ -187,7 +190,7 @@ public function setValue(array $params): array
. '";',
'NUM'
);
list($formattedValue, $isHtmlFormatted) = $this->formatVariable(
[$formattedValue, $isHtmlFormatted] = $this->formatVariable(
$params['varName'],
$varValue[1]
);
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Table/IndexesController.php
Expand Up @@ -9,6 +9,7 @@
namespace PhpMyAdmin\Controllers\Table;

use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Index;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
Expand Down Expand Up @@ -158,7 +159,7 @@ public function doSaveDataAction()
$message->addParam($this->table);
$this->response->addJSON(
'message',
Util::getMessage($message, $sql_query, 'success')
Generator::getMessage($message, $sql_query, 'success')
);
$this->response->addJSON(
'index_table',
Expand Down

0 comments on commit 3255e4a

Please sign in to comment.