Ricordisamoa has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/236192

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
2 files changed, 13 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/92/236192/1

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 );
+                       }
                }
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/236192
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5151d80ce8d958ce51c172bf1b4c6fdc0f0930ca
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to