From: Brad Jorsch Date: Tue, 3 Mar 2015 15:10:20 +0000 (-0500) Subject: API: Handle invalid titles in action=feedwatchlist X-Git-Tag: 1.31.0-rc.0~12217^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%22id_auteur=%24connect_id_auteur%22%29%20.%20%22?a=commitdiff_plain;h=a5f097c2c3c2273b73aabcc8cd98bd8729d66993;p=lhc%2Fweb%2Fwiklou.git 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 --- 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;