jenkins-bot has submitted this change and it was merged. Change subject: Update Wikidata - Fix formatting of client edit summaries ......................................................................
Update Wikidata - Fix formatting of client edit summaries Bug: T110823 Change-Id: I05a2b3ecf1527e03367c16c7d5bb1384a35c87e1 --- M composer.lock M extensions/Wikibase/client/includes/recentchanges/ExternalChangeFactory.php M extensions/Wikibase/client/tests/phpunit/includes/recentchanges/ExternalChangeFactoryTest.php M vendor/composer/installed.json 4 files changed, 211 insertions(+), 44 deletions(-) Approvals: Thcipriani: Looks good to me, approved jenkins-bot: Verified diff --git a/composer.lock b/composer.lock index 6314265..d8d5828 100644 --- a/composer.lock +++ b/composer.lock @@ -1379,7 +1379,7 @@ "source": { "type": "git", "url": "https://gerrit.wikimedia.org/r/mediawiki/extensions/Wikibase", - "reference": "4b7691ead1d9922d8c8ec1104b2c730c773d0001" + "reference": "27dc06de687582e3c0de5207ea79511703861eee" }, "require": { "data-values/common": "~0.3.0", @@ -1461,7 +1461,7 @@ "issues": "https://phabricator.wikimedia.org/", "irc": "irc://irc.freenode.net/wikidata" }, - "time": "2015-08-25 17:34:58" + "time": "2015-08-31 13:16:41" }, { "name": "wikibase/wikimedia-badges", diff --git a/extensions/Wikibase/client/includes/recentchanges/ExternalChangeFactory.php b/extensions/Wikibase/client/includes/recentchanges/ExternalChangeFactory.php index fbfd5b1..cddd1f9 100644 --- a/extensions/Wikibase/client/includes/recentchanges/ExternalChangeFactory.php +++ b/extensions/Wikibase/client/includes/recentchanges/ExternalChangeFactory.php @@ -141,7 +141,27 @@ } /** - * @fixme refactor comments handling! + * This method transforms the comments field into rc_params into an appropriate + * comment value for ExternalChange. + * + * $comment can be a string or an array with some additional data. + * + * String comments are either 'wikibase-comment-update' (legacy) or have + * comments from the repo, such as '/ wbsetclaim-update:2||1 / [[Property:P213]]: [[Q850]]'. + * + * We don't yet parse repo comments in the client, so for now, we use the + * generic 'wikibase-comment-update' for these. + * + * Comment arrays may contain a message key that provide autocomments for stuff + * like log actions (item deletion) or edits that have no meaningful summary + * to use in the client. + * + * - 'wikibase-comment-unlinked' (when the sitelink to the given page is removed on the repo) + * - 'wikibase-comment-add' (when the item is created, with sitelink to the given page) + * - 'wikibase-comment-remove' (when the item is deleted, the page becomes unconnected) + * - 'wikibase-comment-restore' (when the item is undeleted and reconnected to the page) + * - 'wikibase-comment-sitelink-add' (and other sitelink messages, unused) + * - 'wikibase-comment-update' (legacy, generic, item updated commment) * * @param array|string $comment * @param string $type @@ -163,10 +183,11 @@ } else { $newComment['key'] = $comment['message']; } - } elseif ( is_string( $comment ) ) { - $newComment['key'] = $comment; } + // @todo handle $comment values that are strings or whatever format + // that we use to transfer autocomments from repo to client. + return $newComment; } diff --git a/extensions/Wikibase/client/tests/phpunit/includes/recentchanges/ExternalChangeFactoryTest.php b/extensions/Wikibase/client/tests/phpunit/includes/recentchanges/ExternalChangeFactoryTest.php index 9912e3f..3b4957d 100644 --- a/extensions/Wikibase/client/tests/phpunit/includes/recentchanges/ExternalChangeFactoryTest.php +++ b/extensions/Wikibase/client/tests/phpunit/includes/recentchanges/ExternalChangeFactoryTest.php @@ -21,41 +21,194 @@ */ class ExternalChangeFactoryTest extends \MediaWikiTestCase { - /** - * @dataProvider newFromRecentChangeProvider - */ - public function testNewFromRecentChange( $expected, RecentChange $recentChange ) { + public function testNewFromRecentChange_itemUpdated() { + $commentData = 'wikibase-comment-update'; + + $recentChange = $this->makeRecentChange( $commentData, 'wikibase-item~update', false ); + $externalChangeFactory = new ExternalChangeFactory( 'testrepo' ); - $externalChange = $externalChangeFactory->newFromRecentChange( $recentChange ); - $this->assertEquals( $expected, $externalChange ); - } - - public function newFromRecentChangeProvider() { - $rev = new RevisionData( 'Cat', 5, 92, 90, '20130819111741', - array( 'key' => 'wikibase-comment-update' ), 'testrepo' - ); - - $externalChange = new ExternalChange( new ItemId( 'Q4' ), $rev, 'update' ); - - return array( - array( $externalChange, $this->getEditRecentChange( true ), 'bot edit' ), - array( $externalChange, $this->getEditRecentChange( false ), 'non bot edit' ) + $this->assertEquals( + $this->makeExpectedExternalChange( 'wikibase-comment-update', 'update' ), + $externalChangeFactory->newFromRecentChange( $recentChange ) ); } - /** - * @param boolean $bot - * @return RecentChange - */ - protected function getEditRecentChange( $bot ) { + public function testNewFromRecentChange_siteLinkChange() { + // at the moment, we don't do anything with this info :( and just say + // 'wikibase-comment-update' for these changes. + $commentData = array( + 'message' => 'wikibase-comment-sitelink-add', + 'sitelink' => array( + 'newlink' => array( 'site' => 'dewiki', 'page' => 'Kanada' ) + ) + ); + + $recentChange = $this->makeRecentChange( $commentData, 'wikibase-item~update', false ); + + $externalChangeFactory = new ExternalChangeFactory( 'testrepo' ); + + $this->assertEquals( + $this->makeExpectedExternalChange( 'wikibase-comment-update', 'update' ), + $externalChangeFactory->newFromRecentChange( $recentChange ) + ); + } + + public function testNewFromRecentChange_pageLinkedOnRepo() { + $commentData = array( + 'message' => 'wikibase-comment-linked' + ); + + $recentChange = $this->makeRecentChange( $commentData, 'wikibase-item~add', false ); + + $externalChangeFactory = new ExternalChangeFactory( 'testrepo' ); + + $this->assertEquals( + $this->makeExpectedExternalChange( 'wikibase-comment-linked', 'add' ), + $externalChangeFactory->newFromRecentChange( $recentChange ) + ); + } + + public function testNewFromRecentChange_withRepoComment() { + $commentData = '/* wbsetclaim-update:2||1 */ [[Property:P213]]: [[Q850]]'; + + $recentChange = $this->makeRecentChange( $commentData, 'wikibase-item~update', false ); + + $externalChangeFactory = new ExternalChangeFactory( 'testrepo' ); + + $this->assertEquals( + $this->makeExpectedExternalChange( 'wikibase-comment-update', 'update' ), + $externalChangeFactory->newFromRecentChange( $recentChange ) + ); + } + + public function testNewFromRecentChange_compositeComment() { + $commentData = 'wikibase-comment-update'; + $recentChange = new RecentChange(); $recentChange->counter = 2; - $params = array( + $rcParams = $this->makeRCParams( $commentData, 'wikibase-item~update', false ); + + $rcParams['wikibase-repo-change']['composite-comment'] = array( + 'wikibase-comment-update', + 'wikibase-comment-update' + ); + + $recentChange->setAttribs( $this->makeAttribs( $rcParams, false ) ); + + $expected = new ExternalChange( + new ItemId( 'Q4' ), + $this->makeRevisionData( array( + 'key' => 'wikibase-comment-multi', + 'numparams' => 2 + ) ), + 'update' + ); + + $externalChangeFactory = new ExternalChangeFactory( 'testrepo' ); + + $this->assertEquals( + $expected, + $externalChangeFactory->newFromRecentChange( $recentChange ) + ); + } + + public function testNewFromRecentChange_botEdit() { + $commentData = 'wikibase-comment-update'; + + $recentChange = $this->makeRecentChange( $commentData, 'wikibase-item~update', true ); + + $expected = new ExternalChange( + new ItemId( 'Q4' ), + $this->makeRevisionData( array( + 'key' => 'wikibase-comment-update' + ) ), + 'update' + ); + + $externalChangeFactory = new ExternalChangeFactory( 'testrepo' ); + + $this->assertEquals( + $this->makeExpectedExternalChange( 'wikibase-comment-update', 'update' ), + $externalChangeFactory->newFromRecentChange( $recentChange ) + ); + } + + public function testNewFromRecentChange_nonBotEdit() { + $commentData = 'wikibase-comment-update'; + + $recentChange = $this->makeRecentChange( $commentData, 'wikibase-item~update', false ); + + $externalChangeFactory = new ExternalChangeFactory( 'testrepo' ); + + $this->assertEquals( + $this->makeExpectedExternalChange( 'wikibase-comment-update', 'update' ), + $externalChangeFactory->newFromRecentChange( $recentChange ) + ); + } + + /** + * @param string $expectedComment + * @param string $expectedType + * + * @return ExternalChange + */ + private function makeExpectedExternalChange( $expectedComment, $expectedType ) { + return new ExternalChange( + new ItemId( 'Q4' ), + $this->makeRevisionData( array( + 'key' => $expectedComment + ) ), + $expectedType + ); + } + + private function makeRevisionData( array $comment ) { + return new RevisionData( + 'Cat', + 5, + 92, + 90, + '20130819111741', + $comment, + 'testrepo' + ); + } + + /** + * @param array|string $commentData + * @param string $changeType + * @param bool $isBot + * + * @return RecentChange + */ + private function makeRecentChange( $commentData, $changeType, $isBot ) { + $recentChange = new RecentChange(); + $recentChange->counter = 2; + + $attribs = $this->makeAttribs( + $this->makeRCParams( $commentData, $changeType, $isBot ), + $isBot + ); + + $recentChange->setAttribs( $attribs ); + + return $recentChange; + } + + /** + * @param array|string $commentData + * @param string $changeType + * @param boolean $bot + * + * @return array + */ + private function makeRCParams( $commentData, $changeType, $bot ) { + return array( 'wikibase-repo-change' => array( 'id' => 4, - 'type' => 'wikibase-item~update', + 'type' => $changeType, 'time' => '20130819111741', 'object_id' => 'q4', 'user_id' => 1, @@ -66,16 +219,13 @@ 'page_id' => 5, 'rev_id' => 92, 'parent_id' => 90, - 'comment' => array( - 'message' => 'wikibase-comment-sitelink-add', - 'sitelink' => array( - 'newlink' => array( 'site' => 'dewiki', 'page' => 'Kanada' ) - ) - ) + 'comment' => $commentData ) ); + } - $attribs = array( + private function makeAttribs( array $rcParams, $bot ) { + return array( 'rc_id' => 315, 'rc_timestamp' => '20130819111741', 'rc_user' => 0, @@ -98,12 +248,8 @@ 'rc_logid' => 0, 'rc_log_type' => null, 'rc_log_action' => '', - 'rc_params' => serialize( $params ) + 'rc_params' => serialize( $rcParams ) ); - - $recentChange->setAttribs( $attribs ); - - return $recentChange; } } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index cead815..959d555 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1467,7 +1467,7 @@ "source": { "type": "git", "url": "https://gerrit.wikimedia.org/r/mediawiki/extensions/Wikibase", - "reference": "4b7691ead1d9922d8c8ec1104b2c730c773d0001" + "reference": "27dc06de687582e3c0de5207ea79511703861eee" }, "require": { "data-values/common": "~0.3.0", @@ -1497,7 +1497,7 @@ "require-dev": { "squizlabs/php_codesniffer": "~2.1" }, - "time": "2015-08-25 15:36:29", + "time": "2015-08-30 19:08:10", "type": "mediawiki-extension", "installation-source": "source", "autoload": { -- To view, visit https://gerrit.wikimedia.org/r/234991 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I05a2b3ecf1527e03367c16c7d5bb1384a35c87e1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikidata Gerrit-Branch: wmf/1.26wmf20 Gerrit-Owner: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Thcipriani <tcipri...@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