GitRevision.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Displays git revision
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Display;
  9. use PhpMyAdmin\Core;
  10. use PhpMyAdmin\Response;
  11. use PhpMyAdmin\Util;
  12. /**
  13. * PhpMyAdmin\Display\GitRevision class
  14. *
  15. * @package PhpMyAdmin
  16. */
  17. class GitRevision
  18. {
  19. /**
  20. * Prints details about the current Git commit revision
  21. *
  22. * @return void
  23. */
  24. public static function display()
  25. {
  26. // load revision data from repo
  27. $GLOBALS['PMA_Config']->checkGitRevision();
  28. if (! $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT')) {
  29. $response = Response::getInstance();
  30. $response->setRequestStatus(false);
  31. return;
  32. }
  33. // if using a remote commit fast-forwarded, link to GitHub
  34. $commit_hash = substr(
  35. $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH'),
  36. 0,
  37. 7
  38. );
  39. $commit_hash = '<strong title="'
  40. . htmlspecialchars($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_MESSAGE'))
  41. . '">' . htmlspecialchars($commit_hash) . '</strong>';
  42. if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTECOMMIT')) {
  43. $commit_hash = '<a href="'
  44. . Core::linkURL(
  45. 'https://github.com/phpmyadmin/phpmyadmin/commit/'
  46. . htmlspecialchars($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH'))
  47. )
  48. . '" rel="noopener noreferrer" target="_blank">' . $commit_hash . '</a>';
  49. }
  50. $branch = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH');
  51. $isRemoteBranch = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTEBRANCH');
  52. if ($isRemoteBranch) {
  53. $branch = '<a href="'
  54. . Core::linkURL(
  55. 'https://github.com/phpmyadmin/phpmyadmin/tree/'
  56. . $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH')
  57. )
  58. . '" rel="noopener noreferrer" target="_blank">' . htmlspecialchars($branch) . '</a>';
  59. }
  60. if ($branch !== false) {
  61. $branch = sprintf(
  62. __('%1$s from %2$s branch'),
  63. $commit_hash,
  64. $isRemoteBranch ? $branch : htmlspecialchars($branch)
  65. );
  66. } else {
  67. $branch = $commit_hash . ' (' . __('no branch') . ')';
  68. }
  69. $committer = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITTER');
  70. $author = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_AUTHOR');
  71. Core::printListItem(
  72. __('Git revision:') . ' '
  73. . $branch . ',<br /> '
  74. . sprintf(
  75. __('committed on %1$s by %2$s'),
  76. Util::localisedDate(strtotime($committer['date'])),
  77. '<a href="' . Core::linkURL(
  78. 'mailto:' . htmlspecialchars($committer['email'])
  79. ) . '">'
  80. . htmlspecialchars($committer['name']) . '</a>'
  81. )
  82. . ($author != $committer
  83. ? ', <br />'
  84. . sprintf(
  85. __('authored on %1$s by %2$s'),
  86. Util::localisedDate(strtotime($author['date'])),
  87. '<a href="' . Core::linkURL(
  88. 'mailto:' . htmlspecialchars($author['email'])
  89. ) . '">'
  90. . htmlspecialchars($author['name']) . '</a>'
  91. )
  92. : ''),
  93. 'li_pma_version_git', null, null, null
  94. );
  95. }
  96. }