New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Util::linkOrButton #13649

Closed
nijel opened this Issue Sep 5, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@nijel
Member

nijel commented Sep 5, 2017

While looking at code blocks in common.inc.php (see #11731), I've noticed code handling subforms (see below) and that brought my attention to Util::linkOrButton. I think this deserves serious cleanups:

  • The whole forms stuff in linkOrButton would be better and simpler handled client side - the server would generate something like <a href="target.php" data-post="post-data">...</a> and client would submit the form with these data, no need to deal with nested forms or other magic which has to be implemented on both sides
  • Overriding tag_params parameter seems quite fragile, probably separate parameter should be used for each purpose
  • There are more parts of the code which I found questionable (eg. "Add text if not already added"), but I did not really investigate if those are needed

Code for subforms:

/**
* Subforms - some functions need to be called by form, cause of the limited URL
* length, but if this functions inside another form you cannot just open a new
* form - so phpMyAdmin uses 'arrays' inside this form
*
* <code>
* <form ...>
* ... main form elements ...
* <input type="hidden" name="subform[action1][id]" value="1" />
* ... other subform data ...
* <input type="submit" name="usesubform[action1]" value="do action1" />
* ... other subforms ...
* <input type="hidden" name="subform[actionX][id]" value="X" />
* ... other subform data ...
* <input type="submit" name="usesubform[actionX]" value="do actionX" />
* ... main form elements ...
* <input type="submit" name="main_action" value="submit form" />
* </form>
* </code>
*
* so we now check if a subform is submitted
*/
$__redirect = null;
if (isset($_POST['usesubform']) && ! defined('PMA_MINIMUM_COMMON')) {
// if a subform is present and should be used
// the rest of the form is deprecated
$subform_id = key($_POST['usesubform']);
$subform = $_POST['subform'][$subform_id];
$_POST = $subform;
$_REQUEST = $subform;
/**
* some subforms need another page than the main form, so we will just
* include this page at the end of this script - we use $__redirect to
* track this
*/
if (isset($_POST['redirect'])
&& $_POST['redirect'] != basename($PMA_PHP_SELF)
) {
$__redirect = $_POST['redirect'];
unset($_POST['redirect']);
}
unset($subform_id, $subform);
} else {
// Note: here we overwrite $_REQUEST so that it does not contain cookies,
// because another application for the same domain could have set
// a cookie (with a compatible path) that overrides a variable
// we expect from GET or POST.
// We'll refer to cookies explicitly with the $_COOKIE syntax.
$_REQUEST = array_merge($_GET, $_POST);
}
// end check if a subform is submitted

@nijel nijel self-assigned this Nov 16, 2017

nijel added a commit to nijel/phpmyadmin that referenced this issue Nov 16, 2017

Simplify handling of long URLs in Util::linkOrButton
We no longer create form, but rather rather tag the link to be handled
as POST on the client side.

This way the code is way simpler without need on any special case
handling on server side.

Fixes phpmyadmin#13649

Signed-off-by: Michal Čihař <michal@cihar.com>

@nijel nijel added this to the 4.8.0 milestone Nov 16, 2017

nijel added a commit to nijel/phpmyadmin that referenced this issue Nov 16, 2017

Simplify handling of long URLs in Util::linkOrButton
We no longer create form, but rather rather tag the link to be handled
as POST on the client side.

This way the code is way simpler without need on any special case
handling on server side.

Fixes phpmyadmin#13649

Signed-off-by: Michal Čihař <michal@cihar.com>

nijel added a commit to nijel/phpmyadmin that referenced this issue Nov 16, 2017

Simplify handling of long URLs in Util::linkOrButton
We no longer create form, but rather rather tag the link to be handled
as POST on the client side.

This way the code is way simpler without need on any special case
handling on server side.

Fixes phpmyadmin#13649

Signed-off-by: Michal Čihař <michal@cihar.com>

nijel added a commit to nijel/phpmyadmin that referenced this issue Nov 16, 2017

Simplify handling of long URLs in Util::linkOrButton
We no longer create form, but rather rather tag the link to be handled
as POST on the client side.

This way the code is way simpler without need on any special case
handling on server side.

Fixes phpmyadmin#13649

Signed-off-by: Michal Čihař <michal@cihar.com>

@nijel nijel closed this in #13817 Nov 16, 2017

mauriciofauth added a commit to mauriciofauth/phpmyadmin that referenced this issue Feb 22, 2018

Simplify handling of long URLs in Util::linkOrButton
We no longer create form, but rather rather tag the link to be handled
as POST on the client side.

This way the code is way simpler without need on any special case
handling on server side.

Fixes phpmyadmin#13649

(cherry-picking commit 3b9fb2b)

Signed-off-by: Michal Čihař <michal@cihar.com>

mauriciofauth added a commit to mauriciofauth/phpmyadmin that referenced this issue Feb 22, 2018

Simplify handling of long URLs in Util::linkOrButton
We no longer create form, but rather rather tag the link to be handled
as POST on the client side.

This way the code is way simpler without need on any special case
handling on server side.

Fixes phpmyadmin#13649

(cherry-picking commit 3b9fb2b)

Signed-off-by: Michal Čihař <michal@cihar.com>

mauriciofauth added a commit to mauriciofauth/phpmyadmin that referenced this issue Feb 22, 2018

Simplify handling of long URLs in Util::linkOrButton
We no longer create form, but rather rather tag the link to be handled
as POST on the client side.

This way the code is way simpler without need on any special case
handling on server side.

Fixes phpmyadmin#13649

Signed-off-by: Michal Čihař <michal@cihar.com>
(cherry picked from commit 3b9fb2b)
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment