PageView.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace dokuwiki\Ui;
  3. use dokuwiki\Extension\Event;
  4. /**
  5. * DokuWiki PageView Interface
  6. *
  7. * @package dokuwiki\Ui
  8. */
  9. class PageView extends Ui
  10. {
  11. protected $text;
  12. /**
  13. * PageView Ui constructor
  14. *
  15. * @param null|string $text wiki text or null for showing $ID
  16. */
  17. public function __construct($text = null)
  18. {
  19. $this->text = $text;
  20. }
  21. /**
  22. * Show a wiki page
  23. *
  24. * @author Andreas Gohr <andi@splitbrain.org>
  25. *
  26. * @triggers HTML_SHOWREV_OUTPUT
  27. * @return void
  28. */
  29. public function show()
  30. {
  31. global $ID;
  32. global $REV;
  33. global $HIGH;
  34. global $INFO;
  35. global $DATE_AT;
  36. //disable section editing for old revisions or in preview
  37. if ($this->text !== null || $REV) {
  38. $secedit = false;
  39. } else {
  40. $secedit = true;
  41. }
  42. if ($this->text !== null) {
  43. //PreviewHeader
  44. echo '<br id="scroll__here" />';
  45. // print intro for preview
  46. echo p_locale_xhtml('preview');
  47. echo '<div class="preview"><div class="pad">';
  48. $html = html_secedit(p_render('xhtml', p_get_instructions($this->text), $info), $secedit);
  49. if ($INFO['prependTOC']) $html = tpl_toc(true) . $html;
  50. echo $html;
  51. echo '<div class="clearer"></div>';
  52. echo '</div></div>';
  53. } else {
  54. if ($REV || $DATE_AT) {
  55. // print intro for old revisions
  56. $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
  57. Event::createAndTrigger('HTML_SHOWREV_OUTPUT', $data, [$this, 'showrev']);
  58. }
  59. $html = p_wiki_xhtml($ID, $REV, true, $DATE_AT);
  60. $html = html_secedit($html, $secedit);
  61. if ($INFO['prependTOC']) $html = tpl_toc(true) . $html;
  62. $html = html_hilight($html, $HIGH);
  63. echo $html;
  64. }
  65. }
  66. /**
  67. * Show a revision warning
  68. *
  69. * @author Szymon Olewniczak <dokuwiki@imz.re>
  70. */
  71. public function showrev()
  72. {
  73. print p_locale_xhtml('showrev');
  74. }
  75. }