ChangeLogController.php 3.5 KB

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