GitRevision.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. . '">' . $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. . $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. if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTEBRANCH')) {
  52. $branch = '<a href="'
  53. . Core::linkURL(
  54. 'https://github.com/phpmyadmin/phpmyadmin/tree/'
  55. . $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH')
  56. )
  57. . '" rel="noopener noreferrer" target="_blank">' . $branch . '</a>';
  58. }
  59. if ($branch !== false) {
  60. $branch = sprintf(__('%1$s from %2$s branch'), $commit_hash, $branch);
  61. } else {
  62. $branch = $commit_hash . ' (' . __('no branch') . ')';
  63. }
  64. $committer = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITTER');
  65. $author = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_AUTHOR');
  66. Core::printListItem(
  67. __('Git revision:') . ' '
  68. . $branch . ',<br /> '
  69. . sprintf(
  70. __('committed on %1$s by %2$s'),
  71. Util::localisedDate(strtotime($committer['date'])),
  72. '<a href="' . Core::linkURL(
  73. 'mailto:' . htmlspecialchars($committer['email'])
  74. ) . '">'
  75. . htmlspecialchars($committer['name']) . '</a>'
  76. )
  77. . ($author != $committer
  78. ? ', <br />'
  79. . sprintf(
  80. __('authored on %1$s by %2$s'),
  81. Util::localisedDate(strtotime($author['date'])),
  82. '<a href="' . Core::linkURL(
  83. 'mailto:' . htmlspecialchars($author['email'])
  84. ) . '">'
  85. . htmlspecialchars($author['name']) . '</a>'
  86. )
  87. : ''),
  88. 'li_pma_version_git', null, null, null
  89. );
  90. }
  91. }