From f21e6dfc7ce85a4939f7ad84913f8b5f2a089566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 27 Jan 2021 16:40:57 +0100 Subject: [PATCH] New error message when the page doesn't exist The previous confusing error was coming from the getLatestRevision() call. Bug: T273068 Change-Id: I5bb53c875bb08f6fb087875a6e55fb033d182056 --- includes/ApiDiscussionToolsEdit.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/includes/ApiDiscussionToolsEdit.php b/includes/ApiDiscussionToolsEdit.php index 1ca7cc7e3..4962c9415 100644 --- a/includes/ApiDiscussionToolsEdit.php +++ b/includes/ApiDiscussionToolsEdit.php @@ -98,6 +98,17 @@ class ApiDiscussionToolsEdit extends ApiBase { break; case 'addcomment': + $commentId = $params['commentid'] ?? null; + + if ( !$commentId ) { + $this->dieWithError( [ 'apierror-missingparam', 'commentid' ] ); + } + + if ( !$title->exists() ) { + // The page does not exist, so the comment we're trying to reply to can't exist either. + $this->dieWithError( [ 'apierror-discussiontools-commentid-notfound', $commentId ] ); + } + // Fetch the latest revision $requestedRevision = $this->getLatestRevision( $title ); $response = $this->requestRestbasePageHtml( $requestedRevision ); @@ -133,12 +144,6 @@ class ApiDiscussionToolsEdit extends ApiBase { $container = $doc->getElementsByTagName( 'body' )->item( 0 ); '@phan-var DOMElement $container'; - $commentId = $params['commentid'] ?? null; - - if ( !$commentId ) { - $this->dieWithError( [ 'apierror-missingparam', 'commentid' ] ); - } - $parser = CommentParser::newFromGlobalState( $container ); $comment = $parser->findCommentById( $commentId );