API: Handle invalid titles in action=feedwatchlist
authorBrad Jorsch <bjorsch@wikimedia.org>
Tue, 3 Mar 2015 15:10:20 +0000 (10:10 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Tue, 3 Mar 2015 15:29:49 +0000 (10:29 -0500)
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

index 561ff3b..bfa750b 100644 (file)
@@ -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;