Visitar URL original
Minor code refactoring of Privileges.php (#17993) · phpmyadmin/phpmyadmin@f7524fd · GitHub
Skip to content

Commit f7524fd

Browse files
Minor code refactoring of Privileges.php (#17993)
* Small fixes * Replace escapeString with quoteString This also fixes bug with $_POST['old_username']. * Add userExists() method * Merge if statements * Use ServerRequest for $initial * Extract getExportPageTitle from getExportUserDefinitionTextarea * Update baselines * Complete redesign of getCurrentAuthenticationPlugin() * Add method getEmptyUserNotice() * Remove redundant variable sets and unsets * Add method checkStructureOfPrivilegeTable() * Remove testGetHtmlForViewUsersError() * Privatize getAddUserHtmlFieldset * Improve tests for mysql.user table checks Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent 1ec3868 commit f7524fd

8 files changed

Lines changed: 527 additions & 735 deletions

File tree

‎libraries/classes/Controllers/Server/PrivilegesController.php‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
use function __;
2323
use function header;
24+
use function htmlspecialchars;
2425
use function implode;
2526
use function is_array;
2627
use function is_string;
@@ -160,7 +161,10 @@ public function __invoke(ServerRequest $request): void
160161
/**
161162
* Changes / copies a user, part I
162163
*/
163-
$password = $serverPrivileges->getDataForChangeOrCopyUser();
164+
$password = $serverPrivileges->getDataForChangeOrCopyUser(
165+
$request->getParsedBodyParam('old_username', ''),
166+
$request->getParsedBodyParam('old_hostname', '')
167+
);
164168

165169
/**
166170
* Adds a user
@@ -192,7 +196,9 @@ public function __invoke(ServerRequest $request): void
192196
$queries = $serverPrivileges->getDbSpecificPrivsQueriesForChangeOrCopyUser(
193197
$queries,
194198
$GLOBALS['username'],
195-
$GLOBALS['hostname']
199+
$GLOBALS['hostname'],
200+
$request->getParsedBodyParam('old_username'),
201+
$request->getParsedBodyParam('old_hostname')
196202
);
197203
}
198204

@@ -337,9 +343,19 @@ public function __invoke(ServerRequest $request): void
337343

338344
// export user definition
339345
if ($request->hasQueryParam('export') || $request->getParsedBodyParam('submit_mult') === 'export') {
340-
[$title, $export] = $serverPrivileges->getListForExportUserDefinition(
346+
/** @var string[]|null $selectedUsers */
347+
$selectedUsers = $request->getParsedBodyParam('selected_usr');
348+
349+
$title = $this->getExportPageTitle(
341350
$GLOBALS['username'] ?? '',
342-
$GLOBALS['hostname'] ?? ''
351+
$GLOBALS['hostname'] ?? '',
352+
$selectedUsers
353+
);
354+
355+
$export = $serverPrivileges->getExportUserDefinitionTextarea(
356+
$GLOBALS['username'] ?? '',
357+
$GLOBALS['hostname'] ?? '',
358+
$selectedUsers
343359
);
344360

345361
unset($GLOBALS['username'], $GLOBALS['hostname']);
@@ -380,7 +396,10 @@ public function __invoke(ServerRequest $request): void
380396
if (! isset($GLOBALS['username'])) {
381397
// No username is given --> display the overview
382398
$this->response->addHTML(
383-
$serverPrivileges->getHtmlForUserOverview($GLOBALS['text_dir'])
399+
$serverPrivileges->getHtmlForUserOverview(
400+
$GLOBALS['text_dir'],
401+
$request->getQueryParam('initial', '')
402+
)
384403
);
385404
} elseif (! empty($routinename)) {
386405
$this->response->addHTML(
@@ -419,4 +438,14 @@ public function __invoke(ServerRequest $request): void
419438

420439
$this->response->addHTML('</div>');
421440
}
441+
442+
private function getExportPageTitle(string $username, string $hostname, ?array $selectedUsers): string
443+
{
444+
if ($selectedUsers !== null) {
445+
return __('Privileges');
446+
}
447+
448+
return __('User') . ' `' . htmlspecialchars($username)
449+
. '`@`' . htmlspecialchars($hostname) . '`';
450+
}
422451
}

0 commit comments

Comments
 (0)