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