1<?php
2
3namespace dokuwiki\Ui;
4
5use dokuwiki\ChangeLog\PageChangeLog;
6use dokuwiki\ChangeLog\RevisionInfo;
7use dokuwiki\Form\Form;
8
9/**
10 * DokuWiki PageRevisions Interface
11 *
12 * @package dokuwiki\Ui
13 */
14class PageRevisions extends Revisions
15{
16    /* @var PageChangeLog */
17    protected $changelog;
18
19    /**
20     * PageRevisions Ui constructor
21     *
22     * @param string $id id of page
23     */
24    public function __construct($id = null)
25    {
26        global $INFO;
27        if (!isset($id)) $id = $INFO['id'];
28        parent::__construct($id);
29    }
30
31    /** @inheritdoc */
32    protected function setChangeLog()
33    {
34        $this->changelog = new PageChangeLog($this->id);
35    }
36
37    /**
38     * Display list of old revisions of the page
39     *
40     * @param int $first skip the first n changelog lines
41     * @return void
42     * @author Kate Arzamastseva <pshns@ukr.net>
43     * @author Satoshi Sahara <sahara.satoshi@gmail.com>
44     *
45     * @author Andreas Gohr <andi@splitbrain.org>
46     * @author Ben Coburn <btcoburn@silicodon.net>
47     */
48    public function show($first = -1)
49    {
50        global $lang, $REV;
51        $changelog =& $this->changelog;
52
53        // get revisions, and set correct pagination parameters (first, hasNext)
54        if ($first === null) $first = -1;
55        $hasNext = false;
56        $revisions = $this->getRevisions($first, $hasNext);
57
58        // print intro
59        echo p_locale_xhtml('revisions');
60
61        // create the form
62        $form = new Form([
63            'id' => 'page__revisions',
64            'class' => 'changes',
65        ]);
66        $form->addTagOpen('div')->addClass('no');
67
68        // start listing
69        $form->addTagOpen('ul');
70        foreach ($revisions as $info) {
71            $rev = $info['date'];
72
73            $RevInfo = new RevisionInfo($info);
74            $RevInfo->isCurrent($changelog->isCurrentRevision($rev));
75
76            $class = ($RevInfo->val('type') === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : '';
77            $form->addTagOpen('li')->addClass($class);
78            $form->addTagOpen('div')->addClass('li');
79
80            if ($RevInfo->isCurrent()) {
81                $form->addCheckbox('rev2[]')->val($rev);
82            } elseif ($rev == $REV) {
83                $form->addCheckbox('rev2[]')->val($rev)->attr('checked', 'checked');
84            } elseif (page_exists($this->id, $rev)) {
85                $form->addCheckbox('rev2[]')->val($rev);
86            } else {
87                $form->addCheckbox('')->val($rev)->attr('disabled', 'disabled');
88            }
89            $form->addHTML(' ');
90
91            $html = implode(' ', [
92                $RevInfo->showEditDate(true),      // edit date and time
93                $RevInfo->showIconCompareWithCurrent(),  // link to diff view icon
94                $RevInfo->showFileName(),          // name of page or media
95                $RevInfo->showEditSummary(),       // edit summary
96                $RevInfo->showEditor(),            // editor info
97                $RevInfo->showSizechange(),        // size change indicator
98                $RevInfo->showCurrentIndicator(),  // current indicator (only when k=1)
99            ]);
100            $form->addHTML($html);
101            $form->addTagClose('div');
102            $form->addTagClose('li');
103        }
104        $form->addTagClose('ul');  // end of revision list
105
106        // show button for diff view
107        $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit');
108
109        $form->addTagClose('div'); // close div class=no
110
111        echo $form->toHTML('Revisions');
112
113        // provide navigation for paginated revision list (of pages and/or media files)
114        echo $this->navigation($first, $hasNext, static fn($n) => ['do' => 'revisions', 'first' => $n]);
115    }
116}
117