xref: /dokuwiki/inc/Ui/PageRevisions.php (revision 3df364a338f91f787f996b83392bc95fe38abc2c)
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     * @author Andreas Gohr <andi@splitbrain.org>
41     * @author Ben Coburn <btcoburn@silicodon.net>
42     * @author Kate Arzamastseva <pshns@ukr.net>
43     * @author Satoshi Sahara <sahara.satoshi@gmail.com>
44     *
45     * @param int $first  skip the first n changelog lines
46     * @return void
47     */
48    public function show($first = 0)
49    {
50        global $lang, $REV;
51        $changelog =& $this->changelog;
52
53        // get revisions, and set correct pagenation parameters (first, hasNext)
54        if ($first === null) $first = 0;
55        $hasNext = false;
56        $revisions = $this->getRevisions($first, $hasNext);
57
58        // print intro
59        print 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            $info['current'] = $changelog->isCurrentRevision($rev);
73
74            $class = ($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : '';
75            $form->addTagOpen('li')->addClass($class);
76            $form->addTagOpen('div')->addClass('li');
77
78            if (isset($info['current'])) {
79                $form->addCheckbox('rev2[]')->val($rev);
80            } elseif ($rev == $REV) {
81                $form->addCheckbox('rev2[]')->val($rev)->attr('checked','checked');
82            } elseif (page_exists($this->id, $rev)) {
83                $form->addCheckbox('rev2[]')->val($rev);
84            } else {
85                $form->addCheckbox('')->val($rev)->attr('disabled','disabled');
86            }
87            $form->addHTML(' ');
88
89            $RevInfo = new RevisionInfo($info);
90            $html = implode(' ', [
91                $RevInfo->editDate(true),      // edit date and time
92                $RevInfo->difflinkRevision(),  // link to diffview icon
93                $RevInfo->itemName(),          // name of page or media
94                $RevInfo->editSummary(),       // edit summary
95                $RevInfo->editor(),            // editor info
96                $RevInfo->sizechange(),        // size change indicator
97                $RevInfo->currentIndicator(),  // current indicator (only when k=1)
98            ]);
99            $form->addHTML($html);
100            $form->addTagClose('div');
101            $form->addTagClose('li');
102        }
103        $form->addTagClose('ul');  // end of revision list
104
105        // show button for diff view
106        $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit');
107
108        $form->addTagClose('div'); // close div class=no
109
110        print $form->toHTML('Revisions');
111
112        // provide navigation for paginated revision list (of pages and/or media files)
113        print $this->navigation($first, $hasNext, function ($n) {
114            return array('do' => 'revisions', 'first' => $n);
115        });
116    }
117}
118