Failed Conditions
Pull Request — master (#3361)
by
unknown
02:55
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
        $this->item = 'media';
23
        parent::__construct($id);
24
    }
25
26
    /** @inheritdoc */
27
    protected function setChangeLog()
28
    {
29
        $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...
30
    }
31
32
    /**
33
     * Display a list of Media Revisions in the MediaManager
34
     *
35
     * @author Andreas Gohr <[email protected]>
36
     * @author Ben Coburn <[email protected]>
37
     * @author Kate Arzamastseva <[email protected]>
38
     * @author Satoshi Sahara <[email protected]>
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