renamed difflinkRevision
[dokuwiki.git] / inc / Ui / MediaRevisions.php
blobc562401ba6ff189f9a3be8ad89a1a7e0bbfbffa0
1 <?php
3 namespace dokuwiki\Ui;
5 use dokuwiki\ChangeLog\MediaChangeLog;
6 use dokuwiki\ChangeLog\RevisionInfo;
7 use dokuwiki\Form\Form;
8 use InvalidArgumentException;
10 /**
11 * DokuWiki MediaRevisions Interface
13 * @package dokuwiki\Ui
15 class MediaRevisions extends Revisions
17 /* @var MediaChangeLog */
18 protected $changelog;
20 /**
21 * MediaRevisions Ui constructor
23 * @param string $id id of media
25 public function __construct($id)
27 if (!$id) {
28 throw new InvalidArgumentException('media id should not be empty!');
30 parent::__construct($id);
33 /** @inheritdoc */
34 protected function setChangeLog()
36 $this->changelog = new MediaChangeLog($this->id);
39 /**
40 * Display a list of Media Revisions in the MediaManager
42 * @author Andreas Gohr <andi@splitbrain.org>
43 * @author Ben Coburn <btcoburn@silicodon.net>
44 * @author Kate Arzamastseva <pshns@ukr.net>
45 * @author Satoshi Sahara <sahara.satoshi@gmail.com>
47 * @param int $first skip the first n changelog lines
48 * @return void
50 public function show($first = 0)
52 global $lang;
53 $changelog =& $this->changelog;
55 // get revisions, and set correct pagenation parameters (first, hasNext)
56 if ($first === null) $first = 0;
57 $hasNext = false;
58 $revisions = $this->getRevisions($first, $hasNext);
60 // create the form
61 $form = new Form([
62 'id' => 'page__revisions', // must not be "media__revisions"
63 'action' => media_managerURL(['image' => $this->id], '&'),
64 'class' => 'changes',
65 ]);
66 $form->setHiddenField('mediado', 'diff'); // required for media revisions
67 $form->addTagOpen('div')->addClass('no');
69 // start listing
70 $form->addTagOpen('ul');
71 foreach ($revisions as $info) {
72 $rev = $info['date'];
73 $info['current'] = $changelog->isCurrentRevision($rev);
75 $class = ($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : '';
76 $form->addTagOpen('li')->addClass($class);
77 $form->addTagOpen('div')->addClass('li');
79 if (isset($info['current'])) {
80 $form->addCheckbox('rev2[]')->val($rev);
81 } elseif (file_exists(mediaFN($this->id, $rev))) {
82 $form->addCheckbox('rev2[]')->val($rev);
83 } else {
84 $form->addCheckbox('')->val($rev)->attr('disabled','disabled');
86 $form->addHTML(' ');
88 $RevInfo = new RevisionInfo($info);
89 $html = implode(' ', [
90 $RevInfo->editDate(), // edit date and time
91 $RevInfo->difflinkRevision(), // link to diffview icon
92 $RevInfo->itemName(), // name of page or media
93 '<div>',
94 $RevInfo->editSummary(), // edit summary
95 $RevInfo->editor(), // editor info
96 $RevInfo->sizechange(), // size change indicator
97 $RevInfo->currentIndicator(), // current indicator (only when k=1)
98 '</div>',
99 ]);
100 $form->addHTML($html);
102 $form->addTagClose('div');
103 $form->addTagClose('li');
105 $form->addTagClose('ul'); // end of revision list
107 // show button for diff view
108 $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit');
110 $form->addTagClose('div'); // close div class=no
112 print $form->toHTML('Revisions');
114 // provide navigation for pagenated revision list (of pages and/or media files)
115 print $this->navigation($first, $hasNext, function ($n) {
116 return media_managerURL(['first' => $n], '&', false, true);