preference['fromAjax'] = false; // see dokuwiki\Ajax::callMediadiff() $this->preference['showIntro'] = false; $this->preference['difftype'] = 'both'; // diff view type: both, opacity or portions parent::__construct($id); } /** @inheritdoc */ protected function setChangeLog() { $this->changelog = new MediaChangeLog($this->id); } /** * Handle requested revision(s) and diff view preferences * * @return void */ protected function handle() { global $INPUT; // retrieve requested rev or rev2 parent::handle(); // requested diff view type if ($INPUT->has('difftype')) { $this->preference['difftype'] = $INPUT->str('difftype'); } } /** * Prepare revision info of comparison pair */ protected function preProcess() { $changelog =& $this->changelog; // create revision info object for older and newer sides // Rev1 : older, left side // Rev2 : newer, right side $this->Rev1 = new RevisionInfo($changelog->getRevisionInfo($this->rev1)); $this->Rev2 = new RevisionInfo($changelog->getRevisionInfo($this->rev2)); [$Rev1, $Rev2] = [$this->Rev1, $this->Rev2]; $this->is_img = preg_match('/\.(jpe?g|gif|png)$/', $this->id); foreach ([$Rev1, $Rev2] as $Revision) { $isCurrent = $changelog->isCurrentRevision($Revision->val('date')); $Revision->isCurrent($isCurrent); if ($this->is_img) { $rev = $isCurrent ? '' : $Revision->val('date'); $meta = new JpegMeta(mediaFN($this->id, $rev)); // get image width and height for the media manager preview panel $Revision->append([ 'previewSize' => media_image_preview_size($this->id, $rev, $meta) ]); } } // re-check image, ensure minimum image width for showImageDiff() $this->is_img = ($this->is_img && ($Rev1->val('previewSize')[0] ?? 0) >= 30 && ($Rev2->val('previewSize')[0] ?? 0) >= 30 ); // adjust requested diff view type if (!$this->is_img) { $this->preference['difftype'] = 'both'; } } /** * Shows difference between two revisions of media * * @author Kate Arzamastseva */ public function show() { global $conf; $ns = getNS($this->id); $auth = auth_quickaclcheck("$ns:*"); if ($auth < AUTH_READ || !$this->id || !$conf['mediarevisions']) return; // retrieve form parameters: rev, rev2, difftype $this->handle(); // prepare revision info of comparison pair $this->preProcess(); // display intro if ($this->preference['showIntro']) echo p_locale_xhtml('diff'); // print form to choose diff view type if ($this->is_img && !$this->preference['fromAjax']) { $this->showDiffViewSelector(); echo '
'; } switch ($this->preference['difftype']) { case 'opacity': case 'portions': $this->showImageDiff(); break; case 'both': default: $this->showFileDiff(); break; } if ($this->is_img && !$this->preference['fromAjax']) { echo '
'; } } /** * Print form to choose diff view type * the dropdown is to be added through JavaScript, see lib/scripts/media.js */ protected function showDiffViewSelector() { // revision information object [$Rev1, $Rev2] = [$this->Rev1, $this->Rev2]; echo '
'; $form = new Form([ 'id' => 'mediamanager__form_diffview', 'action' => media_managerURL([], '&'), 'method' => 'get', 'class' => 'diffView', ]); $form->addTagOpen('div')->addClass('no'); $form->setHiddenField('sectok', null); $form->setHiddenField('mediado', 'diff'); $form->setHiddenField('rev2[0]', (int)$Rev1->val('date')); $form->setHiddenField('rev2[1]', (int)$Rev2->val('date')); $form->addTagClose('div'); echo $form->toHTML(); echo '
'; // .diffoptions } /** * Prints two images side by side * and slider * * @author Kate Arzamastseva */ protected function showImageDiff() { // revision information object [$Rev1, $Rev2] = [$this->Rev1, $this->Rev2]; $rev1 = $Rev1->isCurrent() ? '' : $Rev1->val('date'); $rev2 = $Rev2->isCurrent() ? '' : $Rev2->val('date'); // diff view type: opacity or portions $type = $this->preference['difftype']; // adjust image width, right side (newer) has priority $rev1Size = $Rev1->val('previewSize'); $rev2Size = $Rev2->val('previewSize'); if ($rev1Size != $rev2Size) { if ($rev2Size[0] > $rev1Size[0]) { $rev1Size = $rev2Size; } } $rev1Src = ml($this->id, ['rev' => $rev1, 'h' => $rev1Size[1], 'w' => $rev1Size[0]]); $rev2Src = ml($this->id, ['rev' => $rev2, 'h' => $rev1Size[1], 'w' => $rev1Size[0]]); // slider echo '
'; // two images in divs echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo ''; echo '
'; echo '
'; } /** * Shows difference between two revisions of media file * * @author Kate Arzamastseva */ protected function showFileDiff() { global $lang; $ns = getNS($this->id); $auth = auth_quickaclcheck("$ns:*"); // revision information object [$Rev1, $Rev2] = [$this->Rev1, $this->Rev2]; $rev1 = $Rev1->isCurrent() ? '' : (int)$Rev1->val('date'); $rev2 = $Rev2->isCurrent() ? '' : (int)$Rev2->val('date'); // revision title $rev1Title = trim($Rev1->showRevisionTitle() .' '. $Rev1->showCurrentIndicator()); $rev1Supple = ($Rev1->val('date')) ? $Rev1->showEditSummary() .' '. $Rev1->showEditor() : ''; $rev2Title = trim($Rev2->showRevisionTitle() .' '. $Rev2->showCurrentIndicator()); $rev2Supple = ($Rev2->val('date')) ? $Rev2->showEditSummary() .' '. $Rev2->showEditor() : ''; $rev1Meta = new JpegMeta(mediaFN($this->id, $rev1)); $rev2Meta = new JpegMeta(mediaFN($this->id, $rev2)); // display diff view table echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $rev1Tags = media_file_tags($rev1Meta); $rev2Tags = media_file_tags($rev2Meta); // FIXME rev2Tags-only stuff ignored foreach ($rev1Tags as $key => $tag) { if ($tag['value'] != $rev2Tags[$key]['value']) { $rev2Tags[$key]['highlighted'] = true; $rev1Tags[$key]['highlighted'] = true; } elseif (!$tag['value'] || !$rev2Tags[$key]['value']) { unset($rev2Tags[$key]); unset($rev1Tags[$key]); } } echo ''; foreach ([$rev1Tags, $rev2Tags] as $tags) { echo ''; } echo ''; echo '
'. $rev1Title .' '. $rev1Supple .''. $rev2Title .' '. $rev2Supple .'
'; media_preview($this->id, $auth, $rev1, $rev1Meta); // $auth not used in media_preview()? echo ''; media_preview($this->id, $auth, $rev2, $rev2Meta); echo '
'; media_preview_buttons($this->id, $auth, $rev1); // $auth used in media_preview_buttons() echo ''; media_preview_buttons($this->id, $auth, $rev2); echo '
'; echo '
'; foreach ($tags as $tag) { $value = cleanText($tag['value']); if (!$value) $value = '-'; echo '
'.$lang[$tag['tag'][1]].'
'; echo '
'; if (!empty($tag['highlighted'])) echo ''; if ($tag['tag'][2] == 'date') { echo dformat($value); } else { echo hsc($value); } if (!empty($tag['highlighted'])) echo ''; echo '
'; } echo '
'; echo '
'; echo '
'; } }