Skip to content

Commit

Permalink
Merge #16192 - Support Twig 3
Browse files Browse the repository at this point in the history
Pull-request: #16192
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Jun 15, 2020
2 parents 179ce1c + f7b6949 commit 289fbc1
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 109 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
"phpmyadmin/motranslator": "^4.0",
"phpmyadmin/shapefile": "^2.0",
"phpmyadmin/sql-parser": "^5.0",
"phpmyadmin/twig-i18n-extension": "^2.0",
"phpmyadmin/twig-i18n-extension": "^2.0 || ^3.0",
"phpseclib/phpseclib": "^2.0",
"symfony/config": "^4.2.8",
"symfony/dependency-injection": "^4.2.8",
"symfony/expression-language": "^4.2",
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-mbstring": "^1.3",
"symfony/yaml": "^4.2.8",
"twig/twig": "^2.9",
"twig/twig": "^2.9 || ^3",
"williamdes/mariadb-mysql-kbs": "^1.2"
},
"conflict": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\ReplicationGui;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;

/**
* Server replications
Expand All @@ -27,9 +24,9 @@ class ReplicationController extends AbstractController
*
* @return string HTML
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function index(array $params, ReplicationGui $replicationGui): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
use PhpMyAdmin\ReplicationGui;
use PhpMyAdmin\Util;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;

/**
* Class StatusController
Expand All @@ -27,9 +24,9 @@ class StatusController extends AbstractController
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function index(ReplicationGui $replicationGui): string
{
Expand Down
9 changes: 3 additions & 6 deletions libraries/classes/Display/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Template;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;

/**
* Displays Error
Expand All @@ -32,9 +29,9 @@ class Error
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public static function display(
Template $template,
Expand Down
9 changes: 3 additions & 6 deletions libraries/classes/Display/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;

/**
* PhpMyAdmin\Display\Export class
Expand Down Expand Up @@ -576,9 +573,9 @@ public function getHtmlForOptions(
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
private function getHtmlForCurrentAlias()
{
Expand Down
9 changes: 3 additions & 6 deletions libraries/classes/Plugins/TwoFactor/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
use Samyoul\U2F\U2FServer\U2FServer;
use stdClass;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;

/**
* Hardware key based two-factor authentication
Expand Down Expand Up @@ -137,9 +134,9 @@ public function render()
* @return string HTML code
* @throws U2FException
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function setup()
{
Expand Down
24 changes: 9 additions & 15 deletions libraries/classes/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@
use RuntimeException;
use Throwable;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
use Twig_TemplateWrapper;
use Twig\TemplateWrapper;

/**
* Class Template
Expand Down Expand Up @@ -95,12 +89,12 @@ public function __construct()
*
* @param string $templateName Template path name
*
* @return Twig_TemplateWrapper
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
* @return TemplateWrapper
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function load(string $templateName): Twig_TemplateWrapper
public function load(string $templateName): TemplateWrapper
{
try {
$template = static::$twig->load($templateName . '.twig');
Expand Down Expand Up @@ -131,9 +125,9 @@ public function load(string $templateName): Twig_TemplateWrapper
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function render(string $template, array $data = []): string
{
Expand Down
3 changes: 1 addition & 2 deletions libraries/classes/Twig/I18n/TokenParserTrans.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use PhpMyAdmin\Twig\Extensions\TokenParser\TransTokenParser;
use Twig\Token;
use Twig_Error_Syntax;

/**
* Class TokenParserTrans
Expand All @@ -27,7 +26,7 @@ class TokenParserTrans extends TransTokenParser
*
* @return NodeTrans
*
* @throws Twig_Error_Syntax
* @throws \Twig\Error\SyntaxError
*/
public function parse(Token $token)
{
Expand Down
15 changes: 6 additions & 9 deletions libraries/classes/UserPreferencesHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

use PhpMyAdmin\Config\Forms\User\UserFormList;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;

/**
* Functions for displaying user preferences header
Expand All @@ -30,9 +27,9 @@ class UserPreferencesHeader
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public static function getContent(Template $template, Relation $relation): string
{
Expand All @@ -46,9 +43,9 @@ public static function getContent(Template $template, Relation $relation): strin
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
protected static function displayTabs(Template $template): string
{
Expand Down
6 changes: 5 additions & 1 deletion scripts/generate-twig-cache
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ foreach (new \RecursiveIteratorIterator(
// force compilation
if ($file->isFile() && $file->getExtension() === 'twig') {
$name = str_replace($tplDir . '/', '', $file->getPathname());
$template = $twig->loadTemplate($name);
if (Environment::MAJOR_VERSION === 3) {
$template = $twig->loadTemplate($twig->getTemplateClass($name), $name);
} else {
$template = $twig->loadTemplate($name);
}

// Generate line map
$cacheFilename = $twigCache->generateKey($name, $twig->getTemplateClass($name));
Expand Down
4 changes: 1 addition & 3 deletions templates/columns_definitions/column_virtuality.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
</select>

{% if char_editing == 'textarea' %}
{% apply spaceless %}
<textarea name="field_expression[{{ column_number }}]"
cols="15"
class="textfield expression">
{{ expression }}
{{- expression -}}
</textarea>
{% endapply %}
{% else %}
<input type="text"
name="field_expression[{{ column_number }}]"
Expand Down
4 changes: 1 addition & 3 deletions templates/columns_definitions/partitions.twig
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@
) }}
</td>
<td>
{% apply spaceless %}
<textarea name="{{ subpartition['prefix'] }}[comment]">
{{ subpartition['comment'] }}
{{- subpartition['comment'] -}}
</textarea>
{% endapply %}
</td>
<td>
<input type="text" name="{{ subpartition['prefix'] }}[data_directory]"
Expand Down
2 changes: 0 additions & 2 deletions templates/database/designer/main.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{# Invisible characters will make javascript crash #}
{% apply spaceless %}
<script type="text/javascript">
var designerConfig = {{ designer_config|raw }};
</script>
{% endapply %}

{# side menu #}
{% if not has_query %}
Expand Down
16 changes: 7 additions & 9 deletions templates/database/multi_table_query/form.twig
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,13 @@
</fieldset>

<fieldset>
{% apply spaceless %}
<textarea id="MultiSqlquery"
cols="80"
rows="4"
style="float:left"
name="sql_query"
dir="ltr">
</textarea>
{% endapply %}
{# Keep the block without a space between the open and close tag #}
<textarea id="MultiSqlquery"
cols="80"
rows="4"
style="float: left;"
name="sql_query"
dir="ltr"></textarea>
</fieldset>
</fieldset>

Expand Down
17 changes: 8 additions & 9 deletions templates/display/export/options_rows.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
<li>
<label for="limit_to">{% trans 'Number of rows:' %}</label>
<input type="text" id="limit_to" name="limit_to" size="5" value="
{%- apply spaceless %}
{% if limit_to is not null %}
{{ limit_to }}
{% elseif unlim_num_rows is not empty and unlim_num_rows != 0 %}
{{ unlim_num_rows }}
{% else %}
{{ number_of_rows }}
{% endif %}
{% endapply %}" onfocus="this.select()">
{# Keep everything space less because it is a value #}
{%- if limit_to is not null -%}
{{- limit_to -}}
{%- elseif unlim_num_rows is not empty and unlim_num_rows != 0 -%}
{{- unlim_num_rows -}}
{%- else %}
{{- number_of_rows -}}
{%- endif -%}" onfocus="this.select()">
</li>
<li>
<label for="limit_from">{% trans 'Row to begin at:' %}</label>
Expand Down
4 changes: 1 addition & 3 deletions templates/display/import/javascript.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ $( function() {
{% set import_url = get_common_raw({'import_status': 1}, '&') %}

{% set upload_html %}
{% apply spaceless %}
<div class="upload_progress">
<div class="upload_progress_bar_outer">
<div class="percentage"></div>
Expand All @@ -31,7 +30,6 @@ $( function() {
</div>
<div id="statustext"></div>
</div>
{% endapply %}
{% endset %}

{# Start output #}
Expand Down Expand Up @@ -79,7 +77,7 @@ $( function() {
{# Show progress UI #}
$("#importmain").hide();
$("#import_form_status")
.html('{{ upload_html|raw }}')
.html('{{ upload_html|spaceless|raw }}')
.show();
import_start = now;
}
Expand Down
15 changes: 6 additions & 9 deletions test/classes/Display/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
use PhpMyAdmin\Template;
use PHPUnit\Framework\TestCase;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;

require_once ROOT_PATH . 'libraries/config.default.php';

Expand All @@ -33,9 +30,9 @@ class ErrorTest extends TestCase
*
* @return void
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function testDisplaySimple(): void
{
Expand All @@ -61,9 +58,9 @@ public function testDisplaySimple(): void
*
* @return void
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function testDisplayToSanitize(): void
{
Expand Down
Loading

0 comments on commit 289fbc1

Please sign in to comment.