jenkins-bot has submitted this change and it was merged. Change subject: (bug 48224) Format site link already used message with correct link ......................................................................
(bug 48224) Format site link already used message with correct link Together with https://gerrit.wikimedia.org/r/#/c/64083/, this would improve error messaging. Change-Id: Ie9daf6bb4094ac8e41a3a874809cedd5ae2031a3 --- M repo/Wikibase.i18n.php M repo/includes/content/ItemContent.php M repo/tests/phpunit/includes/content/ItemContentTest.php 3 files changed, 86 insertions(+), 19 deletions(-) Approvals: Tobias Gritschacher: Looks good to me, but someone else must approve Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php index da1d4a4..a847571 100644 --- a/repo/Wikibase.i18n.php +++ b/repo/Wikibase.i18n.php @@ -102,7 +102,7 @@ 'wikibase-error-constraint-violation-description' => 'There is {{PLURAL:$1|a constraint|constraints}} violation for {{PLURAL:$1|description|descriptions}} "$3" for {{PLURAL:$1|language code|language codes}} "$2".', 'wikibase-error-constraint-violation-aliases' => 'There is {{PLURAL:$1|a constraint|constraints}} violation for {{PLURAL:$1|alias|aliases}} "$3" for {{PLURAL:$1|language code|language codes}} "$2".', - 'wikibase-error-sitelink-already-used' => 'Site link [[$1:$2]] already used by item [[$3]].', + 'wikibase-error-sitelink-already-used' => 'Site link [$1 $2] already used by item [[$3]].', 'wikibase-error-label-not-unique-wikibase-property' => 'Another property ($3) already has label "$1" associated with language code $2', 'wikibase-error-label-not-unique-wikibase-query' => 'Another query ($3) already has label "$1" associated with language code $2', 'wikibase-error-label-not-unique-item' => 'Another item ($3) already has label "$1" and description "$4" associated with language code $2', @@ -611,9 +611,9 @@ * $2 - the violating languages * $3 - the violating string, but this is usually not very useful as the message is usually given in an edit window', # Fuzzy 'wikibase-error-sitelink-already-used' => "Error message shown when an item can't be saved because it contains a site link already used by another item. Parameters: -* $1 is the site id (interwiki prefix); -* $2 is the title on the remote site; -* $3 is the title of the conflicting item.", +* $1 is the url to the remote client page; +* $2 is the title on the remote client site; +* $3 is the item (e.g. Q60) on the repo with the conflicting site link.", 'wikibase-error-label-not-unique-wikibase-property' => 'Error message shown when a user tries to save a property that has a non-unique label. * $1 is label text * $2 is the labels language code @@ -1318,7 +1318,7 @@ 'wikibase-shortcopyrightwarning' => 'Al calcar en "$1", aceuta [[$2|les condiciones d\'usu]] y aceuta ensin vuelta lliberar les sos collaboraciones baxo la $3.', 'wikibase-copyrighttooltip-acknowledge' => 'Aceuto estes condiciones pa les mios futures ediciones. Nun volver a amosar esti mensaxe.', 'wikibase-entityselector-more' => 'más', - 'wikibase-anonymouseditwarning' => "Avisu: Nun anició sesión. + 'wikibase-anonymouseditwarning' => "Avisu: Nun anició sesión. La direición IP quedará rexistrada nel historial d'ediciones de $1.", 'wikibase-restrictionedit-tooltip-message' => 'Esta páxina ta protexida. Nun se permite la edición.', 'wikibase-blockeduser-tooltip-message' => "Nun tien permisu pa editar porque'l so nome d'usuariu o direición IP tan bloquiaos.", diff --git a/repo/includes/content/ItemContent.php b/repo/includes/content/ItemContent.php index 91adc7f..ad10807 100644 --- a/repo/includes/content/ItemContent.php +++ b/repo/includes/content/ItemContent.php @@ -147,27 +147,43 @@ $conflicts = StoreFactory::getStore()->newSiteLinkCache()->getConflictsForItem( $this->getItem(), $db ); foreach ( $conflicts as $conflict ) { - $id = new EntityId( Item::ENTITY_TYPE, $conflict['itemId'] ); + $msg = $this->getConflictMessage( $conflict ); - /** - * @var WikiPage $ipsPage - */ - $conflictingPage = EntityContentFactory::singleton()->getWikiPageForId( $id ); - - // NOTE: it would be nice to generate the link here and just pass it as HTML, - // but Status forces all parameters to be escaped. - $status->fatal( - 'wikibase-error-sitelink-already-used', - $conflict['siteId'], - $conflict['sitePage'], - $conflictingPage->getTitle()->getFullText() - ); + $status->fatal( $msg ); } wfProfileOut( __METHOD__ ); } /** + * Get Message for a conflict + * + * @since 0.4 + * + * @param array $conflict + * + * @return \Message + */ + protected function getConflictMessage( array $conflict ) { + $id = new EntityId( Item::ENTITY_TYPE, $conflict['itemId'] ); + + /** + * @var WikiPage $ipsPage + */ + $conflictingPage = EntityContentFactory::singleton()->getWikiPageForId( $id ); + + $siteSqlStore = \SiteSQLStore::newInstance(); + $site = $siteSqlStore->getSite( $conflict['siteId'] ); + $pageUrl = $site->getPageUrl( $conflict['sitePage'] ); + + $msg = new \Message( 'wikibase-error-sitelink-already-used' ); + $msg->rawParams( $pageUrl ); + $msg->params( array( $conflict['sitePage'], $conflictingPage->getTitle()->getFullText() ) ); + + return $msg; + } + + /** * Deletes the item. * * @since 0.1 diff --git a/repo/tests/phpunit/includes/content/ItemContentTest.php b/repo/tests/phpunit/includes/content/ItemContentTest.php index a3ce71a..70b9b42 100644 --- a/repo/tests/phpunit/includes/content/ItemContentTest.php +++ b/repo/tests/phpunit/includes/content/ItemContentTest.php @@ -2,6 +2,7 @@ namespace Wikibase\Test; use Wikibase\ItemContent; +use Wikibase\SiteLink; /** * Tests for the Wikibase\ItemContent class. @@ -39,6 +40,18 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > */ class ItemContentTest extends EntityContentTest { + + public function setUp() { + parent::setUp(); + + $site = new \MediaWikiSite(); + $site->setGlobalId( 'eswiki' ); + $site->setPath( \MediaWikiSite::PATH_PAGE, "https://es.wikipedia.org/wiki/$1" ); + + $sitesTable = \SiteSQLStore::newInstance(); + $sitesTable->clear(); + $sitesTable->saveSites( array( $site ) ); + } /** * @see EntityContentTest::getContentClass @@ -88,4 +101,42 @@ $this->assertTrue( $status->hasMessage( 'wikibase-error-label-not-unique-item' ) ); } + /** + * @dataProvider siteLinkConflictProvider + */ + public function testSiteLinkConflict( SiteLink $siteLink, $expected ) { + $content = ItemContent::newEmpty(); + $content->getItem()->addSiteLink( $siteLink ); + + $status = $content->save( 'add item', null, EDIT_NEW ); + + $this->assertTrue( $status->isOK(), 'item creation succeeded' ); + + $content1 = ItemContent::newEmpty(); + $content1->getItem()->addSiteLink( $siteLink ); + + $status = $content1->save( 'add item', null, EDIT_NEW ); + + $this->assertFalse( $status->isOK(), "saving an item with a site link conflict should fail" ); + + $html = $status->getHTML(); + $expected = preg_replace( '(\$1)', $content->getTitle()->getFullText(), $html ); + + $this->assertEquals( $expected, $status->getHTML() ); + } + + public function siteLinkConflictProvider() { + $site = new \MediaWikiSite(); + $site->setGlobalId( 'eswiki' ); + + $siteLink = new SiteLink( $site, 'Pelecanus' ); + + return array( + array( + $siteLink, + 'Site link [https://es.wikipedia.org/wiki/Pelecanus Pelecanus] already used by item [[$1]].' + ) + ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/64881 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie9daf6bb4094ac8e41a3a874809cedd5ae2031a3 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Siebrand <siebr...@wikimedia.org> Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits