id = $id;
}
/**
* Gets or Sets preference of the Ui\Diff object
*
* @param string|array $prefs a key name or key-value pair(s)
* @param mixed $value value used when the first args is string
* @return array|$this
*/
public function preference($prefs = null, $value = null)
{
// set
if (is_array($prefs)) {
foreach ($prefs as $name => $value) {
$this->preference[$name] = $value;
}
return $this;
} elseif (is_string($prefs) && isset($value)) {
$this->preference[$prefs] = $value;
return $this;
}
// get
return $this->preference;
}
/**
* Get header of diff HTML
*
* @param ChangeLog $changelog PageChangeLog or MediaChangeLog object
* @param string $l_rev Left revisions
* @param string $r_rev Right revision
* @param string $id Page id, if null $ID is used // クラスプロパティを使用するべき
* @param bool $media If it is for media files // changelog object を渡せばよいのは?
* @param bool $inline Return the header on a single line // クラスプロパティを使用するべき
* @return string[] HTML snippets for diff header
*/
public function diffHead($changelog, $l_rev, $r_rev)
{
global $lang;
// detect PageDiff or MediaDiff
switch (get_class($changelog)) {
case PageChangeLog::class :
$media_or_wikiFN = 'wikiFN';
$ml_or_wl = 'wl';
$media = false;
break;
case MediaChangeLog::class :
$media_or_wikiFN = 'mediaFN';
$ml_or_wl = 'ml';
$media = true;
break;
}
$head_separator = ($this->preference['difftype'] === 'inline') ? ' ' : '
';
$l_minor = $r_minor = '';
// left side
if (!$l_rev) {
$l_head = '—';
} else {
$l_info = $changelog->getRevisionInfo($l_rev);
if ($l_info['user']) {
$l_user = ''.editorinfo($l_info['user']).'';
if (auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
} else {
$l_user = ''.$l_info['ip'].'';
}
$l_user = ''.$l_user.'';
$l_sum = ($l_info['sum']) ? ''.hsc($l_info['sum']).'' : '';
if ($l_info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
$l_head_title = ($media) ? dformat($l_rev) : $this->id.' ['.dformat($l_rev).']';
$l_head = ''
. $l_head_title.''.$head_separator.$l_user.' '.$l_sum;
}
// right side
if ($r_rev) {
$r_info = $changelog->getRevisionInfo($r_rev);
if ($r_info['user']) {
$r_user = ''.editorinfo($r_info['user']).'';
if (auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
} else {
$r_user = ''.$r_info['ip'].'';
}
$r_user = ''.$r_user.'';
$r_sum = ($r_info['sum']) ? ''.hsc($r_info['sum']).'' : '';
if ($r_info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
$r_head_title = ($media) ? dformat($r_rev) : $this->id.' ['.dformat($r_rev).']';
$r_head = ''
. $r_head_title.''.$head_separator.$r_user.' '.$r_sum;
} elseif ($_rev = @filemtime($media_or_wikiFN($this->id))) {
$_info = $changelog->getRevisionInfo($_rev);
if ($_info['user']) {
$_user = ''.editorinfo($_info['user']).'';
if (auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
} else {
$_user = ''.$_info['ip'].'';
}
$_user = ''.$_user.'';
$_sum = ($_info['sum']) ? ''.hsc($_info['sum']).'' : '';
if ($_info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
$r_head_title = ($media) ? dformat($_rev) : $this->id.' ['.dformat($_rev).']';
$r_head = ''
. $r_head_title.' '.'('.$lang['current'].')'.$head_separator.$_user.' '.$_sum;
}else{
$r_head = '— ('.$lang['current'].')';
}
return array($l_head, $r_head, $l_minor, $r_minor);
}
}