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

MediaRevisions::setChangeLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
    /** 
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);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \dokuwiki\ChangeLog\MediaChangeLog($this->id) of type object<dokuwiki\ChangeLog\MediaChangeLog> is incompatible with the declared type object<dokuwiki\Ui\ChangeLog> of property $changelog.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
    }
34
35
    /**
36
     * Display a list of Media Revisions in the MediaManager
37
     *
38
     * @author Andreas Gohr <[email protected]>
39
     * @author Ben Coburn <[email protected]>
40
     * @author Kate Arzamastseva <[email protected]>
41
     * @author Satoshi Sahara <[email protected]>
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