jenkins-bot has submitted this change and it was merged. Change subject: Diff sitelinks now link to the relevant page ......................................................................
Diff sitelinks now link to the relevant page Bug: 53471 Change-Id: I7e2ae200b0290a0919cf9085d8357bf29dbab4b6 --- M lib/includes/DiffView.php M lib/includes/EntityDiffVisualizer.php M repo/includes/EntityContentDiffView.php M repo/includes/actions/EditEntityAction.php 4 files changed, 117 insertions(+), 129 deletions(-) Approvals: Aude: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/includes/DiffView.php b/lib/includes/DiffView.php index 71a97f7..3ea72ea 100644 --- a/lib/includes/DiffView.php +++ b/lib/includes/DiffView.php @@ -1,39 +1,29 @@ <?php namespace Wikibase; + use Html; use Diff\Diff; use Diff\DiffOp; +use IContextSource; +use MWException; +use SiteStore; /** * Class for generating views of DiffOp objects. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * http://www.gnu.org/copyleft/gpl.html - * * @since 0.1 - * - * @file - * @ingroup WikibaseLib * * @licence GNU GPL v2+ * @author Daniel Kinzler * @author Jeroen De Dauw < [email protected] > * @author Tobias Gritschacher < [email protected] > + * @author Adam Shorland */ class DiffView extends \ContextSource { + + /** @var SiteStore */ + public $siteStore; /** * @since 0.1 @@ -56,15 +46,18 @@ * * @param array $path * @param Diff $diff - * @param \IContextSource|null $contextSource + * @param SiteStore $siteStore + * @param IContextSource|null $contextSource */ - public function __construct( array $path, Diff $diff, \IContextSource $contextSource = null ) { + public function __construct( array $path, Diff $diff, SiteStore $siteStore, IContextSource $contextSource = null ) { $this->path = $path; $this->diff = $diff; + $this->siteStore = $siteStore; if ( !is_null( $contextSource ) ) { $this->setContext( $contextSource ); } + $this->siteStore = $siteStore; } /** @@ -87,23 +80,23 @@ * @param DiffOp $op * * @return string - * @throws \MWException + * @throws MWException */ protected function generateOpHtml( array $path, DiffOp $op ) { if ( $op->isAtomic() ) { $html = $this->generateDiffHeaderHtml( implode( ' / ', $path ) ); - //TODO: no path, but localized section title. + //TODO: no path, but localized section title //FIXME: complex objects as values? if ( $op->getType() === 'add' ) { - $html .= $this->generateAddOpHtml( $op->getNewValue() ); + $html .= $this->generateChangeOpHtml( null, $op->getNewValue(), $path ); } elseif ( $op->getType() === 'remove' ) { - $html .= $this->generateRemoveOpHtml( $op->getOldValue() ); + $html .= $this->generateChangeOpHtml( $op->getOldValue(), null, $path ); } elseif ( $op->getType() === 'change' ) { - $html .= $this->generateChangeOpHtml( $op->getOldValue(), $op->getNewValue() ); + $html .= $this->generateChangeOpHtml( $op->getOldValue(), $op->getNewValue(), $path ); } else { - throw new \MWException( 'Invalid diffOp type' ); + throw new MWException( 'Invalid diffOp type' ); } } else { $html = ''; @@ -119,79 +112,70 @@ } /** - * Generates HTML for an add diffOp - * - * @since 0.4 - * - * @param string $value - * - * @return string - */ - protected function generateAddOpHtml( $value ) { - $html = Html::openElement( 'tr' ); - $html .= Html::rawElement( 'td', array( 'colspan'=>'2' ), ' ' ); - $html .= Html::rawElement( 'td', array( 'class' => 'diff-marker' ), '+' ); - $html .= Html::rawElement( 'td', array( 'class' => 'diff-addedline' ), - Html::rawElement( 'div', array(), - Html::element( 'ins', array( 'class' => 'diffchange diffchange-inline' ), - $value ) ) ); - $html .= Html::closeElement( 'tr' ); - - return $html; - } - - /** - * Generates HTML for an remove diffOp - * - * @since 0.4 - * - * @param string $value - * - * @return string - */ - protected function generateRemoveOpHtml( $value ) { - $html = Html::openElement( 'tr' ); - $html .= Html::rawElement( 'td', array( 'class' => 'diff-marker' ), '-' ); - $html .= Html::rawElement( 'td', array( 'class' => 'diff-deletedline' ), - Html::rawElement( 'div', array(), - Html::element( 'del', array( 'class' => 'diffchange diffchange-inline' ), - $value ) ) ); - $html .= Html::rawElement( 'td', array( 'colspan'=>'2' ), ' ' ); - $html .= Html::closeElement( 'tr' ); - - return $html; - } - - /** * Generates HTML for an change diffOp * * @since 0.4 * - * @param string $oldValue - * @param string $newValue + * @param string|null $oldValue + * @param string|null $newValue + * @param array $path * * @return string */ - protected function generateChangeOpHtml( $oldValue, $newValue ) { + protected function generateChangeOpHtml( $oldValue, $newValue, $path ) { //TODO: use WordLevelDiff! $html = Html::openElement( 'tr' ); - $html .= Html::rawElement( 'td', array( 'class' => 'diff-marker' ), '-' ); - $html .= Html::rawElement( 'td', array( 'class' => 'diff-deletedline' ), - Html::rawElement( 'div', array(), - Html::element( 'del', array( 'class' => 'diffchange diffchange-inline' ), - $oldValue ) ) ); - $html .= Html::rawElement( 'td', array( 'class' => 'diff-marker' ), '+' ); - $html .= Html::rawElement( 'td', array( 'class' => 'diff-addedline' ), - Html::rawElement( 'div', array(), - Html::element( 'ins', array( 'class' => 'diffchange diffchange-inline' ), - $newValue ) ) ); - $html .= Html::closeElement( 'tr' ); + if( $oldValue !== null ){ + $html .= Html::rawElement( 'td', array( 'class' => 'diff-marker' ), '-' ); + $html .= Html::rawElement( 'td', array( 'class' => 'diff-deletedline' ), + Html::rawElement( 'div', array(), $this->getDeletedLine( $oldValue, $path ) ) ); + } + if( $newValue !== null ){ + if( $oldValue === null ){ + $html .= Html::rawElement( 'td', array( 'colspan'=>'2' ), ' ' ); + } + $html .= Html::rawElement( 'td', array( 'class' => 'diff-marker' ), '+' ); + $html .= Html::rawElement( 'td', array( 'class' => 'diff-addedline' ), + Html::rawElement( 'div', array(), $this->getAddedLine( $newValue, $path ) ) ); + } $html .= Html::closeElement( 'tr' ); return $html; } /** + * @param string $value + * @param array $path + * @return string + */ + protected function getDeletedLine( $value, $path ) { + if( $path[0] === $this->getLanguage()->getMessage( 'wikibase-diffview-link' ) ) { + $siteLink = new SiteLink( $this->siteStore->getSite( $path[1] ), $value ); + return Html::rawElement( 'del', array( 'class' => 'diffchange diffchange-inline' ), + Html::element( 'a', array( 'href' => $siteLink->getUrl() ), $value ) + ); + } else { + return Html::element( 'del', array( 'class' => 'diffchange diffchange-inline' ), $value ); + } + } + + /** + * @param string $value + * @param array $path + * @return string + */ + protected function getAddedLine( $value, $path ) { + if( $path[0] === $this->getLanguage()->getMessage( 'wikibase-diffview-link' ) ){ + $siteLink = new SiteLink( $this->siteStore->getSite( $path[1] ), $value ); + return Html::rawElement( 'ins', array( 'class' => 'diffchange diffchange-inline' ), + Html::element( 'a', array( 'href' => $siteLink->getUrl() ), $value ) + ); + } else { + return Html::element( 'ins', array( 'class' => 'diffchange diffchange-inline' ), $value ); + } + } + + /** * Generates HTML for the header of the diff operation * * @since 0.4 diff --git a/lib/includes/EntityDiffVisualizer.php b/lib/includes/EntityDiffVisualizer.php index 7195839..aa4b90a 100644 --- a/lib/includes/EntityDiffVisualizer.php +++ b/lib/includes/EntityDiffVisualizer.php @@ -10,29 +10,12 @@ use Diff\DiffOpChange; use Diff\DiffOpAdd; use Diff\DiffOpRemove; +use SiteStore; /** * Class for generating views of EntityDiff objects. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * http://www.gnu.org/copyleft/gpl.html - * * @since 0.4 - * - * @file - * @ingroup WikibaseLib * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > @@ -62,6 +45,11 @@ private $claimDiffVisualizer; /** + * @var SiteStore + */ + private $siteStore; + + /** * Constructor. * * @since 0.4 @@ -69,12 +57,17 @@ * @param IContextSource $contextSource * @param ClaimDiffer $claimDiffer * @param ClaimDifferenceVisualizer $claimDiffView + * @param SiteStore $siteStore */ - public function __construct( IContextSource $contextSource, ClaimDiffer $claimDiffer, - ClaimDifferenceVisualizer $claimDiffView ) { + public function __construct( IContextSource $contextSource, + ClaimDiffer $claimDiffer, + ClaimDifferenceVisualizer $claimDiffView, + SiteStore $siteStore + ) { $this->context = $contextSource; $this->claimDiffer = $claimDiffer; $this->claimDiffVisualizer = $claimDiffView; + $this->siteStore = $siteStore; } /** @@ -91,11 +84,15 @@ $termDiffVisualizer = new DiffView( array(), - new Diff( array( - $this->context->getLanguage()->getMessage( 'wikibase-diffview-label' ) => $diff->getLabelsDiff(), - $this->context->getLanguage()->getMessage( 'wikibase-diffview-alias' ) => $diff->getAliasesDiff(), - $this->context->getLanguage()->getMessage( 'wikibase-diffview-description' ) => $diff->getDescriptionsDiff(), - ), true ), + new Diff( + array ( + $this->context->getLanguage()->getMessage( 'wikibase-diffview-label' ) => $diff->getLabelsDiff(), + $this->context->getLanguage()->getMessage( 'wikibase-diffview-alias' ) => $diff->getAliasesDiff(), + $this->context->getLanguage()->getMessage( 'wikibase-diffview-description' ) => $diff->getDescriptionsDiff(), + ), + true + ), + $this->siteStore, $this->context ); @@ -109,9 +106,13 @@ if ( $diff instanceof ItemDiff ) { $termDiffVisualizer = new DiffView( array(), - new Diff( array( - $this->context->getLanguage()->getMessage( 'wikibase-diffview-link' ) => $diff->getSiteLinkDiff(), - ), true ), + new Diff( + array ( + $this->context->getLanguage()->getMessage( 'wikibase-diffview-link' ) => $diff->getSiteLinkDiff(), + ), + true + ), + $this->siteStore, $this->context ); diff --git a/repo/includes/EntityContentDiffView.php b/repo/includes/EntityContentDiffView.php index 7968141..2765018 100644 --- a/repo/includes/EntityContentDiffView.php +++ b/repo/includes/EntityContentDiffView.php @@ -7,6 +7,10 @@ use Diff\ListDiffer; use Content; use Html; +use Linker; +use ParserOptions; +use Revision; +use SiteSQLStore; use ValueFormatters\FormatterOptions; use ValueFormatters\ValueFormatter; use Wikibase\Lib\EntityIdLabelFormatter; @@ -66,12 +70,12 @@ /** * Get a header for a specified revision. * - * @param $rev \Revision + * @param $rev Revision * @param $complete String: 'complete' to get the header wrapped depending * the visibility of the revision and a link to edit the page. * @return String HTML fragment */ - protected function getRevisionHeader( \Revision $rev, $complete = '' ) { + protected function getRevisionHeader( Revision $rev, $complete = '' ) { //NOTE: This must be kept in sync with the parent implementation. // Perhaps some parts could be factored out to reduce code duplication. @@ -95,10 +99,10 @@ $title = $rev->getTitle(); - $header = \Linker::linkKnown( $title, $header, array(), + $header = Linker::linkKnown( $title, $header, array(), array( 'oldid' => $rev->getID() ) ); - if ( $rev->userCan( \Revision::DELETED_TEXT, $user ) ) { + if ( $rev->userCan( Revision::DELETED_TEXT, $user ) ) { if ( $title->quickUserCan( 'edit', $user ) ) { if ( $rev->isCurrent() ) { $editQuery = array( 'action' => 'edit' ); @@ -109,10 +113,10 @@ $msg = $this->msg( 'wikibase-restoreold' )->escaped(); } - $header .= ' (' . \Linker::linkKnown( $title, $msg, array(), $editQuery ) . ')'; + $header .= ' (' . Linker::linkKnown( $title, $msg, array(), $editQuery ) . ')'; } - if ( $rev->isDeleted( \Revision::DELETED_TEXT ) ) { + if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) { $header = Html::rawElement( 'span', array( 'class' => 'history-deleted' ), $header ); } } else { @@ -134,17 +138,15 @@ $diffVisualizer = new EntityDiffVisualizer( $this->getContext(), new ClaimDiffer( new OrderedListDiffer( new ComparableComparer() ) ), - new ClaimDifferenceVisualizer( - $this->propertyNameFormatter, - $this->snakValueFormatter - ) + new ClaimDifferenceVisualizer( $this->propertyNameFormatter, $this->snakValueFormatter ), + SiteSQLStore::newInstance() ); return $diffVisualizer->visualizeDiff( $diff ); } - protected function getParserOutput( \WikiPage $page, \Revision $rev ) { - $parserOptions = \ParserOptions::newFromContext( $this->getContext() ); + protected function getParserOutput( \WikiPage $page, Revision $rev ) { + $parserOptions = ParserOptions::newFromContext( $this->getContext() ); $parserOptions->enableLimitReport(); $parserOptions->setTidy( true ); diff --git a/repo/includes/actions/EditEntityAction.php b/repo/includes/actions/EditEntityAction.php index bab8ce8..8f30f07 100644 --- a/repo/includes/actions/EditEntityAction.php +++ b/repo/includes/actions/EditEntityAction.php @@ -5,8 +5,11 @@ use Diff\Comparer\ComparableComparer; use Diff\OrderedListDiffer; use Html; +use IContextSource; use Linker; use MWException; +use Page; +use SiteSQLStore; use Skin; use Status; use Revision; @@ -30,7 +33,7 @@ */ abstract class EditEntityAction extends ViewEntityAction { - public function __construct( \Page $page, \IContextSource $context = null ) { + public function __construct( Page $page, IContextSource $context = null ) { parent::__construct( $page, $context ); //TODO: proper injection @@ -454,10 +457,8 @@ $diffVisualizer = new EntityDiffVisualizer( $this->getContext(), new ClaimDiffer( new OrderedListDiffer( new ComparableComparer() ) ), - new ClaimDifferenceVisualizer( - $this->propertyNameFormatter, - $this->snakValueFormatter - ) + new ClaimDifferenceVisualizer( $this->propertyNameFormatter, $this->snakValueFormatter ), + SiteSQLStore::newInstance() ); $this->getOutput()->addHTML( $diffVisualizer->visualizeDiff( $diff ) ); -- To view, visit https://gerrit.wikimedia.org/r/90896 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I7e2ae200b0290a0919cf9085d8357bf29dbab4b6 Gerrit-PatchSet: 9 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <[email protected]> Gerrit-Reviewer: Addshore <[email protected]> Gerrit-Reviewer: Aude <[email protected]> Gerrit-Reviewer: Daniel Kinzler <[email protected]> Gerrit-Reviewer: Henning Snater <[email protected]> Gerrit-Reviewer: Jeroen De Dauw <[email protected]> Gerrit-Reviewer: Tobias Gritschacher <[email protected]> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
