X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiStashEdit.php;h=ab9ae8e4e1d8bd4489086eb2751a2bdfba33dc84;hb=ab94b635267bb6b2be253cb27c840b6a56fcd080;hp=b4b93217878c483087bab4007a4b92437d76ade6;hpb=07a791ffd1d80c6a8f2ca4dfdbc3f2002ac869fe;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php index b4b9321787..ab9ae8e4e1 100644 --- a/includes/api/ApiStashEdit.php +++ b/includes/api/ApiStashEdit.php @@ -67,11 +67,11 @@ class ApiStashEdit extends ApiBase { ); } - $this->requireAtLeastOneParameter( $params, 'stashedtexthash', 'text' ); + $this->requireOnlyOneParameter( $params, 'stashedtexthash', 'text' ); $text = null; $textHash = null; - if ( strlen( $params['stashedtexthash'] ) ) { + if ( $params['stashedtexthash'] !== null ) { // Load from cache since the client indicates the text is the same as last stash $textHash = $params['stashedtexthash']; if ( !preg_match( '/^[0-9a-f]{40}$/', $textHash ) ) { @@ -82,16 +82,11 @@ class ApiStashEdit extends ApiBase { if ( !is_string( $text ) ) { $this->dieWithError( 'apierror-stashedit-missingtext', 'missingtext' ); } - } elseif ( $params['text'] !== null ) { - // Trim and fix newlines so the key SHA1's match (see WebRequest::getText()) + } else { + // 'text' was passed. Trim and fix newlines so the key SHA1's + // match (see WebRequest::getText()) $text = rtrim( str_replace( "\r\n", "\n", $params['text'] ) ); $textHash = sha1( $text ); - } else { - $this->dieWithError( [ - 'apierror-missingparam-at-least-one-of', - Message::listParam( [ 'stashedtexthash', 'text' ] ), - 2, - ], 'missingparam' ); } $textContent = ContentHandler::makeContent( @@ -156,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 ); } /** @@ -240,6 +234,7 @@ class ApiStashEdit extends ApiBase { return self::ERROR_CACHE; } } else { + // @todo Doesn't seem reachable, see @todo in buildStashValue $logger->info( "Uncacheable parser output for key '{cachekey}' ('{title}') [{code}].", [ 'cachekey' => $key, 'title' => $titleStr, 'code' => $code ] ); return self::ERROR_UNCACHEABLE; @@ -340,11 +335,15 @@ class ApiStashEdit extends ApiBase { * @return string|null TS_MW timestamp or null */ private static function lastEditTime( User $user ) { - $time = wfGetDB( DB_REPLICA )->selectField( - 'recentchanges', + $db = wfGetDB( DB_REPLICA ); + $actorQuery = ActorMigration::newMigration()->getWhere( $db, 'rc_user', $user, false ); + $time = $db->selectField( + [ 'recentchanges' ] + $actorQuery['tables'], 'MAX(rc_timestamp)', - [ 'rc_user_text' => $user->getName() ], - __METHOD__ + [ $actorQuery['conds'] ], + __METHOD__, + [], + $actorQuery['joins'] ); return wfTimestampOrNull( TS_MW, $time ); @@ -403,7 +402,7 @@ class ApiStashEdit extends ApiBase { ) { // If an item is renewed, mind the cache TTL determined by config and parser functions. // Put an upper limit on the TTL for sanity to avoid extreme template/file staleness. - $since = time() - wfTimestamp( TS_UNIX, $parserOutput->getTimestamp() ); + $since = time() - wfTimestamp( TS_UNIX, $parserOutput->getCacheTime() ); $ttl = min( $parserOutput->getCacheExpiry() - $since, self::MAX_CACHE_TTL ); // Avoid extremely stale user signature timestamps (T84843) @@ -412,6 +411,9 @@ class ApiStashEdit extends ApiBase { } if ( $ttl <= 0 ) { + // @todo It doesn't seem like this can occur, because it would mean an entry older than + // getCacheExpiry() seconds, which is much longer than PRESUME_FRESH_TTL_SEC, and + // anything older than PRESUME_FRESH_TTL_SEC will have been thrown out already. return [ null, 0, 'no_ttl' ]; }