diff options
Diffstat (limited to 'Thanks/includes/ApiCoreThank.php')
-rw-r--r-- | Thanks/includes/ApiCoreThank.php | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/Thanks/includes/ApiCoreThank.php b/Thanks/includes/ApiCoreThank.php index 38ac6c52..b9a2828c 100644 --- a/Thanks/includes/ApiCoreThank.php +++ b/Thanks/includes/ApiCoreThank.php @@ -1,5 +1,8 @@ <?php +use MediaWiki\MediaWikiServices; +use MediaWiki\Revision\RevisionRecord; + /** * API module to send thanks notifications for revisions and log entries. * @@ -10,6 +13,8 @@ class ApiCoreThank extends ApiThank { /** * Perform the API request. + * @suppress PhanTypeMismatchArgumentNullable T240141 + * @suppress PhanPossiblyUndeclaredVariable Phan get's confused by the badly arranged code */ public function execute() { // Initial setup. @@ -29,8 +34,10 @@ class ApiCoreThank extends ApiThank { $id = $params['log']; } else { $this->dieWithError( 'thanks-error-api-params', 'thanks-error-api-params' ); + throw new LogicException(); } + $recipientUsername = null; // Determine thanks parameters. if ( $type === 'log' ) { $logEntry = $this->getLogEntryFromId( $id ); @@ -39,6 +46,8 @@ class ApiCoreThank extends ApiThank { $type = 'rev'; $id = $logEntry->getAssociatedRevId(); } else { + // If there's no associated revision, die if the user is sitewide blocked + $this->dieOnSitewideBlockedUser( $user ); $excerpt = ''; $title = $logEntry->getTarget(); $recipient = $this->getUserFromLog( $logEntry ); @@ -49,11 +58,14 @@ class ApiCoreThank extends ApiThank { $revision = $this->getRevisionFromId( $id ); $excerpt = EchoDiscussionParser::getEditExcerpt( $revision, $this->getLanguage() ); $title = $this->getTitleFromRevision( $revision ); + $this->dieOnBlockedUser( $user, $title ); + $recipient = $this->getUserFromRevision( $revision ); - $recipientUsername = $revision->getUserText(); + $recipientUsername = $revision->getUser()->getName(); // If there is no parent revid of this revision, it's a page creation. - if ( !(bool)$revision->getPrevious() ) { + $store = MediaWikiServices::getInstance()->getRevisionStore(); + if ( !(bool)$store->getPreviousRevision( $revision ) ) { $revcreation = true; } } @@ -83,7 +95,7 @@ class ApiCoreThank extends ApiThank { * @param int $id The revision or log ID. * @return bool */ - protected function userAlreadySentThanks( User $user, $type, $id ) { + protected function userAlreadySentThanks( User $user, $type, $id ) { if ( $type === 'rev' ) { // For b/c with old-style keys $type = ''; @@ -92,11 +104,12 @@ class ApiCoreThank extends ApiThank { } private function getRevisionFromId( $revId ) { - $revision = Revision::newFromId( $revId ); + $store = MediaWikiServices::getInstance()->getRevisionStore(); + $revision = $store->getRevisionById( $revId ); // Revision ID 1 means an invalid argument was passed in. if ( !$revision || $revision->getId() === 1 ) { $this->dieWithError( 'thanks-error-invalidrevision', 'invalidrevision' ); - } elseif ( $revision->isDeleted( Revision::DELETED_TEXT ) ) { + } elseif ( $revision->isDeleted( RevisionRecord::DELETED_TEXT ) ) { $this->dieWithError( 'thanks-error-revdeleted', 'revdeleted' ); } return $revision; @@ -126,11 +139,12 @@ class ApiCoreThank extends ApiThank { $this->dieWithError( 'thanks-error-log-deleted', 'thanks-error-log-deleted' ); } + // @phan-suppress-next-line PhanTypeMismatchReturnNullable T240141 return $logEntry; } - private function getTitleFromRevision( Revision $revision ) { - $title = Title::newFromID( $revision->getPage() ); + private function getTitleFromRevision( RevisionRecord $revision ) { + $title = Title::newFromID( $revision->getPageId() ); if ( !$title instanceof Title ) { $this->dieWithError( 'thanks-error-notitle', 'notitle' ); } @@ -150,19 +164,28 @@ class ApiCoreThank extends ApiThank { } } - private function getUserFromRevision( Revision $revision ) { - $recipient = $revision->getUser(); + /** + * @param RevisionRecord $revision + * @return User + */ + private function getUserFromRevision( RevisionRecord $revision ) { + $recipient = $revision->getUser()->getId(); if ( !$recipient ) { $this->dieWithError( 'thanks-error-invalidrecipient', 'invalidrecipient' ); } return User::newFromId( $recipient ); } + /** + * @param LogEntry $logEntry + * @return User + */ private function getUserFromLog( LogEntry $logEntry ) { $recipient = $logEntry->getPerformer(); if ( !$recipient ) { $this->dieWithError( 'thanks-error-invalidrecipient', 'invalidrecipient' ); } + // @phan-suppress-next-line PhanTypeMismatchReturnNullable T240141 return $recipient; } |