From a5f097c2c3c2273b73aabcc8cd98bd8729d66993 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 3 Mar 2015 10:10:20 -0500 Subject: [PATCH] API: Handle invalid titles in action=feedwatchlist When new interwiki prefixes or the like get added, it can cause existing watchlist entries to become invalid. Let's handle this more gracefully than "Fatal error: Call to a member function getFullURL() on a non-object". Bug: T44274 Change-Id: I9476fa7a86aaae810b8c0c2da08a9317451a0bdf --- includes/api/ApiFeedWatchlist.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php index 561ff3b406..bfa750bfa4 100644 --- a/includes/api/ApiFeedWatchlist.php +++ b/includes/api/ApiFeedWatchlist.php @@ -117,7 +117,10 @@ class ApiFeedWatchlist extends ApiBase { $feedItems = array(); foreach ( (array)$data['query']['watchlist'] as $info ) { - $feedItems[] = $this->createFeedItem( $info ); + $feedItem = $this->createFeedItem( $info ); + if ( $feedItem ) { + $feedItems[] = $feedItem; + } } $msg = wfMessage( 'watchlist' )->inContentLanguage()->text(); @@ -166,10 +169,22 @@ class ApiFeedWatchlist extends ApiBase { private function createFeedItem( $info ) { $titleStr = $info['title']; $title = Title::newFromText( $titleStr ); + $curidParam = array(); + if ( !$title || $title->isExternal() ) { + // Probably a formerly-valid title that's now conflicting with an + // interwiki prefix or the like. + if ( isset( $info['pageid'] ) ) { + $title = Title::newFromId( $info['pageid'] ); + $curidParam = array( 'curid' => $info['pageid'] ); + } + if ( !$title || $title->isExternal() ) { + return null; + } + } if ( isset( $info['revid'] ) ) { $titleUrl = $title->getFullURL( array( 'diff' => $info['revid'] ) ); } else { - $titleUrl = $title->getFullURL(); + $titleUrl = $title->getFullURL( $curidParam ); } $comment = isset( $info['comment'] ) ? $info['comment'] : null; -- 2.20.1