SpecialDoubleRedirects: Fix undefined '$result->namespace' notice
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 10 Aug 2017 20:26:08 +0000 (16:26 -0400)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 10 Aug 2017 20:26:08 +0000 (16:26 -0400)
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

index ba14c66..d73ac19 100644 (file)
@@ -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 '<del>' . $linkRenderer->makeLink( $titleA, null, [], [ 'redirect' => 'no' ] ) . '</del>';
                }
 
@@ -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() );