diff --git a/composer.json b/composer.json index f7d2688bd5..6716ab9842 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "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", @@ -57,7 +57,7 @@ "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": { diff --git a/libraries/classes/Controllers/Server/ReplicationController.php b/libraries/classes/Controllers/Server/ReplicationController.php index dd48411aa0..635f9c4993 100644 --- a/libraries/classes/Controllers/Server/ReplicationController.php +++ b/libraries/classes/Controllers/Server/ReplicationController.php @@ -11,9 +11,6 @@ namespace PhpMyAdmin\Controllers\Server; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\ReplicationGui; use Throwable; -use Twig_Error_Loader; -use Twig_Error_Runtime; -use Twig_Error_Syntax; /** * Server replications @@ -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 { diff --git a/libraries/classes/Controllers/Server/Status/StatusController.php b/libraries/classes/Controllers/Server/Status/StatusController.php index 53d78a32dc..78cdde2e2b 100644 --- a/libraries/classes/Controllers/Server/Status/StatusController.php +++ b/libraries/classes/Controllers/Server/Status/StatusController.php @@ -12,9 +12,6 @@ namespace PhpMyAdmin\Controllers\Server\Status; use PhpMyAdmin\ReplicationGui; use PhpMyAdmin\Util; use Throwable; -use Twig_Error_Loader; -use Twig_Error_Runtime; -use Twig_Error_Syntax; /** * Class StatusController @@ -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 { diff --git a/libraries/classes/Display/Error.php b/libraries/classes/Display/Error.php index a60153285d..4e2a01c042 100644 --- a/libraries/classes/Display/Error.php +++ b/libraries/classes/Display/Error.php @@ -12,9 +12,6 @@ namespace PhpMyAdmin\Display; use PhpMyAdmin\Sanitize; use PhpMyAdmin\Template; use Throwable; -use Twig_Error_Loader; -use Twig_Error_Runtime; -use Twig_Error_Syntax; /** * Displays Error @@ -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, diff --git a/libraries/classes/Display/Export.php b/libraries/classes/Display/Export.php index db02a5e7c8..df82615aaa 100644 --- a/libraries/classes/Display/Export.php +++ b/libraries/classes/Display/Export.php @@ -21,9 +21,6 @@ use PhpMyAdmin\Table; use PhpMyAdmin\Template; use PhpMyAdmin\Util; use Throwable; -use Twig_Error_Loader; -use Twig_Error_Runtime; -use Twig_Error_Syntax; /** * PhpMyAdmin\Display\Export class @@ -576,9 +573,9 @@ class Export * * @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() { diff --git a/libraries/classes/Plugins/TwoFactor/Key.php b/libraries/classes/Plugins/TwoFactor/Key.php index cbb118c03f..1f1459b424 100644 --- a/libraries/classes/Plugins/TwoFactor/Key.php +++ b/libraries/classes/Plugins/TwoFactor/Key.php @@ -17,9 +17,6 @@ use Samyoul\U2F\U2FServer\U2FException; 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 @@ -137,9 +134,9 @@ class Key extends TwoFactorPlugin * @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() { diff --git a/libraries/classes/Template.php b/libraries/classes/Template.php index 9b26a9eca3..2a9101f2ac 100644 --- a/libraries/classes/Template.php +++ b/libraries/classes/Template.php @@ -25,14 +25,8 @@ use PhpMyAdmin\Twig\UtilExtension; 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 @@ -95,12 +89,12 @@ class Template * * @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'); @@ -131,9 +125,9 @@ class Template * * @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 { diff --git a/libraries/classes/Twig/I18n/TokenParserTrans.php b/libraries/classes/Twig/I18n/TokenParserTrans.php index adcf8c86e5..81d2a63cb5 100644 --- a/libraries/classes/Twig/I18n/TokenParserTrans.php +++ b/libraries/classes/Twig/I18n/TokenParserTrans.php @@ -11,7 +11,6 @@ namespace PhpMyAdmin\Twig\I18n; use PhpMyAdmin\Twig\Extensions\TokenParser\TransTokenParser; use Twig\Token; -use Twig_Error_Syntax; /** * Class TokenParserTrans @@ -27,7 +26,7 @@ class TokenParserTrans extends TransTokenParser * * @return NodeTrans * - * @throws Twig_Error_Syntax + * @throws \Twig\Error\SyntaxError */ public function parse(Token $token) { diff --git a/libraries/classes/UserPreferencesHeader.php b/libraries/classes/UserPreferencesHeader.php index cecbb05cdc..4d6b26f189 100644 --- a/libraries/classes/UserPreferencesHeader.php +++ b/libraries/classes/UserPreferencesHeader.php @@ -11,9 +11,6 @@ namespace PhpMyAdmin; 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 @@ -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 { @@ -46,9 +43,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 */ protected static function displayTabs(Template $template): string { diff --git a/scripts/generate-twig-cache b/scripts/generate-twig-cache index c343c4511f..ccacb93ebd 100644 --- a/scripts/generate-twig-cache +++ b/scripts/generate-twig-cache @@ -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)); diff --git a/templates/columns_definitions/column_virtuality.twig b/templates/columns_definitions/column_virtuality.twig index 96f020e136..d53f5d55e8 100644 --- a/templates/columns_definitions/column_virtuality.twig +++ b/templates/columns_definitions/column_virtuality.twig @@ -15,13 +15,11 @@ {% if char_editing == 'textarea' %} - {% apply spaceless %} - {% endapply %} {% else %} - {% apply spaceless %} - {% endapply %} var designerConfig = {{ designer_config|raw }}; -{% endapply %} {# side menu #} {% if not has_query %} diff --git a/templates/database/multi_table_query/form.twig b/templates/database/multi_table_query/form.twig index 068ceda20f..04d7b7a5d7 100644 --- a/templates/database/multi_table_query/form.twig +++ b/templates/database/multi_table_query/form.twig @@ -163,15 +163,13 @@
- {% apply spaceless %} - - {% endapply %} + {# Keep the block without a space between the open and close tag #} +
diff --git a/templates/display/export/options_rows.twig b/templates/display/export/options_rows.twig index 1d4f866a02..041740454f 100644 --- a/templates/display/export/options_rows.twig +++ b/templates/display/export/options_rows.twig @@ -9,15 +9,14 @@
  • + {# 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()">
  • diff --git a/templates/display/import/javascript.twig b/templates/display/import/javascript.twig index ec91e3c362..5802c35121 100644 --- a/templates/display/import/javascript.twig +++ b/templates/display/import/javascript.twig @@ -18,7 +18,6 @@ $( function() { {% set import_url = get_common_raw({'import_status': 1}, '&') %} {% set upload_html %} - {% apply spaceless %}
    @@ -31,7 +30,6 @@ $( function() {
    - {% endapply %} {% endset %} {# Start output #} @@ -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; } diff --git a/test/classes/Display/ErrorTest.php b/test/classes/Display/ErrorTest.php index 4c76aa5bc6..aa1b0f9731 100644 --- a/test/classes/Display/ErrorTest.php +++ b/test/classes/Display/ErrorTest.php @@ -13,9 +13,6 @@ use PhpMyAdmin\Display\Error; 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'; @@ -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 { @@ -61,9 +58,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 testDisplayToSanitize(): void { diff --git a/test/classes/UserPreferencesHeaderTest.php b/test/classes/UserPreferencesHeaderTest.php index f079aa0d8a..d096a4847c 100644 --- a/test/classes/UserPreferencesHeaderTest.php +++ b/test/classes/UserPreferencesHeaderTest.php @@ -17,9 +17,6 @@ use PhpMyAdmin\Tests\PmaTestCase; use PhpMyAdmin\UserPreferences; use PhpMyAdmin\UserPreferencesHeader; use Throwable; -use Twig_Error_Loader; -use Twig_Error_Runtime; -use Twig_Error_Syntax; /** * tests for methods under PhpMyAdmin\UserPreferencesHeader class @@ -48,9 +45,9 @@ class UserPreferencesHeaderTest extends PmaTestCase * * @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 testGetContentWithSelectedTab(): void { @@ -83,9 +80,9 @@ class UserPreferencesHeaderTest extends PmaTestCase * * @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 testGetContentAfterSave(): void { @@ -108,9 +105,9 @@ class UserPreferencesHeaderTest extends PmaTestCase * * @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 testGetContentWithSessionStorage(): void {