xref: /dokuwiki/inc/Ui/MediaRevisions.php (revision e937d00471b8194e1dc5cf14501b68d8840212a3)
1<?php
2
3namespace dokuwiki\Ui;
4
5use dokuwiki\ChangeLog\MediaChangeLog;
6use dokuwiki\Form\Form;
7
8/**
9 * DokuWiki MediaRevisions Interface
10 *
11 * @package dokuwiki\Ui
12 */
13class MediaRevisions extends Revisions
14{
15    /* @var MediaChangeLog */
16    protected $changelog;
17
18    /**
19     * MediaRevisions Ui constructor
20     *
21     * @param string $id  id of media
22     */
23    public function __construct($id)
24    {
25        if (!$id) {
26            throw new \InvalidArgumentException('media id should not be empty!');
27        }
28        parent::__construct($id);
29    }
30
31    /** @inheritdoc */
32    protected function setChangeLog()
33    {
34        $this->changelog = new MediaChangeLog($this->id);
35    }
36
37    /**
38     * Display a list of Media Revisions in the MediaManager
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;
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        // create the form
59        $form = new Form([
60                'id' => 'page__revisions', // must not be "media__revisions"
61                'action' => media_managerURL(['image' => $this->id], '&'),
62                'class'  => 'changes',
63        ]);
64        $form->setHiddenField('mediado', 'diff'); // required for media revisions
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 (file_exists(mediaFN($this->id, $rev))) {
78                $form->addCheckbox('rev2[]')->val($rev);
79            } else {
80                $form->addCheckbox('')->val($rev)->attr('disabled','disabled');
81            }
82            $form->addHTML(' ');
83
84            $objRevInfo = $this->getObjRevInfo($info);
85            $html = implode(' ', [
86                $objRevInfo->editDate(),          // edit date and time
87                $objRevInfo->difflink(),          // link to diffview icon
88                $objRevInfo->itemName(),          // name of page or media
89                '<div>',
90                $objRevInfo->editSummary(),       // edit summary
91                $objRevInfo->editor(),            // editor info
92                $objRevInfo->sizechange(),        // size change indicator
93                $objRevInfo->currentIndicator(),  // current indicator (only when k=1)
94                '</div>',
95            ]);
96            $form->addHTML($html);
97
98            $form->addTagClose('div');
99            $form->addTagClose('li');
100        }
101        $form->addTagClose('ul');  // end of revision list
102
103        // show button for diff view
104        $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit');
105
106        $form->addTagClose('div'); // close div class=no
107
108        print $form->toHTML('Revisions');
109
110        // provide navigation for pagenated revision list (of pages and/or media files)
111        print $this->navigation($first, $hasNext, function ($n) {
112            return media_managerURL(['first' => $n], '&', false, true);
113        });
114    }
115
116}
117