From 8acb5869d587dea0ce60af5f216a9f5119c0c00b Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 10 Aug 2017 16:26:08 -0400 Subject: [PATCH] SpecialDoubleRedirects: Fix undefined '$result->namespace' notice Follows-up 7be1a8c0bc4d29d. $result is used for both the original and the on-demand deep query (in case of cache). However this re-query can fail if the page no longer exists. This used to be accounted for by creating the Title object before (possibly) trying to re-query, and also checked for with "if !$result", which is only intended to happen if the re-query failed (the initial value of $result comes from the main (cacheable) query, and always exists. Could be moved by moving the $titleA assignment back up, but that doesn't address the confusion problem that led to this. Fix it by using a separate variable names. Bug: T173045 Change-Id: I0e9ae89a3772b33b916b506033bd334ade5f03fa --- includes/specials/SpecialDoubleRedirects.php | 47 +++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/includes/specials/SpecialDoubleRedirects.php b/includes/specials/SpecialDoubleRedirects.php index ba14c664ce..d73ac19875 100644 --- a/includes/specials/SpecialDoubleRedirects.php +++ b/includes/specials/SpecialDoubleRedirects.php @@ -122,28 +122,33 @@ class DoubleRedirectsPage extends QueryPage { // That does save the bulk of the query cost, but now we need to // get a little more detail about each individual entry quickly // using the filter of reallyGetQueryInfo. - if ( $result && !isset( $result->b_namespace ) ) { - $dbr = wfGetDB( DB_REPLICA ); - $qi = $this->reallyGetQueryInfo( - $result->namespace, - $result->title - ); - $res = $dbr->select( - $qi['tables'], - $qi['fields'], - $qi['conds'], - __METHOD__ - ); - - if ( $res ) { - $result = $dbr->fetchObject( $res ); + $deep = false; + if ( $result ) { + if ( isset( $result->b_namespace ) ) { + $deep = $result; + } else { + $dbr = wfGetDB( DB_REPLICA ); + $qi = $this->reallyGetQueryInfo( + $result->namespace, + $result->title + ); + $res = $dbr->select( + $qi['tables'], + $qi['fields'], + $qi['conds'], + __METHOD__ + ); + + if ( $res ) { + $deep = $dbr->fetchObject( $res ) ?: false; + } } } $titleA = Title::makeTitle( $result->namespace, $result->title ); $linkRenderer = $this->getLinkRenderer(); - if ( !$result ) { + if ( !$deep ) { return '' . $linkRenderer->makeLink( $titleA, null, [], [ 'redirect' => 'no' ] ) . ''; } @@ -171,7 +176,7 @@ class DoubleRedirectsPage extends QueryPage { [ 'redirect' => 'no' ] ); - $titleB = Title::makeTitle( $result->b_namespace, $result->b_title ); + $titleB = Title::makeTitle( $deep->b_namespace, $deep->b_title ); $linkB = $linkRenderer->makeKnownLink( $titleB, null, @@ -180,10 +185,10 @@ class DoubleRedirectsPage extends QueryPage { ); $titleC = Title::makeTitle( - $result->c_namespace, - $result->c_title, - $result->c_fragment, - $result->c_interwiki + $deep->c_namespace, + $deep->c_title, + $deep->c_fragment, + $deep->c_interwiki ); $linkC = $linkRenderer->makeKnownLink( $titleC, $titleC->getFullText() ); -- 2.20.1