diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2019-08-21 06:07:00 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2019-08-21 06:11:04 +0300 |
commit | 632a774de2856f3c1d0531b953706524fab0b435 (patch) | |
tree | f0b7b575c1f595ac7c14870687aeac0727ac09f7 | |
parent | 2ca7148f6a39d72bd1b011b4697d5cebb64836b7 (diff) |
Use the router for transformation_wrapper.php
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r-- | index.php | 3 | ||||
-rw-r--r-- | libraries/classes/Core.php | 3 | ||||
-rw-r--r-- | libraries/classes/Display/Results.php | 1 | ||||
-rw-r--r-- | libraries/classes/InsertEdit.php | 5 | ||||
-rw-r--r-- | libraries/classes/Plugins/Transformations/Abs/DownloadTransformationsPlugin.php | 20 | ||||
-rw-r--r-- | libraries/classes/Plugins/Transformations/Abs/ImageLinkTransformationsPlugin.php | 9 | ||||
-rw-r--r-- | libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php | 3 | ||||
-rw-r--r-- | libraries/classes/Plugins/Transformations/Abs/InlineTransformationsPlugin.php | 17 | ||||
-rw-r--r-- | libraries/classes/Plugins/TransformationsPlugin.php | 2 | ||||
-rw-r--r-- | libraries/config.default.php | 1 | ||||
-rw-r--r-- | libraries/entry_points/transformation/wrapper.php (renamed from transformation_wrapper.php) | 6 | ||||
-rw-r--r-- | test/classes/CoreTest.php | 3 | ||||
-rw-r--r-- | test/classes/Plugins/Transformations/TransformationPluginsTest.php | 33 |
13 files changed, 60 insertions, 46 deletions
@@ -269,6 +269,9 @@ if (isset($_GET['route']) || isset($_POST['route'])) { $routes->addRoute(['GET', 'POST'], '/overview', function () { require_once ROOT_PATH . 'libraries/entry_points/transformation/overview.php'; }); + $routes->addRoute(['GET', 'POST'], '/wrapper', function () { + require_once ROOT_PATH . 'libraries/entry_points/transformation/wrapper.php'; + }); }); $routes->addRoute(['GET', 'POST'], '/user_password', function () { require_once ROOT_PATH . 'libraries/entry_points/user_password.php'; diff --git a/libraries/classes/Core.php b/libraries/classes/Core.php index 475dd8bd59..a46f5af080 100644 --- a/libraries/classes/Core.php +++ b/libraries/classes/Core.php @@ -27,9 +27,6 @@ class Core */ public static $goto_whitelist = [ 'index.php', - 'pdf_pages.php', - 'pdf_schema.php', - 'transformation_wrapper.php', ]; /** diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index 35272186d2..d65241200d 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -2932,6 +2932,7 @@ class Results } $transform_options['wrapper_link'] = Url::getCommon($_url_params); + $transform_options['wrapper_params'] = $_url_params; $display_params = $this->__get('display_params'); diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 4a048aaa16..92040cdcfa 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -2541,6 +2541,7 @@ class InsertEdit : '' ); $transform_options['wrapper_link'] = Url::getCommon($_url_params); + $transform_options['wrapper_params'] = $_url_params; $class_name = $this->transformations->getClassName($include_file); if (class_exists($class_name)) { /** @var TransformationsPlugin $transformation_plugin */ @@ -3334,8 +3335,8 @@ class InsertEdit 'transform_key' => $column['Field'], 'where_clause' => $where_clause, ]; - $transformation_options['wrapper_link'] - = Url::getCommon($_url_params); + $transformation_options['wrapper_link'] = Url::getCommon($_url_params); + $transformation_options['wrapper_params'] = $_url_params; $current_value = ''; if (isset($current_row[$column['Field']])) { $current_value = $current_row[$column['Field']]; diff --git a/libraries/classes/Plugins/Transformations/Abs/DownloadTransformationsPlugin.php b/libraries/classes/Plugins/Transformations/Abs/DownloadTransformationsPlugin.php index d6c21d6054..d8805167dd 100644 --- a/libraries/classes/Plugins/Transformations/Abs/DownloadTransformationsPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/DownloadTransformationsPlugin.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Plugins\Transformations\Abs; use PhpMyAdmin\Plugins\TransformationsPlugin; +use PhpMyAdmin\Url; use stdClass; /** @@ -68,16 +69,19 @@ abstract class DownloadTransformationsPlugin extends TransformationsPlugin } } - return sprintf( - '<a href="transformation_wrapper.php%s&ct=application' - . '/octet-stream&cn=%s" title="%s" class="disableAjax">%s</a>', - $options['wrapper_link'], - htmlspecialchars(urlencode($cn)), - htmlspecialchars($cn), - htmlspecialchars($cn) + $link = '<a href="' . Url::getFromRoute( + '/transformation/wrapper', + array_merge($options['wrapper_params'], [ + 'ct' => 'application/octet-stream', + 'cn' => $cn, + ]) ); - } + $link .= '" title="' . htmlspecialchars($cn); + $link .= '" class="disableAjax">' . htmlspecialchars($cn); + $link .= '</a>'; + return $link; + } /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ diff --git a/libraries/classes/Plugins/Transformations/Abs/ImageLinkTransformationsPlugin.php b/libraries/classes/Plugins/Transformations/Abs/ImageLinkTransformationsPlugin.php index efcfdc50db..b1d7329e79 100644 --- a/libraries/classes/Plugins/Transformations/Abs/ImageLinkTransformationsPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/ImageLinkTransformationsPlugin.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Plugins\Transformations\Abs; use PhpMyAdmin\Plugins\TransformationsPlugin; +use PhpMyAdmin\Url; use stdClass; /** @@ -45,8 +46,12 @@ abstract class ImageLinkTransformationsPlugin extends TransformationsPlugin { // must disable the page loader, see // https://wiki.phpmyadmin.net/pma/Page_loader#Bypassing_the_page_loader - return '<a class="disableAjax" target="_blank" rel="noopener noreferrer" href="transformation_wrapper.php' - . $options['wrapper_link'] . '" alt="[' . htmlspecialchars($buffer) . ']">[BLOB]</a>'; + $link = '<a class="disableAjax" target="_blank" rel="noopener noreferrer" href="'; + $link .= Url::getFromRoute('/transformation/wrapper', $options['wrapper_params']); + $link .= '" alt="[' . htmlspecialchars($buffer); + $link .= ']">[BLOB]</a>'; + + return $link; } /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ diff --git a/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php b/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php index 0e6c0fd100..1a6c7554fc 100644 --- a/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Plugins\Transformations\Abs; use PhpMyAdmin\Plugins\IOTransformationsPlugin; +use PhpMyAdmin\Url; use stdClass; /** @@ -82,7 +83,7 @@ abstract class ImageUploadTransformationsPlugin extends IOTransformationsPlugin . '" value="' . bin2hex($value) . '">'; $html .= '<input type="hidden" name="fields' . $column_name_appendix . '" value="' . bin2hex($value) . '">'; - $src = 'transformation_wrapper.php' . $options['wrapper_link']; + $src = Url::getFromRoute('/transformation/wrapper', $options['wrapper_params']); } $html .= '<img src="' . $src . '" width="' . (isset($options[0]) ? intval($options[0]) : '100') . '" height="' diff --git a/libraries/classes/Plugins/Transformations/Abs/InlineTransformationsPlugin.php b/libraries/classes/Plugins/Transformations/Abs/InlineTransformationsPlugin.php index 102dce925a..2569e8dca8 100644 --- a/libraries/classes/Plugins/Transformations/Abs/InlineTransformationsPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/InlineTransformationsPlugin.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Plugins\Transformations\Abs; use PhpMyAdmin\Plugins\TransformationsPlugin; +use PhpMyAdmin\Url; use stdClass; /** @@ -48,16 +49,16 @@ abstract class InlineTransformationsPlugin extends TransformationsPlugin $options = $this->getOptions($options, $cfg['DefaultTransformations']['Inline']); if (PMA_IS_GD2) { - return '<a href="transformation_wrapper.php' - . $options['wrapper_link'] - . '" rel="noopener noreferrer" target="_blank"><img src="transformation_wrapper.php' - . $options['wrapper_link'] . '&resize=jpeg&newWidth=' - . intval($options[0]) . '&newHeight=' - . intval($options[1]) + return '<a href="' . Url::getFromRoute('/transformation/wrapper', $options['wrapper_params']) + . '" rel="noopener noreferrer" target="_blank"><img src="' + . Url::getFromRoute('/transformation/wrapper', array_merge($options['wrapper_params'], [ + 'resize' => 'jpeg', + 'newWidth' => (int) $options[0], + 'newHeight' => (int) $options[1], + ])) . '" alt="[' . htmlspecialchars($buffer) . ']" border="0"></a>'; } else { - return '<img src="transformation_wrapper.php' - . $options['wrapper_link'] + return '<img src="' . Url::getFromRoute('/transformation/wrapper', $options['wrapper_params']) . '" alt="[' . htmlspecialchars($buffer) . ']" width="320" height="240">'; } } diff --git a/libraries/classes/Plugins/TransformationsPlugin.php b/libraries/classes/Plugins/TransformationsPlugin.php index 32b1abe8b3..d23f474ce9 100644 --- a/libraries/classes/Plugins/TransformationsPlugin.php +++ b/libraries/classes/Plugins/TransformationsPlugin.php @@ -51,7 +51,7 @@ abstract class TransformationsPlugin implements TransformationsInterface * @param string[] $options List of passed options * @param string[] $defaults List of default values * - * @return string[] List of options possibly filled in by defaults. + * @return array List of options possibly filled in by defaults. */ public function getOptions(array $options, array $defaults) { diff --git a/libraries/config.default.php b/libraries/config.default.php index 12357583f6..d071adc619 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -3259,6 +3259,7 @@ $cfg['DefaultTransformations']['Inline'] = [ 100, ]; $cfg['DefaultTransformations']['Inline']['wrapper_link'] = null; +$cfg['DefaultTransformations']['Inline']['wrapper_params'] = []; /** * Default transformations for TextImageLink diff --git a/transformation_wrapper.php b/libraries/entry_points/transformation/wrapper.php index ddf4475d53..8279a0d05d 100644 --- a/transformation_wrapper.php +++ b/libraries/entry_points/transformation/wrapper.php @@ -13,16 +13,14 @@ use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Transformations; -if (! defined('ROOT_PATH')) { - define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); +if (! defined('PHPMYADMIN')) { + exit; } global $cn, $containerBuilder, $db, $table, $transform_key; define('IS_TRANSFORMATION_WRAPPER', true); -require_once ROOT_PATH . 'libraries/common.inc.php'; - /** @var Response $response */ $response = $containerBuilder->get(Response::class); diff --git a/test/classes/CoreTest.php b/test/classes/CoreTest.php index 877334e877..848306870e 100644 --- a/test/classes/CoreTest.php +++ b/test/classes/CoreTest.php @@ -24,9 +24,6 @@ class CoreTest extends PmaTestCase { protected $goto_whitelist = [ 'index.php', - 'pdf_pages.php', - 'pdf_schema.php', - 'transformation_wrapper.php', ]; /** diff --git a/test/classes/Plugins/Transformations/TransformationPluginsTest.php b/test/classes/Plugins/Transformations/TransformationPluginsTest.php index 09eee54669..81afd0b678 100644 --- a/test/classes/Plugins/Transformations/TransformationPluginsTest.php +++ b/test/classes/Plugins/Transformations/TransformationPluginsTest.php @@ -132,7 +132,7 @@ class TransformationPluginsTest extends PmaTestCase '<input type="hidden" name="fields_prev2ndtest" ' . 'value="736f6d657468696e67"><input type="hidden" ' . 'name="fields2ndtest" value="736f6d657468696e67">' - . '<img src="transformation_wrapper.php?table=a" width="100" ' + . '<img src="index.php?route=/transformation/wrapper&key=value&lang=en" width="100" ' . 'height="100" alt="Image preview here"><br><input type="file" ' . 'name="fields_upload2ndtest" accept="image/*" ' . 'class="image-upload">', @@ -142,6 +142,7 @@ class TransformationPluginsTest extends PmaTestCase '2ndtest', [ 'wrapper_link' => '?table=a', + 'wrapper_params' => ['key' => 'value'], ], 'something', 'ltr', @@ -785,10 +786,11 @@ class TransformationPluginsTest extends PmaTestCase [ 0 => "filename", 'wrapper_link' => 'PMA_wrapper_link', + 'wrapper_params' => ['key' => 'value'], ], ], - '<a href="transformation_wrapper.phpPMA_wrapper_link' - . '&ct=application/octet-stream&cn=filename" ' + '<a href="index.php?route=/transformation/wrapper&key=value' + . '&ct=application%2Foctet-stream&cn=filename&lang=en" ' . 'title="filename" class="disableAjax">filename</a>', ], [ @@ -799,10 +801,11 @@ class TransformationPluginsTest extends PmaTestCase 0 => "", 1 => 'cloumn', 'wrapper_link' => 'PMA_wrapper_link', + 'wrapper_params' => ['key' => 'value'], ], ], - '<a href="transformation_wrapper.phpPMA_wrapper_link&' - . 'ct=application/octet-stream&cn=binary_file.dat" ' + '<a href="index.php?route=/transformation/wrapper&key=value' + . '&ct=application%2Foctet-stream&cn=binary_file.dat&lang=en" ' . 'title="binary_file.dat" class="disableAjax">binary_file.dat</a>', ], [ @@ -837,10 +840,11 @@ class TransformationPluginsTest extends PmaTestCase 0 => "./image/", 1 => "200", "wrapper_link" => "PMA_wrapper_link", + 'wrapper_params' => ['key' => 'value'], ], ], '<a class="disableAjax" target="_blank" rel="noopener noreferrer"' - . ' href="transformation_wrapper.phpPMA_wrapper_link"' + . ' href="index.php?route=/transformation/wrapper&key=value&lang=en"' . ' alt="[PMA_IMAGE_LINK]">[BLOB]</a>', ], [ @@ -1056,12 +1060,13 @@ class TransformationPluginsTest extends PmaTestCase 0 => "./image/", 1 => "200", "wrapper_link" => "PMA_wrapper_link", + 'wrapper_params' => ['key' => 'value'], ], ], - '<a href="transformation_wrapper.phpPMA_wrapper_link" ' - . 'rel="noopener noreferrer" target="_blank"><img src="transformation_wrapper.php' - . 'PMA_wrapper_link&resize=jpeg&newWidth=0&' - . 'newHeight=200" alt="[PMA_JPEG_Inline]" border="0"></a>', + '<a href="index.php?route=/transformation/wrapper&key=value&lang=en" ' + . 'rel="noopener noreferrer" target="_blank"><img src="index.php?route=/transformation/wrapper' + . '&key=value&resize=jpeg&newWidth=0&' + . 'newHeight=200&lang=en" alt="[PMA_JPEG_Inline]" border="0"></a>', ]; $result[] = [ new Image_PNG_Inline(), @@ -1071,12 +1076,12 @@ class TransformationPluginsTest extends PmaTestCase 0 => "./image/", 1 => "200", "wrapper_link" => "PMA_wrapper_link", + 'wrapper_params' => ['key' => 'value'], ], ], - '<a href="transformation_wrapper.phpPMA_wrapper_link"' - . ' rel="noopener noreferrer" target="_blank"><img src="transformation_wrapper.php' - . 'PMA_wrapper_link&' - . 'resize=jpeg&newWidth=0&newHeight=200" ' + '<a href="index.php?route=/transformation/wrapper&key=value&lang=en"' + . ' rel="noopener noreferrer" target="_blank"><img src="index.php?route=/transformation/wrapper' + . '&key=value&resize=jpeg&newWidth=0&newHeight=200&lang=en" ' . 'alt="[PMA_PNG_Inline]" border="0"></a>', ]; } |