From 4de1be2eb0278c817f81a408b4b2ef9870f1fd1e Mon Sep 17 00:00:00 2001 From: DannyS712 Date: Thu, 25 Jun 2020 03:32:46 +0000 Subject: [PATCH] ApiQueryRevisions::getRollbackToken - pass RevisionRecord Not actually used, but need to deprecate passing Revision Bug: T249561 Change-Id: Ic4ce2fce64a2f3c8a0c70490599be2022b9f8903 --- RELEASE-NOTES-1.35 | 3 +++ includes/api/ApiQueryRevisions.php | 27 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES-1.35 b/RELEASE-NOTES-1.35 index 6b8a44402ca..01e7d786504 100644 --- a/RELEASE-NOTES-1.35 +++ b/RELEASE-NOTES-1.35 @@ -1184,6 +1184,9 @@ because of Phabricator reports. the second parameter, and the suppression option the third parameter. Previously, the third parameter was unused. Using the old signature is hard deprecated. +* ApiQueryRevisions::getRollbackToken, which has been soft deprecated since + 1.24, accepted as its third parameter a Revision object. It now accepts + a RevisionRecord, and passing a Revision is hard deprecated. * Passing Article to ParserCache::get() was deprecated * ParserOptions::newCanonical() with no first parameter, or null as the first parameter, which falls back to using global $wgUser, is hard deprecated. diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index cb4ee1dd0f6..d95663baeec 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -72,10 +72,15 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { * @deprecated since 1.24 * @param int $pageid * @param Title $title - * @param Revision $rev + * @param RevisionRecord|Revision $rev (passing a Revision hard deprecated since 1.35) * @return bool|string */ public static function getRollbackToken( $pageid, $title, $rev ) { + if ( $rev instanceof Revision ) { + // Don't actually need to use the Revision(Record), just emit warnings + wfDeprecated( __METHOD__ . ' with a Revision object', '1.35' ); + } + global $wgUser; if ( !MediaWikiServices::getInstance()->getPermissionManager() ->userHasRight( $wgUser, 'rollback' ) ) { @@ -420,10 +425,26 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { if ( $this->token !== null ) { $title = Title::newFromLinkTarget( $revision->getPageAsLinkTarget() ); - $revisionCompat = new Revision( $revision ); $tokenFunctions = $this->getTokenFunctions(); foreach ( $this->token as $t ) { - $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revisionCompat ); + if ( $t === 'rollback' ) { + $val = call_user_func( + $tokenFunctions[$t], + $title->getArticleID(), + $title, + $revision + ); + } else { + // Token function added via APIQueryRevisionsTokens, + // Hook is hard deprecated, so any use of + // Revision objects is okay + $val = call_user_func( + $tokenFunctions[$t], + $title->getArticleID(), + $title, + new Revision( $revision ) + ); + } if ( $val === false ) { $this->addWarning( [ 'apiwarn-tokennotallowed', $t ] ); } else {