xref: /dokuwiki/inc/Ui/MediaRevisions.php (revision f7711f2b85e327b7a52627930dff9288aa2482cf)
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            $info['current'] = $changelog->isCurrentRevision($rev);
72
73            $class = ($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : '';
74            $form->addTagOpen('li')->addClass($class);
75            $form->addTagOpen('div')->addClass('li');
76
77            if (isset($info['current'])) {
78                $form->addCheckbox('rev2[]')->val($rev);
79            } elseif (file_exists(mediaFN($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                '<div>',
92                $objRevInfo->editSummary(),       // edit summary
93                $objRevInfo->editor(),            // editor info
94                $objRevInfo->sizechange(),        // size change indicator
95                $objRevInfo->currentIndicator(),  // current indicator (only when k=1)
96                '</div>',
97            ]);
98            $form->addHTML($html);
99
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 pagenated revision list (of pages and/or media files)
113        print $this->navigation($first, $hasNext, function ($n) {
114            return media_managerURL(['first' => $n], '&', false, true);
115        });
116    }
117
118}
119