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