Skip to content

Commit 5b428f6

Browse files
Merge pull request #18603 from MauricioFauth/response-redirect
Move Core::sendHeaderLocation() to ResponseRenderer::redirect()
2 parents 2c9f283 + a520e23 commit 5b428f6

24 files changed

Lines changed: 66 additions & 259 deletions

libraries/classes/Config.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ public function loadAndCheck(string|null $source = null): void
131131
public function checkSystem(): void
132132
{
133133
$this->checkWebServerOs();
134-
$this->checkWebServer();
135134
$this->checkGd2();
136135
$this->checkClient();
137136
$this->checkUpload();
@@ -284,26 +283,6 @@ public function checkGd2(): void
284283
$this->set('PMA_IS_GD2', 0);
285284
}
286285

287-
/**
288-
* Whether the Web server php is running on is IIS
289-
*/
290-
public function checkWebServer(): void
291-
{
292-
// some versions return Microsoft-IIS, some Microsoft/IIS
293-
// we could use a preg_match() but it's slower
294-
if (
295-
Core::getenv('SERVER_SOFTWARE')
296-
&& stripos(Core::getenv('SERVER_SOFTWARE'), 'Microsoft') !== false
297-
&& stripos(Core::getenv('SERVER_SOFTWARE'), 'IIS') !== false
298-
) {
299-
$this->set('PMA_IS_IIS', 1);
300-
301-
return;
302-
}
303-
304-
$this->set('PMA_IS_IIS', 0);
305-
}
306-
307286
/**
308287
* Whether the os php is running on is windows or not
309288
*/

libraries/classes/Config/PageSettings.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace PhpMyAdmin\Config;
99

1010
use PhpMyAdmin\Config\Forms\Page\PageFormList;
11-
use PhpMyAdmin\Core;
1211
use PhpMyAdmin\Message;
1312
use PhpMyAdmin\ResponseRenderer;
1413
use PhpMyAdmin\UserPreferences;
@@ -97,7 +96,7 @@ private function processPageSettings(FormDisplay $formDisplay, ConfigFile $cf):
9796
if ($result === true) {
9897
// reload page
9998
$response = ResponseRenderer::getInstance();
100-
Core::sendHeaderLocation($response->getSelfUrl());
99+
$response->redirect($response->getSelfUrl());
101100
$response->callExit();
102101
}
103102

libraries/classes/Controllers/AbstractController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace PhpMyAdmin\Controllers;
66

7-
use PhpMyAdmin\Core;
87
use PhpMyAdmin\Html\MySQLDocumentation;
98
use PhpMyAdmin\Message;
109
use PhpMyAdmin\ResponseRenderer;
@@ -41,8 +40,7 @@ protected function redirect(string $route, array $params = []): void
4140
return;
4241
}
4342

44-
$uri = './index.php?route=' . $route . Url::getCommonRaw($params, '&');
45-
Core::sendHeaderLocation($uri);
43+
$this->response->redirect('./index.php?route=' . $route . Url::getCommonRaw($params, '&'));
4644
}
4745

4846
/**

libraries/classes/Controllers/CollationConnectionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public function __invoke(ServerRequest $request): void
2626
'utf8mb4_unicode_ci',
2727
);
2828

29-
$this->response->header('Location: index.php?route=/' . Url::getCommonRaw([], '&'));
29+
$this->response->redirect('index.php?route=/' . Url::getCommonRaw([], '&'));
3030
}
3131
}

libraries/classes/Controllers/Export/ExportController.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ public function __invoke(ServerRequest $request): void
283283
// problem opening export file on server?
284284
if ($message !== null) {
285285
$location = $this->export->getPageLocationAndSaveMessage($GLOBALS['export_type'], $message);
286-
$this->response->header('Location: ' . $location);
287-
$this->response->setHttpResponseCode(302);
286+
$this->response->redirect($location);
288287

289288
return;
290289
}
@@ -490,8 +489,7 @@ public function __invoke(ServerRequest $request): void
490489

491490
if ($GLOBALS['save_on_server'] && $GLOBALS['message'] instanceof Message) {
492491
$location = $this->export->getPageLocationAndSaveMessage($GLOBALS['export_type'], $GLOBALS['message']);
493-
$this->response->header('Location: ' . $location);
494-
$this->response->setHttpResponseCode(302);
492+
$this->response->redirect($location);
495493

496494
return;
497495
}
@@ -543,8 +541,7 @@ public function __invoke(ServerRequest $request): void
543541
$GLOBALS['save_filename'],
544542
);
545543
$location = $this->export->getPageLocationAndSaveMessage($GLOBALS['export_type'], $message);
546-
$this->response->header('Location: ' . $location);
547-
$this->response->setHttpResponseCode(302);
544+
$this->response->redirect($location);
548545

549546
return;
550547
}

libraries/classes/Controllers/LogoutController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace PhpMyAdmin\Controllers;
66

7-
use PhpMyAdmin\Core;
87
use PhpMyAdmin\Http\ServerRequest;
98
use PhpMyAdmin\Plugins\AuthenticationPluginFactory;
9+
use PhpMyAdmin\ResponseRenderer;
1010

1111
class LogoutController
1212
{
@@ -17,7 +17,7 @@ public function __construct(private AuthenticationPluginFactory $authPluginFacto
1717
public function __invoke(ServerRequest $request): void
1818
{
1919
if (! $request->isPost() || $GLOBALS['token_mismatch']) {
20-
Core::sendHeaderLocation('./index.php?route=/');
20+
ResponseRenderer::getInstance()->redirect('./index.php?route=/');
2121

2222
return;
2323
}

libraries/classes/Controllers/Sql/SqlController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private function addBookmark(string $goto, array $bkmFields, bool $bkmAllUsers):
229229
}
230230

231231
if (! $this->response->isAjax()) {
232-
Core::sendHeaderLocation('./' . $goto . '&label=' . $bkmFields['bkm_label']);
232+
$this->response->redirect('./' . $goto . '&label=' . $bkmFields['bkm_label']);
233233

234234
return;
235235
}

libraries/classes/Controllers/ThemeSetController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __invoke(ServerRequest $request): void
2828
{
2929
$theme = $request->getParsedBodyParam('set_theme');
3030
if (! $GLOBALS['cfg']['ThemeManager'] || ! is_string($theme) || $theme === '') {
31-
$this->response->header('Location: index.php?route=/' . Url::getCommonRaw([], '&'));
31+
$this->response->redirect('index.php?route=/' . Url::getCommonRaw([], '&'));
3232

3333
return;
3434
}
@@ -47,6 +47,6 @@ public function __invoke(ServerRequest $request): void
4747
$preferences['config_data']['ThemeDefault'] = $theme;
4848
$this->userPreferences->save($preferences['config_data']);
4949

50-
$this->response->header('Location: index.php?route=/' . Url::getCommonRaw([], '&'));
50+
$this->response->redirect('index.php?route=/' . Url::getCommonRaw([], '&'));
5151
}
5252
}

libraries/classes/Core.php

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,22 @@
3232
use function is_array;
3333
use function is_string;
3434
use function json_decode;
35-
use function mb_strlen;
3635
use function mb_strpos;
3736
use function mb_substr;
3837
use function parse_str;
3938
use function parse_url;
4039
use function preg_match;
4140
use function preg_replace;
42-
use function session_write_close;
4341
use function sprintf;
4442
use function str_replace;
4543
use function strlen;
4644
use function strpos;
4745
use function strtolower;
4846
use function substr;
49-
use function trigger_error;
5047
use function unserialize;
5148
use function urldecode;
5249

5350
use const DATE_RFC1123;
54-
use const E_USER_ERROR;
5551
use const E_USER_WARNING;
5652
use const FILTER_VALIDATE_IP;
5753

@@ -257,50 +253,6 @@ public static function getenv(string $varName): string
257253
return '';
258254
}
259255

260-
/**
261-
* Send HTTP header, taking IIS limits into account (600 seems ok)
262-
*
263-
* @param string $uri the header to send
264-
* @param bool $useRefresh whether to use Refresh: header when running on IIS
265-
*/
266-
public static function sendHeaderLocation(string $uri, bool $useRefresh = false): void
267-
{
268-
if ($GLOBALS['config']->get('PMA_IS_IIS') && mb_strlen($uri) > 600) {
269-
ResponseRenderer::getInstance()->disable();
270-
271-
$template = new Template();
272-
echo $template->render('header_location', ['uri' => $uri]);
273-
274-
return;
275-
}
276-
277-
/**
278-
* Avoid relative path redirect problems in case user entered URL
279-
* like /phpmyadmin/index.php/ which some web servers happily accept.
280-
*/
281-
if ($uri[0] === '.') {
282-
$uri = $GLOBALS['config']->getRootPath() . substr($uri, 2);
283-
}
284-
285-
$response = ResponseRenderer::getInstance();
286-
287-
session_write_close();
288-
if ($response->headersSent()) {
289-
trigger_error('Core::sendHeaderLocation called when headers are already sent!', E_USER_ERROR);
290-
}
291-
292-
// bug #1523784: IE6 does not like 'Refresh: 0', it
293-
// results in a blank page
294-
// but we need it when coming from the cookie login panel)
295-
if ($GLOBALS['config']->get('PMA_IS_IIS') && $useRefresh) {
296-
$response->header('Refresh: 0; ' . $uri);
297-
298-
return;
299-
}
300-
301-
$response->header('Location: ' . $uri);
302-
}
303-
304256
/**
305257
* Returns application/json headers. This includes no caching.
306258
*

libraries/classes/Export/Export.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,8 @@ public function exportTable(
10701070

10711071
/**
10721072
* Loads correct page after doing export
1073+
*
1074+
* @psalm-return non-empty-string
10731075
*/
10741076
public function getPageLocationAndSaveMessage(string $exportType, Message $message): string
10751077
{

0 commit comments

Comments
 (0)