Merge pull request #16345 from mauriciofauth/remove-titles

Remove Util::buildActionTitles and the titles global variable
This commit is contained in:
Maurício Meneghini Fauth 2020-09-13 10:44:09 -03:00 committed by GitHub
commit ec10464cc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 22 additions and 178 deletions

View File

@ -42,7 +42,7 @@ class RoutinesController extends AbstractController
{
global $db, $table, $tables, $num_tables, $total_num_tables, $sub_part, $is_show_stats;
global $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos;
global $errors, $titles;
global $errors;
$params = ['type' => $_REQUEST['type'] ?? null];
@ -74,11 +74,6 @@ class RoutinesController extends AbstractController
$this->dbi->selectDb($db);
}
/**
* Create labels for the list
*/
$titles = Util::buildActionTitles();
/**
* Keep a list of errors that occurred while
* processing an 'Add' or 'Edit' operation.

View File

@ -249,7 +249,6 @@ class StructureController extends AbstractController
return;
}
$changes = true;
$titles = Util::buildActionTitles();
$favoriteTable = $parameters['favorite_table'] ?? '';
$alreadyFavorite = $this->checkFavoriteTable($favoriteTable);
@ -300,7 +299,6 @@ class StructureController extends AbstractController
'db_table_name_hash' => md5($this->db . '.' . $favoriteTable),
'fav_params' => $favoriteParams,
'already_favorite' => $alreadyFavorite,
'titles' => $titles,
]);
$this->response->addJSON($json);
@ -540,7 +538,6 @@ class StructureController extends AbstractController
* the code easier to read without this operator.
*/
$may_have_rows = $current_table['TABLE_ROWS'] > 0 || $table_is_view;
$titles = Util::buildActionTitles();
if (! $this->dbIsSystemSchema) {
$drop_query = sprintf(
@ -601,8 +598,7 @@ class StructureController extends AbstractController
'input_class' => implode(' ', $input_class),
'table_is_view' => $table_is_view,
'current_table' => $current_table,
'browse_table_title' => $may_have_rows ? $titles['Browse'] : $titles['NoBrowse'],
'search_table_title' => $may_have_rows ? $titles['Search'] : $titles['NoSearch'],
'may_have_rows' => $may_have_rows,
'browse_table_label_title' => htmlspecialchars($current_table['TABLE_COMMENT']),
'browse_table_label_truename' => $truename,
'empty_table_sql_query' => 'TRUNCATE ' . Util::backquote(
@ -616,12 +612,10 @@ class StructureController extends AbstractController
)
)
),
'empty_table_title' => $may_have_rows ? $titles['Empty'] : $titles['NoEmpty'],
'tracking_icon' => $this->getTrackingIcon($truename),
'server_slave_status' => $replicaInfo['status'],
'table_url_params' => $tableUrlParams,
'db_is_system_schema' => $this->dbIsSystemSchema,
'titles' => $titles,
'drop_query' => $drop_query,
'drop_message' => $drop_message,
'collation' => $collationDefinition,

View File

@ -22,7 +22,7 @@ class TriggersController extends AbstractController
{
global $db, $table, $tables, $num_tables, $total_num_tables, $sub_part, $is_show_stats;
global $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos;
global $errors, $titles;
global $errors;
if (! $this->response->isAjax()) {
/**
@ -50,11 +50,6 @@ class TriggersController extends AbstractController
$this->dbi->selectDb($db);
}
/**
* Create labels for the list
*/
$titles = Util::buildActionTitles();
/**
* Keep a list of errors that occurred while
* processing an 'Add' or 'Edit' operation.

View File

@ -60,7 +60,7 @@ class ChangeController extends AbstractController
global $result, $rows, $found_unique_key, $after_insert, $comments_map, $table_columns;
global $chg_evt_handler, $timestamp_seen, $columns_cnt, $tabindex, $tabindex_for_function;
global $tabindex_for_null, $tabindex_for_value, $o_rows, $biggest_max_file_size, $has_blob_field;
global $titles, $jsvkey, $vkey, $current_result, $repopulate, $checked;
global $jsvkey, $vkey, $current_result, $repopulate, $checked;
$pageSettings = new PageSettings('Edit');
$this->response->addHTML($pageSettings->getErrorHTML());
@ -197,8 +197,6 @@ class ChangeController extends AbstractController
$html_output .= Url::getHiddenInputs($_form_params);
$titles['Browse'] = Generator::getIcon('b_browse', __('Browse foreign values'));
// user can toggle the display of Function column and column types
// (currently does not work for multi-edits)
if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
@ -257,7 +255,6 @@ class ChangeController extends AbstractController
$table,
$db,
$row_id,
$titles,
$biggest_max_file_size,
$text_dir,
$repopulate,

View File

@ -6,7 +6,6 @@ namespace PhpMyAdmin\Controllers\Table;
use PhpMyAdmin\Common;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Operations;
use PhpMyAdmin\Relation;
use PhpMyAdmin\RelationCleanup;
@ -360,12 +359,6 @@ class SearchController extends AbstractController
{
$selected_operator = ($_POST['criteriaColumnOperators'][$search_index] ?? '');
$entered_value = ($_POST['criteriaValues'] ?? '');
$titles = [
'Browse' => Generator::getIcon(
'b_browse',
__('Browse foreign values')
),
];
//Gets column's type and collation
$type = $this->columnTypes[$column_index];
$collation = $this->columnCollations[$column_index];
@ -421,7 +414,6 @@ class SearchController extends AbstractController
'foreign_max_limit' => $GLOBALS['cfg']['ForeignKeyMaxLimit'],
'criteria_values' => $entered_value,
'db' => $this->db,
'titles' => $titles,
'in_fbs' => true,
]);

View File

@ -1467,23 +1467,6 @@ class StructureController extends AbstractController
$this->table
);
$titles = [
'Change' => Generator::getIcon('b_edit', __('Change')),
'Drop' => Generator::getIcon('b_drop', __('Drop')),
'NoDrop' => Generator::getIcon('b_drop', __('Drop')),
'Primary' => Generator::getIcon('b_primary', __('Primary')),
'Index' => Generator::getIcon('b_index', __('Index')),
'Unique' => Generator::getIcon('b_unique', __('Unique')),
'Spatial' => Generator::getIcon('b_spatial', __('Spatial')),
'IdxFulltext' => Generator::getIcon('b_ftext', __('Fulltext')),
'NoPrimary' => Generator::getIcon('bd_primary', __('Primary')),
'NoIndex' => Generator::getIcon('bd_index', __('Index')),
'NoUnique' => Generator::getIcon('bd_unique', __('Unique')),
'NoSpatial' => Generator::getIcon('bd_spatial', __('Spatial')),
'NoIdxFulltext' => Generator::getIcon('bd_ftext', __('Fulltext')),
'DistinctValues' => Generator::getIcon('b_browse', __('Distinct values')),
];
/**
* Displays Space usage and row statistics
*/
@ -1569,7 +1552,6 @@ class StructureController extends AbstractController
'db_is_system_schema' => $db_is_system_schema,
'tbl_is_view' => $tbl_is_view,
'mime_map' => $mime_map,
'titles' => $titles,
'tbl_storage_engine' => $tbl_storage_engine,
'primary' => $primary_index,
'columns_with_unique_index' => $columns_with_unique_index,

View File

@ -19,7 +19,7 @@ class TriggersController extends AbstractController
{
global $db, $table, $tables, $num_tables, $total_num_tables, $sub_part, $is_show_stats;
global $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos;
global $errors, $titles;
global $errors;
if (! $this->response->isAjax()) {
/**
@ -47,11 +47,6 @@ class TriggersController extends AbstractController
$this->dbi->selectDb($db);
}
/**
* Create labels for the list
*/
$titles = Util::buildActionTitles();
/**
* Keep a list of errors that occurred while
* processing an 'Add' or 'Edit' operation.

View File

@ -6,7 +6,6 @@ namespace PhpMyAdmin\Controllers\Table;
use PhpMyAdmin\Common;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
use PhpMyAdmin\Table\Search;
@ -382,13 +381,6 @@ class ZoomSearchController extends AbstractController
}
unset($tmpData);
//Displays form for point data and scatter plot
$titles = [
'Browse' => Generator::getIcon(
'b_browse',
__('Browse foreign values')
),
];
$column_names_hashes = [];
foreach ($this->columnNames as $columnName) {
@ -403,7 +395,6 @@ class ZoomSearchController extends AbstractController
'foreigners' => $this->foreigners,
'column_null_flags' => $this->columnNullFlags,
'column_types' => $this->columnTypes,
'titles' => $titles,
'goto' => $goto,
'data' => $data,
'data_json' => json_encode($data),
@ -425,12 +416,6 @@ class ZoomSearchController extends AbstractController
{
$selected_operator = ($_POST['criteriaColumnOperators'][$search_index] ?? '');
$entered_value = ($_POST['criteriaValues'] ?? '');
$titles = [
'Browse' => Generator::getIcon(
'b_browse',
__('Browse foreign values')
),
];
//Gets column's type and collation
$type = $this->columnTypes[$column_index];
$collation = $this->columnCollations[$column_index];
@ -486,7 +471,6 @@ class ZoomSearchController extends AbstractController
'foreign_max_limit' => $GLOBALS['cfg']['ForeignKeyMaxLimit'],
'criteria_values' => $entered_value,
'db' => $this->db,
'titles' => $titles,
'in_fbs' => true,
]);

View File

@ -680,9 +680,6 @@ class InsertEdit
* @param array $foreignData data about the foreign keys
* @param array $paramTableDbArray array containing $table and $db
* @param int $rownumber the row number
* @param array $titles An HTML IMG tag for a particular icon from
* a theme, which may be an actual file or
* an icon from a sprite
* @param string $text_dir text direction
* @param string $special_chars_encoded replaced char if the string starts
* with a \r\n pair (0x0d0a) add an extra \n
@ -714,7 +711,6 @@ class InsertEdit
array $foreignData,
array $paramTableDbArray,
$rownumber,
array $titles,
$text_dir,
$special_chars_encoded,
$vkey,
@ -742,7 +738,6 @@ class InsertEdit
$data,
$paramTableDbArray,
$rownumber,
$titles,
$readOnly
);
} elseif (is_array($foreignData['disp_row'])) {
@ -880,9 +875,6 @@ class InsertEdit
* @param string $data data to edit
* @param array $paramTableDbArray array containing $table and $db
* @param int $rownumber the row number
* @param array $titles An HTML IMG tag for a particular icon from
* a theme, which may be an actual file or
* an icon from a sprite
* @param bool $readOnly is column read only or not
*
* @return string an html snippet
@ -898,7 +890,6 @@ class InsertEdit
$data,
array $paramTableDbArray,
$rownumber,
array $titles,
$readOnly
) {
[$table, $db] = $paramTableDbArray;
@ -929,7 +920,7 @@ class InsertEdit
],
''
) . '">'
. str_replace("'", "\'", $titles['Browse']) . '</a>';
. Generator::getIcon('b_browse', __('Browse foreign values')) . '</a>';
return $html_output;
}
@ -3219,7 +3210,6 @@ class InsertEdit
* @param string $table table
* @param string $db database
* @param int $row_id row id
* @param array $titles titles
* @param int $biggest_max_file_size biggest max file size
* @param string $default_char_editing default char editing mode which is stored
* in the config.inc.php script
@ -3252,7 +3242,6 @@ class InsertEdit
$table,
$db,
$row_id,
array $titles,
$biggest_max_file_size,
$default_char_editing,
$text_dir,
@ -3492,7 +3481,6 @@ class InsertEdit
$db,
],
$row_id,
$titles,
$text_dir,
$special_chars_encoded,
$vkey,
@ -3533,7 +3521,6 @@ class InsertEdit
* @param string $table table
* @param string $db database
* @param int $row_id row id
* @param array $titles titles
* @param int $biggest_max_file_size biggest max file size
* @param string $text_dir text direction
* @param array $repopulate the data to be repopulated
@ -3563,7 +3550,6 @@ class InsertEdit
$table,
$db,
$row_id,
array $titles,
$biggest_max_file_size,
$text_dir,
array $repopulate,
@ -3618,7 +3604,6 @@ class InsertEdit
$table,
$db,
$row_id,
$titles,
$biggest_max_file_size,
$default_char_editing,
$text_dir,

View File

@ -3174,39 +3174,6 @@ class Util
return ctype_digit((string) $input);
}
/**
* Build titles and icons for action links
*
* @return array the action titles
*/
public static function buildActionTitles(): array
{
$titles = [];
$titles['Browse'] = Generator::getIcon('b_browse', __('Browse'));
$titles['NoBrowse'] = Generator::getIcon('bd_browse', __('Browse'));
$titles['Search'] = Generator::getIcon('b_select', __('Search'));
$titles['NoSearch'] = Generator::getIcon('bd_select', __('Search'));
$titles['Insert'] = Generator::getIcon('b_insrow', __('Insert'));
$titles['NoInsert'] = Generator::getIcon('bd_insrow', __('Insert'));
$titles['Structure'] = Generator::getIcon('b_props', __('Structure'));
$titles['Drop'] = Generator::getIcon('b_drop', __('Drop'));
$titles['NoDrop'] = Generator::getIcon('bd_drop', __('Drop'));
$titles['Empty'] = Generator::getIcon('b_empty', __('Empty'));
$titles['NoEmpty'] = Generator::getIcon('bd_empty', __('Empty'));
$titles['Edit'] = Generator::getIcon('b_edit', __('Edit'));
$titles['NoEdit'] = Generator::getIcon('bd_edit', __('Edit'));
$titles['Export'] = Generator::getIcon('b_export', __('Export'));
$titles['NoExport'] = Generator::getIcon('bd_export', __('Export'));
$titles['Execute'] = Generator::getIcon('b_nextpage', __('Execute'));
$titles['NoExecute'] = Generator::getIcon('bd_nextpage', __('Execute'));
// For Favorite/NoFavorite, we need icon only.
$titles['Favorite'] = Generator::getIcon('b_favorite', '');
$titles['NoFavorite'] = Generator::getIcon('b_no_favorite', '');
return $titles;
}
/**
* Get the protocol from the RFC 7239 Forwarded header
*

View File

@ -2,6 +2,6 @@
class="ajax favorite_table_anchor"
href="{{ url('/database/structure/favorite-table', fav_params) }}"
title="{{ already_favorite ? 'Remove from Favorites'|trans : 'Add to Favorites'|trans }}"
data-favtargets="{{ db_table_name_hash }}" >
{{ already_favorite ? titles['Favorite']|raw : titles['NoFavorite']|raw }}
data-favtargets="{{ db_table_name_hash }}">
{{ already_favorite ? get_icon('b_favorite') : get_icon('b_no_favorite') }}
</a>

View File

@ -34,38 +34,36 @@
'db_table_name_hash': db_table_name_hash,
'fav_params': fav_params,
'already_favorite': already_favorite,
'titles': titles
} only %}
</td>
{% endif %}
<td class="text-center print_ignore">
<a href="{{ url('/sql', table_url_params|merge({'pos': 0})) }}">
{{ browse_table_title|raw }}
{{ may_have_rows ? get_icon('b_browse', 'Browse'|trans) : get_icon('bd_browse', 'Browse'|trans) }}
</a>
</td>
<td class="text-center print_ignore">
<a href="{{ url('/table/structure', table_url_params) }}">
{{ titles['Structure']|raw }}
{{ get_icon('b_props', 'Structure'|trans) }}
</a>
</td>
<td class="text-center print_ignore">
<a href="{{ url('/table/search', table_url_params) }}">
{{ search_table_title|raw }}
{{ may_have_rows ? get_icon('b_select', 'Search'|trans) : get_icon('bd_select', 'Search'|trans) }}
</a>
</td>
{% if not db_is_system_schema %}
<td class="insert_table text-center print_ignore">
<a href="{{ url('/table/change', table_url_params) }}">{{ titles['Insert']|raw }}</a>
<a href="{{ url('/table/change', table_url_params) }}">{{ get_icon('b_insrow', 'Insert'|trans) }}</a>
</td>
{% if table_is_view %}
<td class="text-center print_ignore">
<a href="{{ url('/view/create', {
'db': db,
'table': current_table['TABLE_NAME']
}) }}">{{ titles['Edit']|raw }}</a>
}) }}">{{ get_icon('b_edit', 'Edit'|trans) }}</a>
</td>
{% else %}
<td class="text-center print_ignore">
@ -73,7 +71,7 @@
'sql_query': empty_table_sql_query,
'message_to_show': empty_table_message_to_show
}), '') }}">
{{ empty_table_title|raw }}
{{ may_have_rows ? get_icon('b_empty', 'Empty'|trans) : get_icon('bd_empty', 'Empty'|trans) }}
</a>
</td>
{% endif %}
@ -86,7 +84,7 @@
'sql_query': drop_query,
'message_to_show': drop_message
}), '') }}">
{{ titles['Drop']|raw }}
{{ get_icon('b_drop', 'Drop'|trans) }}
</a>
</td>
{% endif %}

View File

@ -24,7 +24,7 @@
{{- get_common({'db': db, 'table': table}, '') -}}
&amp;field={{ column_name|url_encode }}&amp;fieldkey=
{{- column_index }}&amp;fromsearch=1">
{{ titles['Browse']|replace({"'": "\\'"})|raw }}
{{ get_icon('b_browse', 'Browse foreign values'|trans) }}
</a>
{% endif %}
{% elseif column_type in get_gis_datatypes() %}

View File

@ -106,7 +106,7 @@
'field': row['Field'],
'change_column': 1
}) }}">
{{ titles['Change']|raw }}
{{ get_icon('b_edit', 'Change'|trans) }}
</a>
</td>
<td class="drop text-center print_ignore">
@ -118,7 +118,7 @@
'purge': true,
'message_to_show': 'Column %s has been dropped.'|trans|format(row['Field']|e)
}) }}">
{{ titles['Drop']|raw }}
{{ get_icon('b_drop', 'Drop'|trans) }}
</a>
</td>
{% endif %}
@ -217,10 +217,10 @@
'sql_query': 'ALTER TABLE ' ~ backquote(table) ~ ' ADD FULLTEXT(' ~ backquote(row['Field']) ~ ');',
'message_to_show': 'An index has been added on %s.'|trans|format(row['Field']|e)
}) }}">
{{ titles['IdxFulltext']|raw }}
{{ get_icon('b_ftext', 'Fulltext'|trans) }}
</a>
{% else %}
{{ titles['NoIdxFulltext']|raw }}
{{ get_icon('bd_ftext', 'Fulltext'|trans) }}
{% endif %}
</li>
@ -236,7 +236,7 @@
~ ' ORDER BY ' ~ backquote(row['Field']),
'is_browse_distinct': true
}) }}">
{{ titles['DistinctValues']|raw }}
{{ get_icon('b_browse', 'Distinct values'|trans) }}
</a>
</li>
{% if central_columns_work %}

View File

@ -70,7 +70,6 @@
'foreign_max_limit': foreign_max_limit,
'criteria_values': '',
'db': db,
'titles': titles,
'in_fbs': false
} only %}
</th>

View File

@ -1108,9 +1108,8 @@ class InsertEditTest extends AbstractTestCase
*/
public function testGetForeignLink(): void
{
$column = $titles = [];
$column = [];
$column['Field'] = 'f';
$titles['Browse'] = "'";
$GLOBALS['cfg']['ServerDefault'] = 2;
$result = $this->callFunction(
$this->insertEdit,
@ -1130,7 +1129,6 @@ class InsertEditTest extends AbstractTestCase
'db',
],
8,
$titles,
false,
]
);
@ -4084,7 +4082,6 @@ class InsertEditTest extends AbstractTestCase
'table',
'db',
0,
[],
0,
'',
'',
@ -4167,7 +4164,6 @@ class InsertEditTest extends AbstractTestCase
'table',
'db',
0,
[],
0,
'',
'',
@ -4239,7 +4235,6 @@ class InsertEditTest extends AbstractTestCase
'table',
'db',
0,
[],
0,
'',
[],
@ -4325,7 +4320,6 @@ class InsertEditTest extends AbstractTestCase
'table',
'db',
0,
[],
0,
'',
[],
@ -4385,7 +4379,6 @@ class InsertEditTest extends AbstractTestCase
'table',
'db',
0,
[],
0,
'',
[],

View File

@ -8,7 +8,6 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Core;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\MoTranslator\Loader;
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\SqlParser\Token;
@ -1997,37 +1996,6 @@ class UtilTest extends AbstractTestCase
$this->assertEquals(Util::getPageFromPosition(1, 6), 1);
}
/**
* Test for PhpMyAdmin\Util::buildActionTitles
*/
public function testBuildActionTitles(): void
{
$GLOBALS['cfg'] = ['ActionLinksMode' => 'both'];
$titles = [];
$titles['Browse'] = Generator::getIcon('b_browse', __('Browse'));
$titles['NoBrowse'] = Generator::getIcon('bd_browse', __('Browse'));
$titles['Search'] = Generator::getIcon('b_select', __('Search'));
$titles['NoSearch'] = Generator::getIcon('bd_select', __('Search'));
$titles['Insert'] = Generator::getIcon('b_insrow', __('Insert'));
$titles['NoInsert'] = Generator::getIcon('bd_insrow', __('Insert'));
$titles['Structure'] = Generator::getIcon('b_props', __('Structure'));
$titles['Drop'] = Generator::getIcon('b_drop', __('Drop'));
$titles['NoDrop'] = Generator::getIcon('bd_drop', __('Drop'));
$titles['Empty'] = Generator::getIcon('b_empty', __('Empty'));
$titles['NoEmpty'] = Generator::getIcon('bd_empty', __('Empty'));
$titles['Edit'] = Generator::getIcon('b_edit', __('Edit'));
$titles['NoEdit'] = Generator::getIcon('bd_edit', __('Edit'));
$titles['Export'] = Generator::getIcon('b_export', __('Export'));
$titles['NoExport'] = Generator::getIcon('bd_export', __('Export'));
$titles['Execute'] = Generator::getIcon('b_nextpage', __('Execute'));
$titles['NoExecute'] = Generator::getIcon('bd_nextpage', __('Execute'));
$titles['Favorite'] = Generator::getIcon('b_favorite', '');
$titles['NoFavorite'] = Generator::getIcon('b_no_favorite', '');
$this->assertEquals($titles, Util::buildActionTitles());
}
/**
* Test for Util::isInteger
*