/** * Does the actual work. * * @param string[] $path * @param DiffOp $op * * @return string * @throws MWException */ private function generateOpHtml(array $path, DiffOp $op) { if ($op->isAtomic()) { $html = $this->generateDiffHeaderHtml(implode(' / ', $path)); //TODO: no path, but localized section title //FIXME: complex objects as values? if ($op->getType() === 'add') { /** @var DiffOpAdd $op */ $html .= $this->generateChangeOpHtml(null, $op->getNewValue(), $path); } elseif ($op->getType() === 'remove') { /** @var DiffOpRemove $op */ $html .= $this->generateChangeOpHtml($op->getOldValue(), null, $path); } elseif ($op->getType() === 'change') { /** @var DiffOpChange $op */ $html .= $this->generateChangeOpHtml($op->getOldValue(), $op->getNewValue(), $path); } else { throw new MWException('Invalid diffOp type'); } } else { $html = ''; foreach ($op as $key => $subOp) { $html .= $this->generateOpHtml(array_merge($path, array($key)), $subOp); } } return $html; }
/** * Returns the HTML for a single claim DiffOp. * * @since 0.4 * * @param DiffOp $claimDiffOp * * @return string * @throws MWException */ protected function getClaimDiffHtml(DiffOp $claimDiffOp) { if ($claimDiffOp instanceof DiffOpChange) { $claimDifference = $this->claimDiffer->diffClaims($claimDiffOp->getOldValue(), $claimDiffOp->getNewValue()); return $this->claimDiffVisualizer->visualizeClaimChange($claimDifference, $claimDiffOp->getNewValue()); } if ($claimDiffOp instanceof DiffOpAdd) { return $this->claimDiffVisualizer->visualizeNewClaim($claimDiffOp->getNewValue()); } elseif ($claimDiffOp instanceof DiffOpRemove) { return $this->claimDiffVisualizer->visualizeRemovedClaim($claimDiffOp->getOldValue()); } else { throw new MWException('Encountered an unexpected diff operation type for a claim'); } }
/** * @param DiffOp $diffOp * @param string $action e.g. 'remove', see the constants in EntityChange * @param string $siteId * @param Title|null $title The page we create an edit summary for * * @return array|null */ private function getSiteLinkAddRemoveParams(DiffOp $diffOp, $action, $siteId, Title $title = null) { $params = array(); if (in_array($action, array('remove', 'restore'))) { // Messages: wikibase-comment-remove, wikibase-comment-restore $params['message'] = 'wikibase-comment-' . $action; } elseif ($diffOp instanceof DiffOpAdd) { $params['message'] = 'wikibase-comment-linked'; } elseif ($diffOp instanceof DiffOpRemove) { $params['message'] = 'wikibase-comment-unlink'; } elseif ($diffOp instanceof DiffOpChange) { if ($title && $title->getPrefixedText() === $diffOp->getOldValue()) { $params['message'] = 'wikibase-comment-unlink'; } elseif ($title && $title->getPrefixedText() === $diffOp->getNewValue()) { $params['message'] = 'wikibase-comment-linked'; } else { $params['message'] = 'wikibase-comment-sitelink-change'; $params['sitelink'] = array('oldlink' => array('site' => $siteId, 'page' => $diffOp->getOldValue()), 'newlink' => array('site' => $siteId, 'page' => $diffOp->getNewValue())); } } else { // whatever $params = null; } return $params; }