xref: /dokuwiki/inc/Ui/MediaRevisions.php (revision 79a2d7845d5e5e48fe3be8f192717de9294aaba5)
1<?php
2
3namespace dokuwiki\Ui;
4
5use dokuwiki\ChangeLog\MediaChangeLog;
6use dokuwiki\Form\Form;
7use InvalidArgumentException;
8
9/**
10 * DokuWiki MediaRevisions Interface
11 *
12 * @package dokuwiki\Ui
13 */
14class MediaRevisions extends Revisions
15{
16    /* @var MediaChangeLog */
17    protected $changelog;
18
19    /**
20     * MediaRevisions Ui constructor
21     *
22     * @param string $id  id of media
23     */
24    public function __construct($id)
25    {
26        if (!$id) {
27            throw new InvalidArgumentException('media id should not be empty!');
28        }
29        parent::__construct($id);
30    }
31
32    /** @inheritdoc */
33    protected function setChangeLog()
34    {
35        $this->changelog = new MediaChangeLog($this->id);
36    }
37
38    /**
39     * Display a list of Media Revisions in the MediaManager
40     *
41     * @author Andreas Gohr <andi@splitbrain.org>
42     * @author Ben Coburn <btcoburn@silicodon.net>
43     * @author Kate Arzamastseva <pshns@ukr.net>
44     * @author Satoshi Sahara <sahara.satoshi@gmail.com>
45     *
46     * @param int $first  skip the first n changelog lines
47     * @return void
48     */
49    public function show($first = 0)
50    {
51        global $lang;
52        $changelog =& $this->changelog;
53
54        // get revisions, and set correct pagenation parameters (first, hasNext)
55        if ($first === null) $first = 0;
56        $hasNext = false;
57        $revisions = $this->getRevisions($first, $hasNext);
58
59        // create the form
60        $form = new Form([
61                'id' => 'page__revisions', // must not be "media__revisions"
62                'action' => media_managerURL(['image' => $this->id], '&'),
63                'class'  => 'changes',
64        ]);
65        $form->setHiddenField('mediado', 'diff'); // required for media revisions
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 (file_exists(mediaFN($this->id, $rev))) {
81                $form->addCheckbox('rev2[]')->val($rev);
82            } else {
83                $form->addCheckbox('')->val($rev)->attr('disabled','disabled');
84            }
85            $form->addHTML(' ');
86
87            $objRevInfo = $this->getObjRevInfo($info);
88            $html = implode(' ', [
89                $objRevInfo->editDate(),          // edit date and time
90                $objRevInfo->difflink(),          // link to diffview icon
91                $objRevInfo->itemName(),          // name of page or media
92                '<div>',
93                $objRevInfo->editSummary(),       // edit summary
94                $objRevInfo->editor(),            // editor info
95                $objRevInfo->sizechange(),        // size change indicator
96                $objRevInfo->currentIndicator(),  // current indicator (only when k=1)
97                '</div>',
98            ]);
99            $form->addHTML($html);
100
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        print $form->toHTML('Revisions');
112
113        // provide navigation for pagenated revision list (of pages and/or media files)
114        print $this->navigation($first, $hasNext, function ($n) {
115            return media_managerURL(['first' => $n], '&', false, true);
116        });
117    }
118
119}
120