Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add events DIFF_RENDER and DIFF_TYPES to add new diff renderer via plugin #3547

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 30 additions & 9 deletions inc/Ui/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Diff extends Ui
protected $text;
protected $showIntro;
protected $difftype;
protected $difftypes;

/**
* Diff Ui constructor
Expand All @@ -27,8 +28,16 @@ class Diff extends Ui
*/
public function __construct($text = '', $showIntro = true, $difftype = null)
{
global $lang;

$this->text = $text;
$this->showIntro = $showIntro;

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

// determine diff view type
if (isset($difftype)) {
Expand All @@ -41,7 +50,8 @@ public function __construct($text = '', $showIntro = true, $difftype = null)
$this->difftype = 'inline';
}
}
if ($this->difftype !== 'inline') $this->difftype = 'sidebyside';
if (!isset($this->difftypes[$this->difftype])) $this->difftype = 'sidebyside';

}

/**
Expand Down Expand Up @@ -167,10 +177,7 @@ public function show()
$form->setHiddenField('rev2[0]', $l_rev);
$form->setHiddenField('rev2[1]', $r_rev);
$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->difftype)->addClass('quickselect');
$input->useInput(false); // inhibit prefillInput() during toHTML() process
Expand Down Expand Up @@ -223,10 +230,24 @@ public function show()
. '<th colspan="2" '. $r_minor .'>'. $r_head .'</th>'
. '</tr>';
}

//diff view
print $this->insertSoftbreaks($diffformatter->format($diff));


$eventData = [
'difftype' => $this->difftype,
'diff' => $diff,
'diffformatter' => $diffformatter,
'l_text' => $l_text,
'r_text' => $r_text,
'l_rev' => $l_rev,
'r_rev' => $r_rev,
];
$diffEvent = new Event('DIFF_RENDER', $eventData);
if($diffEvent->advise_before()) {
//diff view
echo $this->insertSoftbreaks($diffformatter->format($diff));
}
$diffEvent->advise_after();
unset($diffEvent);

print '</table>';
print '</div>';
}
Expand Down