jenkins-bot has submitted this change and it was merged.
Change subject: ResultBuilder: flag null edits with 'nochange'
......................................................................
ResultBuilder: flag null edits with 'nochange'
Bug: T75258
Change-Id: I5151d80ce8d958ce51c172bf1b4c6fdc0f0930ca
---
M repo/includes/api/ModifyEntity.php
M repo/includes/api/ResultBuilder.php
M repo/tests/phpunit/includes/api/EditEntityTest.php
3 files changed, 22 insertions(+), 5 deletions(-)
Approvals:
JanZerebecki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/includes/api/ModifyEntity.php
b/repo/includes/api/ModifyEntity.php
index 14c6fbc..d222feb 100644
--- a/repo/includes/api/ModifyEntity.php
+++ b/repo/includes/api/ModifyEntity.php
@@ -454,7 +454,7 @@
$this->flags
);
- $this->addToOutput( $entity, $status );
+ $this->addToOutput( $entity, $status, $entityRevId );
}
/**
@@ -499,9 +499,9 @@
$this->flags |= ( $this->getUser()->isAllowed( 'bot' ) &&
$params['bot'] ) ? EDIT_FORCE_BOT : 0;
}
- protected function addToOutput( Entity $entity, Status $status ) {
+ protected function addToOutput( Entity $entity, Status $status,
$oldRevId = null ) {
$this->getResultBuilder()->addBasicEntityInformation(
$entity->getId(), 'entity' );
- $this->getResultBuilder()->addRevisionIdFromStatusToResult(
$status, 'entity' );
+ $this->getResultBuilder()->addRevisionIdFromStatusToResult(
$status, 'entity', $oldRevId );
$params = $this->extractRequestParams();
diff --git a/repo/includes/api/ResultBuilder.php
b/repo/includes/api/ResultBuilder.php
index 5e38938..c7ce9fe 100644
--- a/repo/includes/api/ResultBuilder.php
+++ b/repo/includes/api/ResultBuilder.php
@@ -1044,7 +1044,8 @@
* Adds the ID of the new revision from the Status object to the API
result structure.
* The status value is expected to be structured in the way that
EditEntity::attemptSave()
* resp WikiPage::doEditContent() do it: as an array, with an
EntityRevision or Revision
- * object in the 'revision' field.
+ * object in the 'revision' field. If $oldRevId is set and the latest
edit was null,
+ * a 'nochange' flag is also added.
*
* If no revision is found the the Status object, this method does
nothing.
*
@@ -1054,8 +1055,10 @@
*
* @param Status $status The status to get the revision ID from.
* @param string|null|array $path Where in the result to put the
revision id
+ * @param int|null $oldRevId The id of the latest revision of the
entity before
+ * the last (possibly null) edit
*/
- public function addRevisionIdFromStatusToResult( Status $status, $path
) {
+ public function addRevisionIdFromStatusToResult( Status $status, $path,
$oldRevId = null ) {
$value = $status->getValue();
if ( isset( $value['revision'] ) ) {
@@ -1068,6 +1071,11 @@
}
$this->setValue( $path, 'lastrevid', empty( $revisionId
) ? 0 : $revisionId );
+
+ if ( $oldRevId && $oldRevId === $revisionId ) {
+ // like core's ApiEditPage
+ $this->setValue( $path, 'nochange', true );
+ }
}
}
diff --git a/repo/tests/phpunit/includes/api/EditEntityTest.php
b/repo/tests/phpunit/includes/api/EditEntityTest.php
index 2b0e88a..805248f 100644
--- a/repo/tests/phpunit/includes/api/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/api/EditEntityTest.php
@@ -331,6 +331,10 @@
.
'"descriptions":{"en":{"language":"en","value":"A description"}}}' ),
'e' => array( 'type' => 'item' )
),
+ 'make a null edit' => array(
+ 'p' => array( 'data' => '{}' ),
+ 'e' => array( 'nochange' => '' )
+ ),
'remove all stuff in another way' => array(
'p' => array( 'clear' => true, 'data' => '{}' ),
'e' => array(
@@ -401,6 +405,11 @@
$this->assertArrayHasKey( 'id', $result['entity'], "Missing
'id' section in entity in response." );
$this->assertEntityEquals( $expected, $result['entity'] );
+ // -- check null edits
---------------------------------------------
+ if ( isset( $expected['nochange'] ) ) {
+ $this->assertArrayHasKey( 'nochange', $result['entity']
);
+ }
+
// -- check the item in the database
-------------------------------
$dbEntity = $this->loadEntity( $result['entity']['id'] );
$this->assertEntityEquals( $expected, $dbEntity, false );
--
To view, visit https://gerrit.wikimedia.org/r/236192
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5151d80ce8d958ce51c172bf1b4c6fdc0f0930ca
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits