Skip to content

Commit

Permalink
Add a isAjax() method to ServerRequest class
Browse files Browse the repository at this point in the history
This method belongs to the ServerRequest class instead of the
ResponseRenderer class, as it's a request property.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Jul 26, 2023
1 parent ef69ad4 commit 19dad3b
Show file tree
Hide file tree
Showing 65 changed files with 199 additions and 151 deletions.
2 changes: 1 addition & 1 deletion js/src/modules/themes-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CommonParams } from './common.ts';
*/
export const ThemesManager = {
handleEvent: () => {
$.get('index.php?route=/themes', { 'server': CommonParams.get('server') }, data => {
$.get('index.php?route=/themes', { 'server': CommonParams.get('server'), 'ajax_request': true }, data => {
$('#themesModal .modal-body').html(data.themes);
});
}
Expand Down
1 change: 1 addition & 0 deletions js/src/server/privileges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const EditUserGroup = {
$.get(
'index.php?route=/server/user-groups/edit-form',
{
'ajax_request': true,
'username': username,
'server': CommonParams.get('server')
},
Expand Down
4 changes: 3 additions & 1 deletion libraries/classes/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,19 @@ public function run(bool $isSetupPage = false): void
// TODO: Set SQL modes too.
} else { // end server connecting
$response = ResponseRenderer::getInstance();
$response->setAjax($request->isAjax());
$response->getHeader()->disableMenuAndConsole();
$response->setMinimalFooter();
}

$response = ResponseRenderer::getInstance();
$response->setAjax($request->isAjax());

/**
* There is no point in even attempting to process
* an ajax request if there is a token mismatch
*/
if ($response->isAjax() && $request->isPost() && $GLOBALS['token_mismatch']) {
if ($request->isAjax() && $request->isPost() && $GLOBALS['token_mismatch']) {
$response->setRequestStatus(false);
$response->addJSON(
'message',
Expand Down
16 changes: 8 additions & 8 deletions libraries/classes/Controllers/Database/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __invoke(ServerRequest $request): void

$this->addScriptFiles(['database/events.js']);

if (! $this->response->isAjax()) {
if (! $request->isAjax()) {
$this->checkParameters(['db']);

$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
Expand All @@ -64,7 +64,7 @@ public function __invoke(ServerRequest $request): void
if (! empty($_POST['editor_process_add']) || ! empty($_POST['editor_process_edit'])) {
$output = $this->events->handleEditor();

if ($this->response->isAjax()) {
if ($request->isAjax()) {
if ($GLOBALS['message']->isSuccess()) {
$events = $this->events->getDetails($GLOBALS['db'], $_POST['item_name']);
$event = $events[0];
Expand Down Expand Up @@ -165,12 +165,12 @@ public function __invoke(ServerRequest $request): void
'db' => $GLOBALS['db'],
'event' => $item,
'mode' => $mode,
'is_ajax' => $this->response->isAjax(),
'is_ajax' => $request->isAjax(),
'status_display' => $this->events->status['display'],
'event_type' => $this->events->type,
'event_interval' => $this->events->interval,
]);
if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->addJSON('message', $editor);
$this->response->addJSON('title', $title);

Expand All @@ -189,7 +189,7 @@ public function __invoke(ServerRequest $request): void
htmlspecialchars(Util::backquote($GLOBALS['db'])),
);
$message = Message::error($message);
if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);

Expand All @@ -212,7 +212,7 @@ public function __invoke(ServerRequest $request): void
$exportData = htmlspecialchars(trim($exportData));
$title = sprintf(__('Export of event %s'), $itemName);

if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->addJSON('message', $exportData);
$this->response->addJSON('title', $title);

Expand All @@ -234,7 +234,7 @@ public function __invoke(ServerRequest $request): void
);
$message = Message::error($message);

if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);

Expand All @@ -253,7 +253,7 @@ public function __invoke(ServerRequest $request): void
'has_privilege' => Util::currentUserHasPrivilege('EVENT', $GLOBALS['db']),
'scheduler_state' => $this->events->getEventSchedulerStatus(),
'text_dir' => $GLOBALS['text_dir'],
'is_ajax' => $this->response->isAjax() && empty($_REQUEST['ajax_page_request']),
'is_ajax' => $request->isAjax() && empty($_REQUEST['ajax_page_request']),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke(ServerRequest $request): void
{
$GLOBALS['errorUrl'] ??= null;

if (! $this->response->isAjax()) {
if (! $request->isAjax()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function __invoke(ServerRequest $request): void
* Database has been successfully renamed/moved. If in an Ajax request,
* generate the output with {@link ResponseRenderer} and exit
*/
if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
$this->response->addJSON('message', $GLOBALS['message']);
$this->response->addJSON('newname', $newDatabaseName?->getName() ?? '');
Expand Down
26 changes: 13 additions & 13 deletions libraries/classes/Controllers/Database/RoutinesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __invoke(ServerRequest $request): void

$this->checkUserPrivileges->getPrivileges();

if (! $this->response->isAjax()) {
if (! $request->isAjax()) {
/**
* Displays the header and tabs
*/
Expand Down Expand Up @@ -92,7 +92,7 @@ public function __invoke(ServerRequest $request): void

if (! empty($_POST['editor_process_add']) || ! empty($_POST['editor_process_edit'])) {
$output = $this->routines->handleRequestCreateOrEdit($GLOBALS['db']);
if ($this->response->isAjax()) {
if ($request->isAjax()) {
if (! $GLOBALS['message']->isSuccess()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $output);
Expand Down Expand Up @@ -227,15 +227,15 @@ public function __invoke(ServerRequest $request): void
'db' => $GLOBALS['db'],
'routine' => $routine,
'is_edit_mode' => $mode === 'edit',
'is_ajax' => $this->response->isAjax(),
'is_ajax' => $request->isAjax(),
'parameter_rows' => $parameterRows,
'charsets' => $charsets,
'numeric_options' => $this->routines->numericOptions,
'has_privileges' => $GLOBALS['proc_priv'] && $GLOBALS['is_reload_priv'],
'sql_data_access' => $this->routines->sqlDataAccess,
]);

if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->addJSON('message', $editor);
$this->response->addJSON('title', $title);
$this->response->addJSON(
Expand Down Expand Up @@ -265,7 +265,7 @@ public function __invoke(ServerRequest $request): void
);

$message = Message::error($message);
if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);

Expand All @@ -289,7 +289,7 @@ public function __invoke(ServerRequest $request): void
htmlspecialchars(Util::backquote($GLOBALS['db'])),
);
$message = Message::error($message);
if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);

Expand All @@ -304,7 +304,7 @@ public function __invoke(ServerRequest $request): void
[$output, $message] = $this->routines->handleExecuteRoutine($routine);

// Print/send output
if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->setRequestStatus($message->isSuccess());
$this->response->addJSON('message', $message->getDisplay() . $output);
$this->response->addJSON('dialog', false);
Expand All @@ -328,11 +328,11 @@ public function __invoke(ServerRequest $request): void
$form = $this->template->render('database/routines/execute_form', [
'db' => $GLOBALS['db'],
'routine' => $routine,
'ajax' => $this->response->isAjax(),
'ajax' => $request->isAjax(),
'show_function_fields' => $GLOBALS['cfg']['ShowFunctionFields'],
'params' => $params,
]);
if ($this->response->isAjax()) {
if ($request->isAjax()) {
$title = __('Execute routine') . ' ' . Util::backquote(
htmlentities($_GET['item_name'], ENT_QUOTES),
);
Expand All @@ -349,7 +349,7 @@ public function __invoke(ServerRequest $request): void
return;
}

if ($this->response->isAjax()) {
if ($request->isAjax()) {
$message = __('Error in processing request:') . ' ';
$message .= sprintf(
__('No routine with name %1$s found in database %2$s.'),
Expand Down Expand Up @@ -389,7 +389,7 @@ public function __invoke(ServerRequest $request): void
$exportData = htmlspecialchars(trim($exportData));
$title = sprintf(__('Export of routine %s'), $itemName);

if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->addJSON('message', $exportData);
$this->response->addJSON('title', $title);

Expand All @@ -414,7 +414,7 @@ public function __invoke(ServerRequest $request): void
);
$message = Message::error($message);

if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);

Expand All @@ -430,7 +430,7 @@ public function __invoke(ServerRequest $request): void
}

$items = Routines::getDetails($this->dbi, $GLOBALS['db'], $type);
$isAjax = $this->response->isAjax() && empty($_REQUEST['ajax_page_request']);
$isAjax = $request->isAjax() && empty($_REQUEST['ajax_page_request']);

$rows = '';
foreach ($items as $item) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Controllers/Database/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __invoke(ServerRequest $request): void
);
$errorMessage .= MySQLDocumentation::showDocumentation('config', 'cfg_UseDbSearch');
$this->response->setRequestStatus(false);
if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->addJSON('message', Message::error($errorMessage)->getDisplay());

return;
Expand All @@ -68,7 +68,7 @@ public function __invoke(ServerRequest $request): void
}

// If we are in an Ajax request, we need to exit after displaying all the HTML
if ($this->response->isAjax() && empty($_REQUEST['ajax_page_request'])) {
if ($request->isAjax() && empty($_REQUEST['ajax_page_request'])) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __invoke(ServerRequest $request): void
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');

if (! $this->response->isAjax()) {
if (! $request->isAjax()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __invoke(ServerRequest $request): void
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');

if (! $this->hasDatabase() || ! $this->response->isAjax()) {
if (! $this->hasDatabase() || ! $request->isAjax()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Controllers/ErrorReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function __invoke(ServerRequest $request): void
}

/* Add message to response */
if ($this->response->isAjax()) {
if ($request->isAjax()) {
if ($exceptionType === 'js') {
$this->response->addJSON('message', $msg);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ final class CheckTimeOutController extends AbstractController
{
public function __invoke(ServerRequest $request): void
{
$this->response->setAjax(true);
if (! $request->isAjax()) {
return;
}

if (isset($_SESSION['pma_export_error'])) {
unset($_SESSION['pma_export_error']);
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Controllers/GitInfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(ResponseRenderer $response, Template $template, priv

public function __invoke(ServerRequest $request): void
{
if (! $this->response->isAjax()) {
if (! $request->isAjax()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __invoke(ServerRequest $request): void
$GLOBALS['show_query'] ??= null;
$GLOBALS['errorUrl'] ??= null;

if ($this->response->isAjax() && ! empty($_REQUEST['access_time'])) {
if ($request->isAjax() && ! empty($_REQUEST['access_time'])) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Controllers/Import/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public function __invoke(ServerRequest $request): void
}

$GLOBALS['import_text'] = $bookmark->getQuery();
if ($this->response->isAjax()) {
if ($request->isAjax()) {
$GLOBALS['message'] = Message::success(__('Showing bookmark'));
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
$this->response->addJSON('message', $GLOBALS['message']);
Expand All @@ -381,7 +381,7 @@ public function __invoke(ServerRequest $request): void
}

$bookmark->delete();
if ($this->response->isAjax()) {
if ($request->isAjax()) {
$GLOBALS['message'] = Message::success(
__('The bookmark has been deleted.'),
);
Expand Down
6 changes: 4 additions & 2 deletions libraries/classes/Controllers/LintController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class LintController extends AbstractController
{
public function __invoke(ServerRequest $request): void
{
if (! $request->isAjax()) {
return;
}

/**
* The SQL query to be analyzed.
*
Expand All @@ -36,8 +40,6 @@ public function __invoke(ServerRequest $request): void
*/
$sqlQuery = $request->getParsedBodyParam('sql_query', '');

$this->response->setAjax(true);

// Disabling standard response.
$this->response->disable();

Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Controllers/NavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(

public function __invoke(ServerRequest $request): void
{
if (! $this->response->isAjax()) {
if (! $request->isAjax()) {
$this->response->addHTML(
Message::error(
__('Fatal error: The navigation can only be accessed via AJAX'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function __invoke(ServerRequest $request): void
),
]);

if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->addJSON('disableNaviSettings', true);
} else {
define('PMA_DISABLE_NAVI_SETTINGS', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function __invoke(ServerRequest $request): void
),
]);

if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->addJSON('disableNaviSettings', true);
} else {
define('PMA_DISABLE_NAVI_SETTINGS', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function __invoke(ServerRequest $request): void
),
]);

if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->addJSON('disableNaviSettings', true);
} else {
define('PMA_DISABLE_NAVI_SETTINGS', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function __invoke(ServerRequest $request): void
),
]);

if ($this->response->isAjax()) {
if ($request->isAjax()) {
$this->response->addJSON('disableNaviSettings', true);
} else {
define('PMA_DISABLE_NAVI_SETTINGS', true);
Expand Down

0 comments on commit 19dad3b

Please sign in to comment.