Include 'false' results in 'transcludedfrom' API response

Skipping them could result in incorrect handling when RESTBase HTML is
outdated.

When a result for a given comment is not found, display an error
instead of assuming it is not transcluded.

Bug: T262065
Change-Id: I14a7a0a25d5181b5c49bd5677f0c002dce5a3cb9
This commit is contained in:
Bartosz Dziewoński 2020-10-22 22:25:29 +02:00
parent 9b965c45b5
commit 7ad6328223
2 changed files with 12 additions and 9 deletions

View file

@ -52,14 +52,10 @@ class ApiDiscussionTools extends ApiBase {
$transcludedFrom = [];
foreach ( $comments as $comment ) {
$from = $comment->getTranscludedFrom();
// 'false' is the most likely result, so don't bother sending it,
// the client can just assume it if the key is missing
if ( $from !== false ) {
$transcludedFrom[ $comment->getId() ] = $from;
$legacyId = $comment->getLegacyId();
if ( $legacyId ) {
$transcludedFrom[ $legacyId ] = $from;
}
$transcludedFrom[ $comment->getId() ] = $from;
$legacyId = $comment->getLegacyId();
if ( $legacyId ) {
$transcludedFrom[ $legacyId ] = $from;
}
}

View file

@ -119,7 +119,14 @@ function checkCommentOnPage( pageName, oldId, commentId ) {
transcludedFrom = response.transcludedfrom;
isTranscludedFrom = transcludedFrom[ commentId ];
if ( isTranscludedFrom ) {
if ( isTranscludedFrom === undefined ) {
// The comment wasn't found when generating the "transcludedfrom" data,
// so we don't know where the reply should be posted. Just give up.
return $.Deferred().reject( 'discussiontools-commentid-notfound-transcludedfrom', { errors: [ {
code: 'discussiontools-commentid-notfound-transcludedfrom',
html: mw.message( 'discussiontools-error-comment-disappeared' ).parse()
} ] } ).promise();
} else if ( isTranscludedFrom ) {
mwTitle = isTranscludedFrom === true ? null : mw.Title.newFromText( isTranscludedFrom );
// If this refers to a template rather than a subpage, we never want to edit it
follow = mwTitle && mwTitle.getNamespaceId() !== mw.config.get( 'wgNamespaceIds' ).template;