From 5c0c4d1201ac15e048520a11070d2ffcc4f2f4c8 Mon Sep 17 00:00:00 2001 From: Ammarpad Date: Wed, 24 Mar 2021 07:43:33 +0100 Subject: [PATCH] MergeHistory: Avoid potential DB query for trivial message variation Title::exists( Title::READ_LATEST ) can lead to querrying the master database just to decide whether to show a variation of message to the user, and even after consulting the master database, the check can be negated by the TitleExists hook (T265775), making the db check useless. This can be simplified by notifying the caller upfront whether the source page is deleted, since this info is authoritatively known at the point of the deletion. Bug: T278295 Change-Id: Iccf61a06306126c03be302dddfdfeb576217a048 --- includes/MergeHistory.php | 2 ++ includes/specials/SpecialMergeHistory.php | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/MergeHistory.php b/includes/MergeHistory.php index 85f6b9c9496..c5d44ff6e0d 100644 --- a/includes/MergeHistory.php +++ b/includes/MergeHistory.php @@ -579,6 +579,8 @@ class MergeHistory { // fails, it will be communicated in the status reponse. $reason = wfMessage( 'mergehistory-source-deleted-reason' )->inContentLanguage()->plain(); $deletionStatus = $newPage->doDeleteArticleReal( $reason, $user ); + // Notify callers that the source page has been deleted. + $status->value = 'source-deleted'; $status->merge( $deletionStatus ); } diff --git a/includes/specials/SpecialMergeHistory.php b/includes/specials/SpecialMergeHistory.php index f81ad0d5e74..9008970cc6e 100644 --- a/includes/specials/SpecialMergeHistory.php +++ b/includes/specials/SpecialMergeHistory.php @@ -411,9 +411,8 @@ class SpecialMergeHistory extends SpecialPage { ); // In some cases the target page will be deleted - $append = $targetTitle->exists( Title::READ_LATEST ) - ? '' - : $this->msg( 'mergehistory-source-deleted', $targetLink ); + $append = ( $mergeStatus->getValue() === 'source-deleted' ) + ? $this->msg( 'mergehistory-source-deleted', $targetLink ) : ''; $this->getOutput()->addWikiMsg( $this->msg( 'mergehistory-done' ) ->rawParams( $targetLink )