Skip to content

Commit

Permalink
Refactor Util Twig extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Strozzi <laps15@inf.ufpr.br>
  • Loading branch information
laps15 committed Aug 3, 2018
1 parent b65ede4 commit 1037b1d
Show file tree
Hide file tree
Showing 55 changed files with 254 additions and 247 deletions.
95 changes: 51 additions & 44 deletions libraries/classes/Twig/UtilExtension.php
Expand Up @@ -11,6 +11,7 @@

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use Twig\TwigFilter;

/**
* Class UtilExtension
Expand All @@ -28,164 +29,170 @@ public function getFunctions()
{
return [
new TwigFunction(
'Util_backquote',
'backquote',
'PhpMyAdmin\Util::backquote'
),
new TwigFunction(
'Util_getBrowseUploadFileBlock',
'get_browse_upload_file_block',
'PhpMyAdmin\Util::getBrowseUploadFileBlock',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_convertBitDefaultValue',
'PhpMyAdmin\Util::convertBitDefaultValue'
),
new TwigFunction(
'Util_escapeMysqlWildcards',
'PhpMyAdmin\Util::escapeMysqlWildcards'
),
new TwigFunction(
'Util_extractColumnSpec',
'extract_column_spec',
'PhpMyAdmin\Util::extractColumnSpec'
),
new TwigFunction(
'Util_formatByteDown',
'format_byte_down',
'PhpMyAdmin\Util::formatByteDown'
),
new TwigFunction(
'Util_formatNumber',
'format_number',
'PhpMyAdmin\Util::formatNumber'
),
new TwigFunction(
'Util_formatSql',
'format_sql',
'PhpMyAdmin\Util::formatSql',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getButtonOrImage',
'get_button_or_image',
'PhpMyAdmin\Util::getButtonOrImage',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getClassForType',
'get_class_for_type',
'PhpMyAdmin\Util::getClassForType',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getDivForSliderEffect',
'get_div_for_slider_effect',
'PhpMyAdmin\Util::getDivForSliderEffect',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getDocuLink',
'get_docu_link',
'PhpMyAdmin\Util::getDocuLink',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getListNavigator',
'get_list_navigator',
'PhpMyAdmin\Util::getListNavigator',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_showDocu',
'show_docu',
'PhpMyAdmin\Util::showDocu',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getDropdown',
'get_dropdown',
'PhpMyAdmin\Util::getDropdown',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getFKCheckbox',
'get_fk_checkbox',
'PhpMyAdmin\Util::getFKCheckbox',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getGISDatatypes',
'get_gis_datatypes',
'PhpMyAdmin\Util::getGISDatatypes'
),
new TwigFunction(
'Util_getGISFunctions',
'get_gis_functions',
'PhpMyAdmin\Util::getGISFunctions'
),
new TwigFunction(
'Util_getHtmlTab',
'get_html_tab',
'PhpMyAdmin\Util::getHtmlTab',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getIcon',
'get_icon',
'PhpMyAdmin\Util::getIcon',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getImage',
'get_image',
'PhpMyAdmin\Util::getImage',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getRadioFields',
'get_radio_fields',
'PhpMyAdmin\Util::getRadioFields',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getSelectUploadFileBlock',
'get_select_upload_file_block',
'PhpMyAdmin\Util::getSelectUploadFileBlock',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getScriptNameForOption',
'get_script_name_for_option',
'PhpMyAdmin\Util::getScriptNameForOption',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getStartAndNumberOfRowsPanel',
'get_start_and_number_of_rows_panel',
'PhpMyAdmin\Util::getStartAndNumberOfRowsPanel',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_getSupportedDatatypes',
'get_supported_datatypes',
'PhpMyAdmin\Util::getSupportedDatatypes',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_isForeignKeySupported',
'is_foreign_key_supported',
'PhpMyAdmin\Util::isForeignKeySupported'
),
new TwigFunction(
'Util_linkOrButton',
'link_or_button',
'PhpMyAdmin\Util::linkOrButton',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_localisedDate',
'localised_date',
'PhpMyAdmin\Util::localisedDate'
),
new TwigFunction(
'Util_showHint',
'show_hint',
'PhpMyAdmin\Util::showHint',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_showDocu',
'PhpMyAdmin\Util::showDocu',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_showIcons',
'show_icons',
'PhpMyAdmin\Util::showIcons'
),
new TwigFunction(
'Util_showMySQLDocu',
'show_mysql_docu',
'PhpMyAdmin\Util::showMySQLDocu',
['is_safe' => ['html']]
),
new TwigFunction(
'Util_sortableTableHeader',
'sortable_table_header',
'PhpMyAdmin\Util::sortableTableHeader',
['is_safe' => ['html']]
),
];
}

/**
* Returns a list of filters to add to the existing list.
*
* @return TwigFilter[]
*/
public function getFilters()
{
return [
new TwigFilter(
'convert_bit_default_value',
'PhpMyAdmin\Util::convertBitDefaultValue'
),
new TwigFilter(
'escape_mysql_wildcards',
'PhpMyAdmin\Util::convertBitDefaultValue'
),
];
}
}
6 changes: 3 additions & 3 deletions templates/columns_definitions/column_definitions_form.twig
Expand Up @@ -75,12 +75,12 @@
<td width="25">&nbsp;</td>
<th>
{% trans 'Storage Engine:' %}
{{ Util_showMySQLDocu('Storage_engines') }}
{{ show_mysql_docu('Storage_engines') }}
</th>
<td width="25">&nbsp;</td>
<th>
{% trans 'Connection:' %}
{{ Util_showMySQLDocu('federated-create-connection') }}
{{ show_mysql_docu('federated-create-connection') }}
</th>
</tr>
<tr>
Expand Down Expand Up @@ -126,7 +126,7 @@
<tr class="vtop">
<th colspan="5">
{% trans 'PARTITION definition:' %}
{{ Util_showMySQLDocu('Partitioning') }}
{{ show_mysql_docu('Partitioning') }}
</th>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion templates/columns_definitions/column_type.twig
Expand Up @@ -4,5 +4,5 @@
{%- if column_meta['column_status'] is defined and not column_meta['column_status']['isEditable'] -%}
disabled="disabled"
{%- endif %}>
{{ Util_getSupportedDatatypes(true, type_upper) }}
{{ get_supported_datatypes(true, type_upper) }}
</select>
2 changes: 1 addition & 1 deletion templates/columns_definitions/move_column.twig
Expand Up @@ -9,7 +9,7 @@
{% for mi in 0..move_columns|length - 1 %}
<option value="{{ move_columns[mi].name }}"
{{- current_index == mi or current_index == mi + 1 ? ' disabled="disabled"' }}>
{{ 'after %s'|trans|format(Util_backquote(move_columns[mi].name|e)) }}
{{ 'after %s'|trans|format(backquote(move_columns[mi].name|e)) }}
</option>
{% endfor %}
</select>
14 changes: 7 additions & 7 deletions templates/columns_definitions/table_fields_definitions.twig
Expand Up @@ -2,23 +2,23 @@
<table id="table_columns" class="noclick">
<caption class="tblHeaders">
{% trans 'Structure' %}
{{ Util_showMySQLDocu('CREATE_TABLE') }}
{{ show_mysql_docu('CREATE_TABLE') }}
</caption>
<tr>
<th>
{% trans 'Name' %}
</th>
<th>
{% trans 'Type' %}
{{ Util_showMySQLDocu('data-types') }}
{{ show_mysql_docu('data-types') }}
</th>
<th>
{% trans 'Length/Values' %}
{{ Util_showHint('If column type is "enum" or "set", please enter the values using this format: \'a\',\'b\',\'c\'…<br />If you ever need to put a backslash ("\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'|trans) }}
{{ show_hint('If column type is "enum" or "set", please enter the values using this format: \'a\',\'b\',\'c\'…<br />If you ever need to put a backslash ("\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'|trans) }}
</th>
<th>
{% trans 'Default' %}
{{ Util_showHint('For default values, please enter just a single value, without backslash escaping or quotes, using this format: a'|trans) }}
{{ show_hint('For default values, please enter just a single value, without backslash escaping or quotes, using this format: a'|trans) }}
</th>
<th>
{% trans 'Collation' %}
Expand All @@ -34,7 +34,7 @@
{% if change_column is defined and change_column is not empty %}
<th>
{% trans 'Adjust privileges' %}
{{ Util_showDocu('faq', 'faq6-39') }}
{{ show_docu('faq', 'faq6-39') }}
</th>
{% endif %}
Expand Down Expand Up @@ -80,7 +80,7 @@
</th>
<th>
{% trans 'Browser display transformation options' %}
{{ Util_showHint('Please enter the values for transformation options using this format: \'a\', 100, b,\'c\'…<br />If you ever need to put a backslash ("\\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'|trans) }}
{{ show_hint('Please enter the values for transformation options using this format: \'a\', 100, b,\'c\'…<br />If you ever need to put a backslash ("\\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'|trans) }}
</th>
<th>
<a href="transformation_overview.php{{ get_common() }}#input_transformation"
Expand All @@ -91,7 +91,7 @@
</th>
<th>
{% trans 'Input transformation options' %}
{{ Util_showHint('Please enter the values for transformation options using this format: \'a\', 100, b,\'c\'…<br />If you ever need to put a backslash ("\\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'|trans) }}
{{ show_hint('Please enter the values for transformation options using this format: \'a\', 100, b,\'c\'…<br />If you ever need to put a backslash ("\\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'|trans) }}
</th>
{% endif %}
</tr>
Expand Down
10 changes: 5 additions & 5 deletions templates/database/central_columns/main.twig
Expand Up @@ -189,7 +189,7 @@
<tr>
<td class="navigation_separator largescreenonly"></td>
<td class="central_columns_navigation">
{{ Util_getIcon('centralColumns_add', 'Add column' | trans)|raw }}
{{ get_icon('centralColumns_add', 'Add column' | trans)|raw }}
<form id="add_column" action="db_central_columns.php" method="post">
{{ get_hidden_inputs(db) | raw }}
<input type="hidden" name="add_column" value="add">
Expand Down Expand Up @@ -276,10 +276,10 @@
value="{{ row['col_name'] | raw }}" id="{{ 'checkbox_row_' ~ row_num }}"/>
</td>
<td id="{{ 'edit_' ~ row_num }}" class="edit center">
<a href="#"> {{ Util_getIcon('b_edit', 'Edit' | trans) | raw }}</a>
<a href="#"> {{ get_icon('b_edit', 'Edit' | trans) | raw }}</a>
</td>
<td class="del_row" data-rownum = "{{ row_num }}">
<a hrf="#">{{ Util_getIcon('b_drop', 'Delete' | trans) }}</a>
<a hrf="#">{{ get_icon('b_drop', 'Delete' | trans) }}</a>
<input type="submit" data-rownum = "{{ row_num }}" class="edit_cancel_form" value="Cancel">
</td>
<td id="{{ 'save_' ~ row_num }}" class="hide">
Expand Down Expand Up @@ -391,14 +391,14 @@
'text_dir' : text_dir,
'form_name' : 'tableslistcontainer',
} only %}
{{ Util_getButtonOrImage(
{{ get_button_or_image(
'edit_central_columns',
'mult_submit change_central_columns',
'Edit' | trans,
'b_edit',
'edit central columns'
) | raw }}
{{ Util_getButtonOrImage(
{{ get_button_or_image(
'delete_central_columns',
'mult_submit',
'Delete' | trans,
Expand Down
4 changes: 2 additions & 2 deletions templates/database/create_table.twig
@@ -1,8 +1,8 @@
<form id="create_table_form_minimal" method="post" action="tbl_create.php" class="lock-page">
<fieldset>
<legend>
{% if Util_showIcons('ActionLinksMode') -%}
{{ Util_getImage('b_table_add') }}
{% if show_icons('ActionLinksMode') -%}
{{ get_image('b_table_add') }}
{%- endif %}
{% trans "Create table" %}
</legend>
Expand Down
2 changes: 1 addition & 1 deletion templates/database/designer/database_tables.twig
Expand Up @@ -64,7 +64,7 @@
table_names_small_url[i],
tab_column[t_n]['COLUMN_NAME'][j]|url_encode
] %}
{% if not Util_isForeignKeySupported(table_types[i]) %}
{% if not is_foreign_key_supported(table_types[i]) %}
{% set click_field_param = click_field_param|merge([tables_pk_or_unique_keys[tmp_column] is defined ? 1 : 0]) %}
{% else %}
{# if foreign keys are supported, it's not necessary that the
Expand Down
2 changes: 1 addition & 1 deletion templates/database/designer/main.twig
Expand Up @@ -110,7 +110,7 @@ var designer_config = {{ designer_config | raw }};
{% trans 'Reload' %}
</span>
</a>
<a href="{{ Util_getDocuLink('faq', 'faq6-31') }}"
<a href="{{ get_docu_link('faq', 'faq6-31') }}"
target="documentation"
class="M_butt">
<img title="{% trans 'Help' %}"
Expand Down
2 changes: 1 addition & 1 deletion templates/database/designer/page_save_as.twig
Expand Up @@ -14,7 +14,7 @@
</tr>
<tr>
<td>
{{ Util_getRadioFields(
{{ get_radio_fields(
'save_page',
{
'same': 'Save to selected page'|trans,
Expand Down

0 comments on commit 1037b1d

Please sign in to comment.