1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Displays git revision
*
* @package PhpMyAdmin
*/
declare(strict_types=1);
namespace PhpMyAdmin\Display;
use PhpMyAdmin\Config;
use PhpMyAdmin\Core;
use PhpMyAdmin\Response;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
/**
* PhpMyAdmin\Display\GitRevision class
*
* @package PhpMyAdmin
*/
class GitRevision
{
/**
* @var Response
*/
private $response;
/**
* @var Config
*/
private $config;
/**
* @var Template
*/
private $template;
/**
* GitRevision constructor.
* @param Response $response Response instance
* @param Config $config Config instance
* @param Template $template Template instance
*/
public function __construct($response, $config, $template)
{
$this->response = $response;
$this->config = $config;
$this->template = $template;
}
/**
* Returns details about the current Git commit revision
*
* @return string HTML
*/
public function display(): string
{
// load revision data from repo
$this->config->checkGitRevision();
if (! $this->config->get('PMA_VERSION_GIT')) {
$this->response->setRequestStatus(false);
return '';
}
// if using a remote commit fast-forwarded, link to GitHub
$commitHash = substr(
$this->config->get('PMA_VERSION_GIT_COMMITHASH'),
0,
7
);
$commitHash = '<strong title="'
. htmlspecialchars($this->config->get('PMA_VERSION_GIT_MESSAGE'))
. '">' . htmlspecialchars($commitHash) . '</strong>';
if ($this->config->get('PMA_VERSION_GIT_ISREMOTECOMMIT')) {
$commitHash = '<a href="'
. Core::linkURL(
'https://github.com/phpmyadmin/phpmyadmin/commit/'
. htmlspecialchars($this->config->get('PMA_VERSION_GIT_COMMITHASH'))
)
. '" rel="noopener noreferrer" target="_blank">' . $commitHash . '</a>';
}
$branch = $this->config->get('PMA_VERSION_GIT_BRANCH');
$isRemoteBranch = $this->config->get('PMA_VERSION_GIT_ISREMOTEBRANCH');
if ($isRemoteBranch) {
$branch = '<a href="'
. Core::linkURL(
'https://github.com/phpmyadmin/phpmyadmin/tree/'
. $this->config->get('PMA_VERSION_GIT_BRANCH')
)
. '" rel="noopener noreferrer" target="_blank">' . htmlspecialchars($branch) . '</a>';
}
if ($branch !== false) {
$branch = sprintf(
__('%1$s from %2$s branch'),
$commitHash,
$isRemoteBranch ? $branch : htmlspecialchars($branch)
);
} else {
$branch = $commitHash . ' (' . __('no branch') . ')';
}
$committer = $this->config->get('PMA_VERSION_GIT_COMMITTER');
$author = $this->config->get('PMA_VERSION_GIT_AUTHOR');
$name = __('Git revision:') . ' '
. $branch . ',<br> '
. sprintf(
__('committed on %1$s by %2$s'),
Util::localisedDate(strtotime($committer['date'])),
'<a href="' . Core::linkURL(
'mailto:' . htmlspecialchars($committer['email'])
) . '">'
. htmlspecialchars($committer['name']) . '</a>'
)
. ($author != $committer
? ', <br>'
. sprintf(
__('authored on %1$s by %2$s'),
Util::localisedDate(strtotime($author['date'])),
'<a href="' . Core::linkURL(
'mailto:' . htmlspecialchars($author['email'])
) . '">'
. htmlspecialchars($author['name']) . '</a>'
)
: '');
return $this->template->render('list/item', [
'content' => $name,
'id' => 'li_pma_version_git',
'class' => null,
'url' => [
'href' => null,
'target' => null,
'id' => null,
'class' => null,
],
'mysql_help_page' => null,
]);
}
}
|