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