Do not return invalid hash from ApiStashEdit
authorAryeh Gregor <ayg@aryeh.name>
Mon, 6 Aug 2018 16:54:04 +0000 (19:54 +0300)
committerKrinkle <krinklemail@gmail.com>
Mon, 6 Aug 2018 20:44:20 +0000 (20:44 +0000)
If we were rate-limited, we don't store a new hash, so we shouldn't
return a new one.  If we received a hash from the client, however, that
should still be valid, so we can return it.

Change-Id: Ifc37ae044172b8838fee15d539b076a0d0f02f22

includes/api/ApiStashEdit.php

index bf956dc..e8318c2 100644 (file)
@@ -151,14 +151,13 @@ class ApiStashEdit extends ApiBase {
                $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
                $stats->increment( "editstash.cache_stores.$status" );
 
-               $this->getResult()->addValue(
-                       null,
-                       $this->getModuleName(),
-                       [
-                               'status' => $status,
-                               'texthash' => $textHash
-                       ]
-               );
+               $ret = [ 'status' => $status ];
+               // If we were rate-limited, we still return the pre-existing valid hash if one was passed
+               if ( $status !== 'ratelimited' || $params['stashedtexthash'] !== null ) {
+                       $ret['texthash'] = $textHash;
+               }
+
+               $this->getResult()->addValue( null, $this->getModuleName(), $ret );
        }
 
        /**