phpmyadmin/libraries/classes/Console.php
Kamil Tekiela 0bdcaba2d2
Add native property types (#18143)
* Add native property types

Includes TypeHints.UnionTypeHintFormat

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Set some default values for properties

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Format and promote properties

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Remove redundant asserts

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Redundant cast

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* $tmanager->theme is never null

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Redundant variable

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Fix empty on $statementInfo bool

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Redundant casts

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Redundant issets

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* getPacked() returns nullable string

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Redundant if

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* $this->content can be null

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Simplify ThemeManager::getInstance()

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Use isset for checking if property is initialized

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Use nullable instead of uninitialized property

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* password is no longer nullable

I can't verify that none of the globals ever tried to set it to null, but the variable should never be nullable.

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Update baselines

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* $same_wide_width param can be float or int

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Update Message.php

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Cast Sub_part to int

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Fix one line doc comments

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

---------

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
2023-02-26 23:30:41 -03:00

118 lines
2.9 KiB
PHP

<?php
/**
* Used to render the console of PMA's pages
*/
declare(strict_types=1);
namespace PhpMyAdmin;
use PhpMyAdmin\ConfigStorage\Relation;
use function __;
use function _ngettext;
use function count;
use function sprintf;
/**
* Class used to output the console
*/
class Console
{
/**
* Whether to display anything
*/
private bool $isEnabled = true;
/**
* Whether we are servicing an ajax request.
*/
private bool $isAjax = false;
public function __construct(private Relation $relation, public Template $template)
{
}
/**
* Set the ajax flag to indicate whether
* we are servicing an ajax request
*
* @param bool $isAjax Whether we are servicing an ajax request
*/
public function setAjax(bool $isAjax): void
{
$this->isAjax = $isAjax;
}
/**
* Disables the rendering of the footer
*/
public function disable(): void
{
$this->isEnabled = false;
}
/**
* Renders the bookmark content
*/
public static function getBookmarkContent(): string
{
$template = new Template();
$relation = new Relation($GLOBALS['dbi']);
$bookmarkFeature = $relation->getRelationParameters()->bookmarkFeature;
if ($bookmarkFeature === null) {
return '';
}
$bookmarks = Bookmark::getList($bookmarkFeature, $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user']);
$count_bookmarks = count($bookmarks);
if ($count_bookmarks > 0) {
$welcomeMessage = sprintf(
_ngettext(
'Showing %1$d bookmark (both private and shared)',
'Showing %1$d bookmarks (both private and shared)',
$count_bookmarks,
),
$count_bookmarks,
);
} else {
$welcomeMessage = __('No bookmarks');
}
return $template->render('console/bookmark_content', [
'welcome_message' => $welcomeMessage,
'bookmarks' => $bookmarks,
]);
}
/**
* Returns the list of JS scripts required by console
*
* @return string[] list of scripts
*/
public function getScripts(): array
{
return ['console.js'];
}
/**
* Renders the console
*/
public function getDisplay(): string
{
if ($this->isAjax || ! $this->isEnabled) {
return '';
}
$bookmarkFeature = $this->relation->getRelationParameters()->bookmarkFeature;
$_sql_history = $this->relation->getHistory($GLOBALS['cfg']['Server']['user']);
$bookmarkContent = static::getBookmarkContent();
return $this->template->render('console/display', [
'has_bookmark_feature' => $bookmarkFeature !== null,
'sql_history' => $_sql_history,
'bookmark_content' => $bookmarkContent,
]);
}
}