Skip to content

Commit 0b9db09

Browse files
Merge pull request #18581 from MauricioFauth/request-is-ajax
Add a isAjax() method to ServerRequest class
2 parents bd20426 + 19dad3b commit 0b9db09

65 files changed

Lines changed: 199 additions & 151 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

js/src/modules/themes-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CommonParams } from './common.ts';
66
*/
77
export const ThemesManager = {
88
handleEvent: () => {
9-
$.get('index.php?route=/themes', { 'server': CommonParams.get('server') }, data => {
9+
$.get('index.php?route=/themes', { 'server': CommonParams.get('server'), 'ajax_request': true }, data => {
1010
$('#themesModal .modal-body').html(data.themes);
1111
});
1212
}

js/src/server/privileges.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const EditUserGroup = {
5050
$.get(
5151
'index.php?route=/server/user-groups/edit-form',
5252
{
53+
'ajax_request': true,
5354
'username': username,
5455
'server': CommonParams.get('server')
5556
},

libraries/classes/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,19 @@ public function run(bool $isSetupPage = false): void
290290
// TODO: Set SQL modes too.
291291
} else { // end server connecting
292292
$response = ResponseRenderer::getInstance();
293+
$response->setAjax($request->isAjax());
293294
$response->getHeader()->disableMenuAndConsole();
294295
$response->setMinimalFooter();
295296
}
296297

297298
$response = ResponseRenderer::getInstance();
299+
$response->setAjax($request->isAjax());
298300

299301
/**
300302
* There is no point in even attempting to process
301303
* an ajax request if there is a token mismatch
302304
*/
303-
if ($response->isAjax() && $request->isPost() && $GLOBALS['token_mismatch']) {
305+
if ($request->isAjax() && $request->isPost() && $GLOBALS['token_mismatch']) {
304306
$response->setRequestStatus(false);
305307
$response->addJSON(
306308
'message',

libraries/classes/Controllers/Database/EventsController.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __invoke(ServerRequest $request): void
4141

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

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

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

67-
if ($this->response->isAjax()) {
67+
if ($request->isAjax()) {
6868
if ($GLOBALS['message']->isSuccess()) {
6969
$events = $this->events->getDetails($GLOBALS['db'], $_POST['item_name']);
7070
$event = $events[0];
@@ -165,12 +165,12 @@ public function __invoke(ServerRequest $request): void
165165
'db' => $GLOBALS['db'],
166166
'event' => $item,
167167
'mode' => $mode,
168-
'is_ajax' => $this->response->isAjax(),
168+
'is_ajax' => $request->isAjax(),
169169
'status_display' => $this->events->status['display'],
170170
'event_type' => $this->events->type,
171171
'event_interval' => $this->events->interval,
172172
]);
173-
if ($this->response->isAjax()) {
173+
if ($request->isAjax()) {
174174
$this->response->addJSON('message', $editor);
175175
$this->response->addJSON('title', $title);
176176

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

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

215-
if ($this->response->isAjax()) {
215+
if ($request->isAjax()) {
216216
$this->response->addJSON('message', $exportData);
217217
$this->response->addJSON('title', $title);
218218

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

237-
if ($this->response->isAjax()) {
237+
if ($request->isAjax()) {
238238
$this->response->setRequestStatus(false);
239239
$this->response->addJSON('message', $message);
240240

@@ -253,7 +253,7 @@ public function __invoke(ServerRequest $request): void
253253
'has_privilege' => Util::currentUserHasPrivilege('EVENT', $GLOBALS['db']),
254254
'scheduler_state' => $this->events->getEventSchedulerStatus(),
255255
'text_dir' => $GLOBALS['text_dir'],
256-
'is_ajax' => $this->response->isAjax() && empty($_REQUEST['ajax_page_request']),
256+
'is_ajax' => $request->isAjax() && empty($_REQUEST['ajax_page_request']),
257257
]);
258258
}
259259
}

libraries/classes/Controllers/Database/Operations/CollationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __invoke(ServerRequest $request): void
3131
{
3232
$GLOBALS['errorUrl'] ??= null;
3333

34-
if (! $this->response->isAjax()) {
34+
if (! $request->isAjax()) {
3535
return;
3636
}
3737

libraries/classes/Controllers/Database/OperationsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function __invoke(ServerRequest $request): void
191191
* Database has been successfully renamed/moved. If in an Ajax request,
192192
* generate the output with {@link ResponseRenderer} and exit
193193
*/
194-
if ($this->response->isAjax()) {
194+
if ($request->isAjax()) {
195195
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
196196
$this->response->addJSON('message', $GLOBALS['message']);
197197
$this->response->addJSON('newname', $newDatabaseName?->getName() ?? '');

libraries/classes/Controllers/Database/RoutinesController.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __invoke(ServerRequest $request): void
5555

5656
$this->checkUserPrivileges->getPrivileges();
5757

58-
if (! $this->response->isAjax()) {
58+
if (! $request->isAjax()) {
5959
/**
6060
* Displays the header and tabs
6161
*/
@@ -92,7 +92,7 @@ public function __invoke(ServerRequest $request): void
9292

9393
if (! empty($_POST['editor_process_add']) || ! empty($_POST['editor_process_edit'])) {
9494
$output = $this->routines->handleRequestCreateOrEdit($GLOBALS['db']);
95-
if ($this->response->isAjax()) {
95+
if ($request->isAjax()) {
9696
if (! $GLOBALS['message']->isSuccess()) {
9797
$this->response->setRequestStatus(false);
9898
$this->response->addJSON('message', $output);
@@ -227,15 +227,15 @@ public function __invoke(ServerRequest $request): void
227227
'db' => $GLOBALS['db'],
228228
'routine' => $routine,
229229
'is_edit_mode' => $mode === 'edit',
230-
'is_ajax' => $this->response->isAjax(),
230+
'is_ajax' => $request->isAjax(),
231231
'parameter_rows' => $parameterRows,
232232
'charsets' => $charsets,
233233
'numeric_options' => $this->routines->numericOptions,
234234
'has_privileges' => $GLOBALS['proc_priv'] && $GLOBALS['is_reload_priv'],
235235
'sql_data_access' => $this->routines->sqlDataAccess,
236236
]);
237237

238-
if ($this->response->isAjax()) {
238+
if ($request->isAjax()) {
239239
$this->response->addJSON('message', $editor);
240240
$this->response->addJSON('title', $title);
241241
$this->response->addJSON(
@@ -265,7 +265,7 @@ public function __invoke(ServerRequest $request): void
265265
);
266266

267267
$message = Message::error($message);
268-
if ($this->response->isAjax()) {
268+
if ($request->isAjax()) {
269269
$this->response->setRequestStatus(false);
270270
$this->response->addJSON('message', $message);
271271

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

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

306306
// Print/send output
307-
if ($this->response->isAjax()) {
307+
if ($request->isAjax()) {
308308
$this->response->setRequestStatus($message->isSuccess());
309309
$this->response->addJSON('message', $message->getDisplay() . $output);
310310
$this->response->addJSON('dialog', false);
@@ -328,11 +328,11 @@ public function __invoke(ServerRequest $request): void
328328
$form = $this->template->render('database/routines/execute_form', [
329329
'db' => $GLOBALS['db'],
330330
'routine' => $routine,
331-
'ajax' => $this->response->isAjax(),
331+
'ajax' => $request->isAjax(),
332332
'show_function_fields' => $GLOBALS['cfg']['ShowFunctionFields'],
333333
'params' => $params,
334334
]);
335-
if ($this->response->isAjax()) {
335+
if ($request->isAjax()) {
336336
$title = __('Execute routine') . ' ' . Util::backquote(
337337
htmlentities($_GET['item_name'], ENT_QUOTES),
338338
);
@@ -349,7 +349,7 @@ public function __invoke(ServerRequest $request): void
349349
return;
350350
}
351351

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

392-
if ($this->response->isAjax()) {
392+
if ($request->isAjax()) {
393393
$this->response->addJSON('message', $exportData);
394394
$this->response->addJSON('title', $title);
395395

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

417-
if ($this->response->isAjax()) {
417+
if ($request->isAjax()) {
418418
$this->response->setRequestStatus(false);
419419
$this->response->addJSON('message', $message);
420420

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

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

435435
$rows = '';
436436
foreach ($items as $item) {

libraries/classes/Controllers/Database/SearchController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __invoke(ServerRequest $request): void
4646
);
4747
$errorMessage .= MySQLDocumentation::showDocumentation('config', 'cfg_UseDbSearch');
4848
$this->response->setRequestStatus(false);
49-
if ($this->response->isAjax()) {
49+
if ($request->isAjax()) {
5050
$this->response->addJSON('message', Message::error($errorMessage)->getDisplay());
5151

5252
return;
@@ -68,7 +68,7 @@ public function __invoke(ServerRequest $request): void
6868
}
6969

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

libraries/classes/Controllers/Database/Structure/FavoriteTableController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __invoke(ServerRequest $request): void
4444
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
4545
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
4646

47-
if (! $this->response->isAjax()) {
47+
if (! $request->isAjax()) {
4848
return;
4949
}
5050

libraries/classes/Controllers/Database/Structure/RealRowCountController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __invoke(ServerRequest $request): void
3838
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
3939
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
4040

41-
if (! $this->hasDatabase() || ! $this->response->isAjax()) {
41+
if (! $this->hasDatabase() || ! $request->isAjax()) {
4242
return;
4343
}
4444

0 commit comments

Comments
 (0)