Hoo man has uploaded a new change for review.
https://gerrit.wikimedia.org/r/212741
Change subject: Update Wikibase: Make wbmergeitems respect the bot parameter
......................................................................
Update Wikibase: Make wbmergeitems respect the bot parameter
Change-Id: I79d2e97d3aecf2ee70fa35bd42c88746321a5be1
Contains: c6cbbc82609018ebc01ba016fb47c030db736ff4
---
M composer.json
M composer.lock
M extensions/Wikibase/repo/includes/Interactors/ItemMergeInteractor.php
M extensions/Wikibase/repo/includes/api/MergeItems.php
M extensions/Wikibase/repo/tests/phpunit/includes/api/BotEditTest.php
M vendor/composer/installed.json
6 files changed, 65 insertions(+), 37 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikidata
refs/changes/41/212741/1
diff --git a/composer.json b/composer.json
index 6dfe443..dcbc3d8 100644
--- a/composer.json
+++ b/composer.json
@@ -5,10 +5,6 @@
"repositories": [
{
"type": "vcs",
- "url":
"https://git.wikimedia.org/git/mediawiki/extensions/Wikibase.git"
- },
- {
- "type": "vcs",
"url": "https://github.com/wmde/Wikidata.org.git"
},
{
@@ -39,4 +35,4 @@
"classmap-authoritative": true,
"preferred-install": "dist"
}
-}
\ No newline at end of file
+}
diff --git a/composer.lock b/composer.lock
index 2762b02..ab003e1 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at
https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "4a3036c7ac17f609f86543c37c121922",
+ "hash": "50d7c5e614946c603401a4b94dc7632a",
"packages": [
{
"name": "composer/installers",
@@ -1212,8 +1212,14 @@
"version": "dev-wmf/1.26wmf6",
"source": {
"type": "git",
- "url":
"https://git.wikimedia.org/git/mediawiki/extensions/Wikibase.git",
- "reference": "9eabd536196d41b66b6921aa28c506c94960e4bc"
+ "url":
"https://github.com/wikimedia/mediawiki-extensions-Wikibase.git",
+ "reference": "c6cbbc82609018ebc01ba016fb47c030db736ff4"
+ },
+ "dist": {
+ "type": "zip",
+ "url":
"https://api.github.com/repos/wikimedia/mediawiki-extensions-Wikibase/zipball/c6cbbc82609018ebc01ba016fb47c030db736ff4",
+ "reference": "c6cbbc82609018ebc01ba016fb47c030db736ff4",
+ "shasum": ""
},
"require": {
"data-values/common": "~0.2.0",
@@ -1262,6 +1268,7 @@
"Wikimedia\\Purtle\\Tests\\": "purtle/tests/phpunit"
}
},
+ "notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0+"
],
@@ -1279,11 +1286,7 @@
"wikibaserepo",
"wikidata"
],
- "support": {
- "issues": "https://bugzilla.wikimedia.org/",
- "irc": "irc://irc.freenode.net/wikidata"
- },
- "time": "2015-05-16 15:55:32"
+ "time": "2015-05-22 00:01:41"
},
{
"name": "wikibase/wikimedia-badges",
diff --git
a/extensions/Wikibase/repo/includes/Interactors/ItemMergeInteractor.php
b/extensions/Wikibase/repo/includes/Interactors/ItemMergeInteractor.php
index 7ac98f0..ef0ebd4 100644
--- a/extensions/Wikibase/repo/includes/Interactors/ItemMergeInteractor.php
+++ b/extensions/Wikibase/repo/includes/Interactors/ItemMergeInteractor.php
@@ -127,13 +127,14 @@
* @param ItemId $toId
* @param array $ignoreConflicts The kinds of conflicts to ignore
* @param string|null $summary
+ * @param bool $bot Mark the edit as bot edit
*
* @return array A list of exactly two EntityRevision objects. The
first one represents
* the modified source item, the second one represents the modified
target item.
*
* @throws ItemMergeException
*/
- public function mergeItems( ItemId $fromId, ItemId $toId,
$ignoreConflicts = array(), $summary = null ) {
+ public function mergeItems( ItemId $fromId, ItemId $toId,
$ignoreConflicts = array(), $summary = null, $bot = false ) {
$this->checkPermissions( $fromId );
$this->checkPermissions( $toId );
@@ -159,7 +160,7 @@
throw new ItemMergeException( $e->getMessage(),
'failed-modify', $e );
}
- return $this->attemptSaveMerge( $fromEntity, $toEntity,
$summary );
+ return $this->attemptSaveMerge( $fromEntity, $toEntity,
$summary, $bot );
}
private function loadEntity( EntityId $entityId ) {
@@ -207,27 +208,33 @@
* @param Item $fromItem
* @param Item $toItem
* @param string|null $summary
+ * @param bool $bot
*
* @return array A list of exactly two EntityRevision objects. The
first one represents
* the modified source item, the second one represents the modified
target item.
*/
- private function attemptSaveMerge( Item $fromItem, Item $toItem,
$summary = null ) {
+ private function attemptSaveMerge( Item $fromItem, Item $toItem,
$summary, $bot ) {
$toSummary = $this->getSummary( 'to', $toItem->getId(),
$summary );
- $fromRev = $this->saveEntity( $fromItem, $toSummary );
+ $fromRev = $this->saveEntity( $fromItem, $toSummary, $bot );
$fromSummary = $this->getSummary( 'from', $fromItem->getId(),
$summary );
- $toRev = $this->saveEntity( $toItem, $fromSummary );
+ $toRev = $this->saveEntity( $toItem, $fromSummary, $bot );
return array( $fromRev, $toRev );
}
- private function saveEntity( Entity $entity, Summary $summary ) {
+ private function saveEntity( Entity $entity, Summary $summary, $bot ) {
+ $flags = EDIT_UPDATE;
+ if ( $bot && $this->user->isAllowed( 'bot' ) ) {
+ $flags |= EDIT_FORCE_BOT;
+ }
+
try {
return $this->entityStore->saveEntity(
$entity,
$this->summaryFormatter->formatSummary(
$summary ),
$this->user,
- EDIT_UPDATE
+ $flags
);
} catch ( StorageException $ex ) {
throw new ItemMergeException( $ex->getMessage(),
'failed-save', $ex );
diff --git a/extensions/Wikibase/repo/includes/api/MergeItems.php
b/extensions/Wikibase/repo/includes/api/MergeItems.php
index d237786..e61f53c 100644
--- a/extensions/Wikibase/repo/includes/api/MergeItems.php
+++ b/extensions/Wikibase/repo/includes/api/MergeItems.php
@@ -126,7 +126,7 @@
$ignoreConflicts = array();
}
- $this->mergeItems( $fromId, $toId, $ignoreConflicts,
$summary );
+ $this->mergeItems( $fromId, $toId, $ignoreConflicts,
$summary, $params['bot'] );
} catch ( EntityIdParsingException $ex ) {
$this->errorReporter->dieException( $ex,
'invalid-entity-id' );
} catch ( ItemMergeException $ex ) {
@@ -139,9 +139,10 @@
* @param ItemId $toId
* @param array $ignoreConflicts
* @param string $summary
+ * @param bool $bot
*/
- private function mergeItems( ItemId $fromId, ItemId $toId, array
$ignoreConflicts, $summary ) {
- list( $newRevisionFrom, $newRevisionTo ) =
$this->interactor->mergeItems( $fromId, $toId, $ignoreConflicts, $summary );
+ private function mergeItems( ItemId $fromId, ItemId $toId, array
$ignoreConflicts, $summary, $bot ) {
+ list( $newRevisionFrom, $newRevisionTo ) =
$this->interactor->mergeItems( $fromId, $toId, $ignoreConflicts, $summary, $bot
);
$this->resultBuilder->setValue( null, 'success', 1 );
diff --git
a/extensions/Wikibase/repo/tests/phpunit/includes/api/BotEditTest.php
b/extensions/Wikibase/repo/tests/phpunit/includes/api/BotEditTest.php
index cfe71fc..fdd7d5c 100644
--- a/extensions/Wikibase/repo/tests/phpunit/includes/api/BotEditTest.php
+++ b/extensions/Wikibase/repo/tests/phpunit/includes/api/BotEditTest.php
@@ -42,9 +42,10 @@
'[email protected]',
array( 'bot' )
);
+ $this->mergeMwGlobalArrayValue( 'wgGroupPermissions', array(
'user' => array( 'item-merge' => true ) ) );
if( !isset( self::$hasSetup ) ){
- $this->initTestEntities( array( 'Empty' ) );
+ $this->initTestEntities( array( 'Empty', 'Leipzig',
'Osaka' ) );
}
self::$hasSetup = true;
@@ -88,6 +89,12 @@
array(//11
'p' => array( 'action' => 'wbeditentity', 'new'
=> 'item', 'data' => '{}' ),
'e' => array( 'bot' => false, 'new' => true ) ),
+ array(//12
+ 'p' => array( 'action' => 'wbmergeitems',
'fromid' => 'Osaka', 'toid' => 'Empty', 'bot' => '' ),
+ 'e' => array( 'bot' => true, 'new' => false ) ),
+ array(//13
+ 'p' => array( 'action' => 'wbmergeitems',
'fromid' => 'Leipzig', 'toid' => 'Empty', 'ignoreconflicts' => 'description' ),
+ 'e' => array( 'bot' => false, 'new' => false )
),
//todo claims, references, qualifiers
);
}
@@ -99,18 +106,29 @@
$this->login( 'wbbot' );
// -- do the request
--------------------------------------------------
- if( array_key_exists( 'handle', $params ) ){
+ if ( array_key_exists( 'handle', $params ) ) {
$params['id'] = EntityTestHelper::getId(
$params['handle'] );
unset( $params['handle'] );
+ }
+
+ // wbmergeitems needs special treatment as it takes two entities
+ if ( $params['action'] === 'wbmergeitems' ) {
+ $params['fromid'] = EntityTestHelper::getId(
$params['fromid'] );
+ $params['toid'] = EntityTestHelper::getId(
$params['toid'] );
}
list( $result,, ) = $this->doApiRequestWithToken( $params,
null, self::$users['wbbot']->user );
// -- check the result
------------------------------------------------
$this->assertArrayHasKey( 'success', $result, "Missing
'success' marker in response." );
$this->assertResultHasEntityType( $result );
- $this->assertArrayHasKey( 'entity', $result, "Missing 'entity'
section in response." );
- $this->assertArrayHasKey( 'lastrevid', $result['entity'] ,
'entity should contain lastrevid key' );
- $myid = $result['entity']['id'];
+ if ( $params['action'] !== 'wbmergeitems' ) {
+ $this->assertArrayHasKey( 'entity', $result, "Missing
'entity' section in response." );
+ $this->assertArrayHasKey( 'lastrevid',
$result['entity'] , 'entity should contain lastrevid key' );
+ $myid = $result['entity']['id'];
+ } else {
+ $this->assertArrayHasKey( 'from', $result, "Missing
'from' section in response." );
+ $myid = $result['from']['id'];
+ }
// -- get the recentchanges
-------------------------------------------
$rcRequest = array(
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index 76bdc00..2ee02f7 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -1302,8 +1302,14 @@
"version_normalized": "dev-wmf/1.26wmf6",
"source": {
"type": "git",
- "url":
"https://git.wikimedia.org/git/mediawiki/extensions/Wikibase.git",
- "reference": "9eabd536196d41b66b6921aa28c506c94960e4bc"
+ "url":
"https://github.com/wikimedia/mediawiki-extensions-Wikibase.git",
+ "reference": "c6cbbc82609018ebc01ba016fb47c030db736ff4"
+ },
+ "dist": {
+ "type": "zip",
+ "url":
"https://api.github.com/repos/wikimedia/mediawiki-extensions-Wikibase/zipball/c6cbbc82609018ebc01ba016fb47c030db736ff4",
+ "reference": "c6cbbc82609018ebc01ba016fb47c030db736ff4",
+ "shasum": ""
},
"require": {
"data-values/common": "~0.2.0",
@@ -1329,9 +1335,9 @@
"conflict": {
"mediawiki/mediawiki": "<1.23"
},
- "time": "2015-05-16 15:46:49",
+ "time": "2015-05-22 00:01:41",
"type": "mediawiki-extension",
- "installation-source": "source",
+ "installation-source": "dist",
"autoload": {
"files": [
"Wikibase.composer.php"
@@ -1354,6 +1360,7 @@
"Wikimedia\\Purtle\\Tests\\": "purtle/tests/phpunit"
}
},
+ "notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0+"
],
@@ -1370,10 +1377,6 @@
"wikibaselib",
"wikibaserepo",
"wikidata"
- ],
- "support": {
- "issues": "https://bugzilla.wikimedia.org/",
- "irc": "irc://irc.freenode.net/wikidata"
- }
+ ]
}
]
--
To view, visit https://gerrit.wikimedia.org/r/212741
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I79d2e97d3aecf2ee70fa35bd42c88746321a5be1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikidata
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits