ChangeLogController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Simple script to set correct charset for changelog
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Controllers;
  7. use PhpMyAdmin\Core;
  8. use function __;
  9. use function array_keys;
  10. use function basename;
  11. use function file_get_contents;
  12. use function htmlspecialchars;
  13. use function is_readable;
  14. use function ob_get_clean;
  15. use function ob_start;
  16. use function preg_replace;
  17. use function printf;
  18. use function readgzfile;
  19. use function substr;
  20. class ChangeLogController extends AbstractController
  21. {
  22. public function __invoke(): void
  23. {
  24. $this->response->disable();
  25. $this->response->getHeader()->sendHttpHeaders();
  26. $filename = CHANGELOG_FILE;
  27. /**
  28. * Read changelog.
  29. */
  30. // Check if the file is available, some distributions remove these.
  31. if (! @is_readable($filename)) {
  32. printf(
  33. __(
  34. 'The %s file is not available on this system, please visit %s for more information.'
  35. ),
  36. basename($filename),
  37. '<a href="' . Core::linkURL('https://www.phpmyadmin.net/')
  38. . '" rel="noopener noreferrer" target="_blank">phpmyadmin.net</a>'
  39. );
  40. return;
  41. }
  42. // Test if the if is in a compressed format
  43. if (substr($filename, -3) === '.gz') {
  44. ob_start();
  45. readgzfile($filename);
  46. $changelog = ob_get_clean();
  47. } else {
  48. $changelog = file_get_contents($filename);
  49. }
  50. /**
  51. * Whole changelog in variable.
  52. */
  53. $changelog = htmlspecialchars((string) $changelog);
  54. $github_url = 'https://github.com/phpmyadmin/phpmyadmin/';
  55. $faq_url = 'https://docs.phpmyadmin.net/en/latest/faq.html';
  56. $replaces = [
  57. '@(https?://[./a-zA-Z0-9.-_-]*[/a-zA-Z0-9_])@' => '<a href="url.php?url=\\1">\\1</a>',
  58. // mail address
  59. '/([0-9]{4}-[0-9]{2}-[0-9]{2}) (.+[^ ]) +&lt;(.*@.*)&gt;/i' => '\\1 <a href="mailto:\\3">\\2</a>',
  60. // FAQ entries
  61. '/FAQ ([0-9]+)\.([0-9a-z]+)/i' => '<a href="url.php?url=' . $faq_url . '#faq\\1-\\2">FAQ \\1.\\2</a>',
  62. // GitHub issues
  63. '/issue\s*#?([0-9]{4,5}) /i' => '<a href="url.php?url=' . $github_url . 'issues/\\1">issue #\\1</a> ',
  64. // CVE/CAN entries
  65. '/((CAN|CVE)-[0-9]+-[0-9]+)/' => '<a href="url.php?url='
  66. . 'https://www.cve.org/CVERecord?id=\\1">\\1</a>',
  67. // PMASAentries
  68. '/(PMASA-[0-9]+-[0-9]+)/' => '<a href="url.php?url=https://www.phpmyadmin.net/security/\\1/">\\1</a>',
  69. // Highlight releases (with links)
  70. '/([0-9]+)\.([0-9]+)\.([0-9]+)\.0 (\([0-9-]+\))/' => '<a id="\\1_\\2_\\3"></a>'
  71. . '<a href="url.php?url=' . $github_url . 'commits/RELEASE_\\1_\\2_\\3">'
  72. . '\\1.\\2.\\3.0 \\4</a>',
  73. '/([0-9]+)\.([0-9]+)\.([0-9]+)\.([1-9][0-9]*) (\([0-9-]+\))/' => '<a id="\\1_\\2_\\3_\\4"></a>'
  74. . '<a href="url.php?url=' . $github_url . 'commits/RELEASE_\\1_\\2_\\3_\\4">'
  75. . '\\1.\\2.\\3.\\4 \\5</a>',
  76. // Highlight releases (not linkable)
  77. '/( ### )(.*)/' => '\\1<b>\\2</b>',
  78. // Links target and rel
  79. '/a href="/' => 'a target="_blank" rel="noopener noreferrer" href="',
  80. ];
  81. $this->response->header('Content-type: text/html; charset=utf-8');
  82. echo $this->template->render('changelog', [
  83. 'changelog' => preg_replace(array_keys($replaces), $replaces, $changelog),
  84. ]);
  85. }
  86. }