Skip to content

Commit

Permalink
add events DIFF_RENDER and DIFF_TYPES
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfromearth committed Nov 14, 2021
1 parent d5824ab commit f98e218
Showing 1 changed file with 62 additions and 43 deletions.
105 changes: 62 additions & 43 deletions inc/Ui/PageDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use dokuwiki\ChangeLog\PageChangeLog;
use dokuwiki\Form\Form;
use dokuwiki\Extension\Event;

/**
* DokuWiki PageDiff Interface
Expand Down Expand Up @@ -32,12 +33,19 @@ class PageDiff extends Diff
public function __construct($id = null)
{
global $INFO;
global $lang;
if (!isset($id)) $id = $INFO['id'];

// init preference
$this->preference['showIntro'] = true;
$this->preference['difftype'] = 'sidebyside'; // diff view type: inline or sidebyside

$this->difftypes = array(
'sidebyside' => $lang['diff_side'],
'inline' => $lang['diff_inline'],
);
Event::createAndTrigger('DIFF_TYPES', $this->difftypes);

parent::__construct($id);
}

Expand Down Expand Up @@ -199,51 +207,65 @@ public function show()
echo '<div class="table">';
echo '<table class="diff diff_'.$this->preference['difftype'] .'">';

//navigation and header
switch ($this->preference['difftype']) {
case 'inline':
if ($this->newRevInfo['rev'] !== false) {
$eventData = [
'difftype' => $this->preference['difftype'],
'oldRevInfo' => $this->oldRevInfo,
'newRevInfo' => $this->newRevInfo,
'classEditType' => $classEditType,
'navOlderRevisions' => $navOlderRevisions,
'navNewerRevisions' => $navNewerRevisions,
];
$diffEvent = new Event('DIFF_RENDER', $eventData);

This comment has been minimized.

Copy link
@Klap-in

Klap-in Nov 14, 2021

Maybe DIFF_DATA_OUTPUT, DIFF_REV_OUTPUT, DIFF_OLDNEWREV_OUTPUT are bit more descriptive names for this event? See also for a definition https://www.dokuwiki.org/devel:events_list#naming_structure

In the default action of this event the final html of the navigation, header and the actual diff view are outputted, they aren’t?

if($diffEvent->advise_before()) {
//default diff view
//navigation and header
switch ($this->preference['difftype']) {
case 'inline':
if ($this->newRevInfo['rev'] !== false) {
echo '<tr>'
.'<td class="diff-lineheader">-</td>'
.'<td class="diffnav">'. $navOlderRevisions .'</td>'
.'</tr>';
echo '<tr>'
.'<th class="diff-lineheader">-</th>'
.'<th'.$classEditType($this->oldRevInfo).'>'.$this->oldRevInfo['navTitle'].'</th>'
.'</tr>';
}
echo '<tr>'
.'<td class="diff-lineheader">-</td>'
.'<td class="diffnav">'. $navOlderRevisions .'</td>'
.'<td class="diff-lineheader">+</td>'
.'<td class="diffnav">'. $navNewerRevisions .'</td>'
.'</tr>';
echo '<tr>'
.'<th class="diff-lineheader">-</th>'
.'<th'.$classEditType($this->oldRevInfo).'>'.$this->oldRevInfo['navTitle'].'</th>'
.'<th class="diff-lineheader">+</th>'
.'<th'.$classEditType($this->newRevInfo).'>'.$this->newRevInfo['navTitle'].'</th>'
.'</tr>';
}
echo '<tr>'
.'<td class="diff-lineheader">+</td>'
.'<td class="diffnav">'. $navNewerRevisions .'</td>'
.'</tr>';
echo '<tr>'
.'<th class="diff-lineheader">+</th>'
.'<th'.$classEditType($this->newRevInfo).'>'.$this->newRevInfo['navTitle'].'</th>'
.'</tr>';
// create formatter object
$DiffFormatter = new \InlineDiffFormatter();
break;

case 'sidebyside':
default:
if ($this->newRevInfo['rev'] !== false) {
// create formatter object
$DiffFormatter = new \InlineDiffFormatter();
break;

case 'sidebyside':
default:
if ($this->newRevInfo['rev'] !== false) {
echo '<tr>'
.'<td colspan="2" class="diffnav">'. $navOlderRevisions .'</td>'
.'<td colspan="2" class="diffnav">'. $navNewerRevisions .'</td>'
.'</tr>';
}
echo '<tr>'
.'<td colspan="2" class="diffnav">'. $navOlderRevisions .'</td>'
.'<td colspan="2" class="diffnav">'. $navNewerRevisions .'</td>'
.'<th colspan="2"'.$classEditType($this->oldRevInfo).'>'.$this->oldRevInfo['navTitle'].'</th>'
.'<th colspan="2"'.$classEditType($this->newRevInfo).'>'.$this->newRevInfo['navTitle'].'</th>'
.'</tr>';
}
echo '<tr>'
.'<th colspan="2"'.$classEditType($this->oldRevInfo).'>'.$this->oldRevInfo['navTitle'].'</th>'
.'<th colspan="2"'.$classEditType($this->newRevInfo).'>'.$this->newRevInfo['navTitle'].'</th>'
.'</tr>';
// create formatter object
$DiffFormatter = new \TableDiffFormatter();
break;
}

// output formatted difference
echo $this->insertSoftbreaks($DiffFormatter->format($Difference));

// create formatter object
$DiffFormatter = new \TableDiffFormatter();
break;
}

// output formatted difference
echo $this->insertSoftbreaks($DiffFormatter->format($Difference));

}
$diffEvent->advise_after();
unset($diffEvent);
echo '</table>';
echo '</div>';
}
Expand Down Expand Up @@ -313,10 +335,7 @@ protected function showDiffViewSelector()
$form->setHiddenField('rev2[0]', $oldRev);
$form->setHiddenField('rev2[1]', $newRev);
$form->setHiddenField('do', 'diff');
$options = array(
'sidebyside' => $lang['diff_side'],
'inline' => $lang['diff_inline'],
);
$options = $this->difftypes;
$input = $form->addDropdown('difftype', $options, $lang['diff_type'])
->val($this->preference['difftype'])
->addClass('quickselect');
Expand Down

0 comments on commit f98e218

Please sign in to comment.