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