From 04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 9 Jan 2020 10:55:03 +0100 Subject: phpmyadmin working --- .../libraries/classes/Twig/CoreExtension.php | 41 ++++ .../libraries/classes/Twig/I18n/NodeTrans.php | 171 +++++++++++++++++ .../classes/Twig/I18n/TokenParserTrans.php | 85 +++++++++ .../libraries/classes/Twig/I18nExtension.php | 45 +++++ .../libraries/classes/Twig/MessageExtension.php | 54 ++++++ .../libraries/classes/Twig/PluginsExtension.php | 52 +++++ .../libraries/classes/Twig/RelationExtension.php | 71 +++++++ .../libraries/classes/Twig/SanitizeExtension.php | 64 +++++++ .../classes/Twig/ServerPrivilegesExtension.php | 51 +++++ .../classes/Twig/StorageEngineExtension.php | 37 ++++ .../libraries/classes/Twig/TableExtension.php | 36 ++++ .../libraries/classes/Twig/TrackerExtension.php | 36 ++++ .../classes/Twig/TransformationsExtension.php | 48 +++++ .../libraries/classes/Twig/UrlExtension.php | 52 +++++ .../libraries/classes/Twig/UtilExtension.php | 212 +++++++++++++++++++++ 15 files changed, 1055 insertions(+) create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/CoreExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/I18n/NodeTrans.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/I18n/TokenParserTrans.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/I18nExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/MessageExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/PluginsExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/RelationExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/SanitizeExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/ServerPrivilegesExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/StorageEngineExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/TableExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/TrackerExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/TransformationsExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/UrlExtension.php create mode 100644 srcs/phpmyadmin/libraries/classes/Twig/UtilExtension.php (limited to 'srcs/phpmyadmin/libraries/classes/Twig') diff --git a/srcs/phpmyadmin/libraries/classes/Twig/CoreExtension.php b/srcs/phpmyadmin/libraries/classes/Twig/CoreExtension.php new file mode 100644 index 0000000..e6e2142 --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/CoreExtension.php @@ -0,0 +1,41 @@ + ['html']] + ), + new TwigFilter( + 'link', + 'PhpMyAdmin\Core::linkURL' + ), + ]; + } +} diff --git a/srcs/phpmyadmin/libraries/classes/Twig/I18n/NodeTrans.php b/srcs/phpmyadmin/libraries/classes/Twig/I18n/NodeTrans.php new file mode 100644 index 0000000..6fae7aa --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/I18n/NodeTrans.php @@ -0,0 +1,171 @@ +node). + * The attributes are automatically made available as array items ($this['name']). + * + * @param Node $body Body of node trans + * @param Node $plural Node plural + * @param AbstractExpression $count Node count + * @param Node $context Node context + * @param Node $notes Node notes + * @param int $lineno The line number + * @param string $tag The tag name associated with the Node + */ + public function __construct( + Node $body, + Node $plural = null, + AbstractExpression $count = null, + Node $context = null, + Node $notes = null, + $lineno, + $tag = null + ) { + $nodes = ['body' => $body]; + if (null !== $count) { + $nodes['count'] = $count; + } + if (null !== $plural) { + $nodes['plural'] = $plural; + } + if (null !== $context) { + $nodes['context'] = $context; + } + if (null !== $notes) { + $nodes['notes'] = $notes; + } + + Node::__construct($nodes, [], $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Compiler $compiler Node compiler + * + * @return void + */ + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + + list($msg, $vars) = $this->compileString($this->getNode('body')); + + if ($this->hasNode('plural')) { + list($msg1, $vars1) = $this->compileString($this->getNode('plural')); + + $vars = array_merge($vars, $vars1); + } + + $function = $this->getTransFunction( + $this->hasNode('plural'), + $this->hasNode('context') + ); + + if ($this->hasNode('notes')) { + $message = trim($this->getNode('notes')->getAttribute('data')); + + // line breaks are not allowed cause we want a single line comment + $message = str_replace(["\n", "\r"], ' ', $message); + $compiler->write("// l10n: {$message}\n"); + } + + if ($vars) { + $compiler + ->write('echo strtr(' . $function . '(') + ->subcompile($msg) + ; + + if ($this->hasNode('plural')) { + $compiler + ->raw(', ') + ->subcompile($msg1) + ->raw(', abs(') + ->subcompile($this->hasNode('count') ? $this->getNode('count') : null) + ->raw(')') + ; + } + + $compiler->raw('), array('); + + foreach ($vars as $var) { + if ('count' === $var->getAttribute('name')) { + $compiler + ->string('%count%') + ->raw(' => abs(') + ->subcompile($this->hasNode('count') ? $this->getNode('count') : null) + ->raw('), ') + ; + } else { + $compiler + ->string('%' . $var->getAttribute('name') . '%') + ->raw(' => ') + ->subcompile($var) + ->raw(', ') + ; + } + } + + $compiler->raw("));\n"); + } else { + $compiler->write('echo ' . $function . '('); + + if ($this->hasNode('context')) { + $context = trim($this->getNode('context')->getAttribute('data')); + $compiler->write('"' . $context . '", '); + } + + $compiler->subcompile($msg); + + if ($this->hasNode('plural')) { + $compiler + ->raw(', ') + ->subcompile($msg1) + ->raw(', abs(') + ->subcompile($this->hasNode('count') ? $this->getNode('count') : null) + ->raw(')') + ; + } + + $compiler->raw(");\n"); + } + } + + /** + * @param bool $plural Return plural or singular function to use + * @param bool $hasMsgContext It has message context? + * + * @return string + */ + protected function getTransFunction($plural, $hasMsgContext = false) + { + if ($hasMsgContext) { + return $plural ? '_ngettext' : '_pgettext'; + } + + return $plural ? '_ngettext' : '_gettext'; + } +} diff --git a/srcs/phpmyadmin/libraries/classes/Twig/I18n/TokenParserTrans.php b/srcs/phpmyadmin/libraries/classes/Twig/I18n/TokenParserTrans.php new file mode 100644 index 0000000..25aade0 --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/I18n/TokenParserTrans.php @@ -0,0 +1,85 @@ +getLine(); + $stream = $this->parser->getStream(); + $count = null; + $plural = null; + $notes = null; + $context = null; + + if (! $stream->test(Token::BLOCK_END_TYPE)) { + $body = $this->parser->getExpressionParser()->parseExpression(); + } else { + $stream->expect(Token::BLOCK_END_TYPE); + $body = $this->parser->subparse([$this, 'decideForFork']); + $next = $stream->next()->getValue(); + + if ('plural' === $next) { + $count = $this->parser->getExpressionParser()->parseExpression(); + $stream->expect(Token::BLOCK_END_TYPE); + $plural = $this->parser->subparse([$this, 'decideForFork']); + + if ('notes' === $stream->next()->getValue()) { + $stream->expect(Token::BLOCK_END_TYPE); + $notes = $this->parser->subparse([$this, 'decideForEnd'], true); + } + } elseif ('context' === $next) { + $stream->expect(Token::BLOCK_END_TYPE); + $context = $this->parser->subparse([$this, 'decideForEnd'], true); + } elseif ('notes' === $next) { + $stream->expect(Token::BLOCK_END_TYPE); + $notes = $this->parser->subparse([$this, 'decideForEnd'], true); + } + } + + $stream->expect(Token::BLOCK_END_TYPE); + + $this->checkTransString($body, $lineno); + + return new NodeTrans($body, $plural, $count, $context, $notes, $lineno, $this->getTag()); + } + + /** + * Tests the current token for a type. + * + * @param Token $token Twig token to test + * + * @return bool + */ + public function decideForFork(Token $token) + { + return $token->test(['plural', 'context', 'notes', 'endtrans']); + } +} diff --git a/srcs/phpmyadmin/libraries/classes/Twig/I18nExtension.php b/srcs/phpmyadmin/libraries/classes/Twig/I18nExtension.php new file mode 100644 index 0000000..4d0c14f --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/I18nExtension.php @@ -0,0 +1,45 @@ +getDisplay(); + }, + ['is_safe' => ['html']] + ), + new TwigFilter( + 'error', + function (string $string) { + return Message::error($string)->getDisplay(); + }, + ['is_safe' => ['html']] + ), + new TwigFilter( + 'raw_success', + function (string $string) { + return Message::rawSuccess($string)->getDisplay(); + }, + ['is_safe' => ['html']] + ), + ]; + } +} diff --git a/srcs/phpmyadmin/libraries/classes/Twig/PluginsExtension.php b/srcs/phpmyadmin/libraries/classes/Twig/PluginsExtension.php new file mode 100644 index 0000000..1706a62 --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/PluginsExtension.php @@ -0,0 +1,52 @@ + ['html']] + ), + new TwigFunction( + 'get_choice', + 'PhpMyAdmin\Plugins::getChoice', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_default_plugin', + 'PhpMyAdmin\Plugins::getDefault', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_options', + 'PhpMyAdmin\Plugins::getOptions', + ['is_safe' => ['html']] + ), + ]; + } +} diff --git a/srcs/phpmyadmin/libraries/classes/Twig/RelationExtension.php b/srcs/phpmyadmin/libraries/classes/Twig/RelationExtension.php new file mode 100644 index 0000000..6aca5d3 --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/RelationExtension.php @@ -0,0 +1,71 @@ + ['html']] + ), + new TwigFunction( + 'get_display_field', + [ + $relation, + 'getDisplayField', + ], + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_foreign_data', + [ + $relation, + 'getForeignData', + ] + ), + new TwigFunction( + 'get_tables', + [ + $relation, + 'getTables', + ] + ), + new TwigFunction( + 'search_column_in_foreigners', + [ + $relation, + 'searchColumnInForeigners', + ] + ), + ]; + } +} diff --git a/srcs/phpmyadmin/libraries/classes/Twig/SanitizeExtension.php b/srcs/phpmyadmin/libraries/classes/Twig/SanitizeExtension.php new file mode 100644 index 0000000..0256109 --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/SanitizeExtension.php @@ -0,0 +1,64 @@ + ['html']] + ), + new TwigFilter( + 'js_format', + 'PhpMyAdmin\Sanitize::jsFormat', + ['is_safe' => ['html']] + ), + new TwigFilter( + 'sanitize', + 'PhpMyAdmin\Sanitize::sanitizeMessage', + ['is_safe' => ['html']] + ), + ]; + } + + /** + * Returns a list of functions to add to the existing list. + * + * @return TwigFunction[] + */ + public function getFunctions() + { + return [ + new TwigFunction( + 'get_js_value', + 'PhpMyAdmin\Sanitize::getJsValue', + ['is_safe' => ['html']] + ), + ]; + } +} diff --git a/srcs/phpmyadmin/libraries/classes/Twig/ServerPrivilegesExtension.php b/srcs/phpmyadmin/libraries/classes/Twig/ServerPrivilegesExtension.php new file mode 100644 index 0000000..0a1363c --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/ServerPrivilegesExtension.php @@ -0,0 +1,51 @@ + ['html']] + ), + ]; + } +} diff --git a/srcs/phpmyadmin/libraries/classes/Twig/StorageEngineExtension.php b/srcs/phpmyadmin/libraries/classes/Twig/StorageEngineExtension.php new file mode 100644 index 0000000..34b87c1 --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/StorageEngineExtension.php @@ -0,0 +1,37 @@ + ['html']] + ), + ]; + } +} diff --git a/srcs/phpmyadmin/libraries/classes/Twig/TableExtension.php b/srcs/phpmyadmin/libraries/classes/Twig/TableExtension.php new file mode 100644 index 0000000..1dc4ef1 --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/TableExtension.php @@ -0,0 +1,36 @@ + ['html']] + ), + new TwigFunction( + 'get_hidden_fields', + 'PhpMyAdmin\Url::getHiddenFields', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_common', + 'PhpMyAdmin\Url::getCommon', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_common_raw', + 'PhpMyAdmin\Url::getCommonRaw', + ['is_safe' => ['html']] + ), + ]; + } +} diff --git a/srcs/phpmyadmin/libraries/classes/Twig/UtilExtension.php b/srcs/phpmyadmin/libraries/classes/Twig/UtilExtension.php new file mode 100644 index 0000000..809b07e --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Twig/UtilExtension.php @@ -0,0 +1,212 @@ + ['html']] + ), + new TwigFunction( + 'extract_column_spec', + 'PhpMyAdmin\Util::extractColumnSpec' + ), + new TwigFunction( + 'format_byte_down', + 'PhpMyAdmin\Util::formatByteDown' + ), + new TwigFunction( + 'format_number', + 'PhpMyAdmin\Util::formatNumber' + ), + new TwigFunction( + 'format_sql', + 'PhpMyAdmin\Util::formatSql', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_button_or_image', + 'PhpMyAdmin\Util::getButtonOrImage', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_docu_link', + 'PhpMyAdmin\Util::getDocuLink', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_list_navigator', + 'PhpMyAdmin\Util::getListNavigator', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'show_docu', + 'PhpMyAdmin\Util::showDocu', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_dropdown', + 'PhpMyAdmin\Util::getDropdown', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_fk_checkbox', + 'PhpMyAdmin\Util::getFKCheckbox', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_gis_datatypes', + 'PhpMyAdmin\Util::getGISDatatypes' + ), + new TwigFunction( + 'get_gis_functions', + 'PhpMyAdmin\Util::getGISFunctions' + ), + new TwigFunction( + 'get_html_tab', + 'PhpMyAdmin\Util::getHtmlTab', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_icon', + 'PhpMyAdmin\Util::getIcon', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_image', + 'PhpMyAdmin\Util::getImage', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_radio_fields', + 'PhpMyAdmin\Util::getRadioFields', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_select_upload_file_block', + 'PhpMyAdmin\Util::getSelectUploadFileBlock', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_script_name_for_option', + 'PhpMyAdmin\Util::getScriptNameForOption', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_start_and_number_of_rows_panel', + 'PhpMyAdmin\Util::getStartAndNumberOfRowsPanel', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_supported_datatypes', + 'PhpMyAdmin\Util::getSupportedDatatypes', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'is_foreign_key_supported', + 'PhpMyAdmin\Util::isForeignKeySupported' + ), + new TwigFunction( + 'link_or_button', + 'PhpMyAdmin\Util::linkOrButton', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'link_to_var_documentation', + 'PhpMyAdmin\Util::linkToVarDocumentation', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'localised_date', + 'PhpMyAdmin\Util::localisedDate' + ), + new TwigFunction( + 'show_hint', + 'PhpMyAdmin\Util::showHint', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'show_icons', + 'PhpMyAdmin\Util::showIcons' + ), + new TwigFunction( + 'show_mysql_docu', + 'PhpMyAdmin\Util::showMySQLDocu', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'get_mysql_docu_url', + 'PhpMyAdmin\Util::getMySQLDocuURL', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'show_php_docu', + 'PhpMyAdmin\Util::showPHPDocu', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'sortable_table_header', + 'PhpMyAdmin\Util::sortableTableHeader', + ['is_safe' => ['html']] + ), + new TwigFunction( + 'timespan_format', + 'PhpMyAdmin\Util::timespanFormat' + ), + new TwigFunction( + 'generate_hidden_max_file_size', + 'PhpMyAdmin\Util::generateHiddenMaxFileSize', + ['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' + ), + ]; + } +} -- cgit