Failed Conditions
Pull Request — master (#3361)
by
unknown
03:00
created

MediaRevisions::itemFN()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 4
c 0
b 0
f 0
cc 1
nop 2
rs 10
1
<?php
2
3
namespace dokuwiki\Ui;
4
5
use dokuwiki\ChangeLog\MediaChangeLog;
6
use dokuwiki\Form\Form;
7
8
/**
9
 * DokuWiki MediaRevisions Interface
10
 *
11
 * @package dokuwiki\Ui
12
 */
13
class 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
        $this->item = 'media';
29
        parent::__construct($id);
30
    }
31
32
    /** @inheritdoc */
33
    protected function setChangeLog()
34
    {
35
        $this->changelog = new MediaChangeLog($this->id);
36
    }
37
38
    /** @inheritdoc */
39
    protected function itemFN($id, $rev = '')
40
    {
41
        return mediaFN($id, $rev);
42
    }
43
44
    /**
45
     * Display a list of Media Revisions in the MediaManager
46
     *
47
     * @author Andreas Gohr <[email protected]>
48
     * @author Ben Coburn <[email protected]>
49
     * @author Kate Arzamastseva <[email protected]>
50
     * @author Satoshi Sahara <[email protected]>
51
     *
52
     * @param int $first  skip the first n changelog lines
53
     * @return void
54
     */
55
    public function show($first = 0)
56
    {
57
        global $lang;
58
59
        // get revisions, and set correct pagenation parameters (first, hasNext)
60
        if ($first === null) $first = 0;
61
        $hasNext = false;
62
        $revisions = $this->getRevisions($first, $hasNext);
63
64
        // create the form
65
        $form = new Form([
66
                'id' => 'page__revisions', // must not be "media__revisions"
67
                'action' => media_managerURL(['image' => $this->id], '&'),
68
                'class'  => 'changes',
69
        ]);
70
        $form->setHiddenField('mediado', 'diff'); // required for media revisions
71
        $form->addTagOpen('div')->addClass('no');
72
73
        // start listing
74
        $form->addTagOpen('ul');
75
        foreach ($revisions as $info) {
76
            $rev = $info['date'];
77
            $class = ($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : '';
78
            $form->addTagOpen('li')->addClass($class);
79
            $form->addTagOpen('div')->addClass('li');
80
81
            if (isset($info['current'])) {
82
               $form->addCheckbox('rev2[]')->val('current');
83
            } elseif (file_exists(mediaFN($this->id, $rev))) {
84
                $form->addCheckbox('rev2[]')->val($rev);
85
            } else {
86
                $form->addCheckbox('')->val($rev)->attr('disabled','disabled');
87
            }
88
            $form->addHTML(' ');
89
90
            $objRevInfo = $this->getObjRevInfo($info);
91
            $html = implode(' ', [
92
                $objRevInfo->editDate(),          // edit date and time
93
                $objRevInfo->difflink(),          // link to diffview icon
94
                $objRevInfo->itemName(),          // name of page or media
95
                '<div>',
96
                $objRevInfo->editSummary(),       // edit summary
97
                $objRevInfo->editor(),            // editor info
98
                $objRevInfo->sizechange(),        // size change indicator
99
                $objRevInfo->currentIndicator(),  // current indicator (only when k=1)
100
                '</div>',
101
            ]);
102
            $form->addHTML($html);
103
104
            $form->addTagClose('div');
105
            $form->addTagClose('li');
106
        }
107
        $form->addTagClose('ul');  // end of revision list
108
109
        // show button for diff view
110
        $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit');
111
112
        $form->addTagClose('div'); // close div class=no
113
114
        print $form->toHTML('Revisions');
115
116
        // provide navigation for pagenated revision list (of pages and/or media files)
117
        print $this->navigation($first, $hasNext, function ($n) {
118
            return media_managerURL(['first' => $n], '&', false, true);
119
        });
120
    }
121
122
}
123