From a5c538db03e7974ca6881e46022bede451675ee5 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Thu, 6 Jan 2011 15:47:57 +0000 Subject: [PATCH] Fixup my FIXME on r79708 Check inner array set, before doing count Also add method documentation --- includes/filerepo/ForeignAPIFile.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/filerepo/ForeignAPIFile.php b/includes/filerepo/ForeignAPIFile.php index 055d3784a6..56fed75e41 100644 --- a/includes/filerepo/ForeignAPIFile.php +++ b/includes/filerepo/ForeignAPIFile.php @@ -21,7 +21,13 @@ class ForeignAPIFile extends File { $this->mInfo = $info; $this->mExists = $exists; } - + + /** + * @static + * @param $title Title + * @param $repo ForeignApiRepo + * @return ForeignAPIFile|null + */ static function newFromTitle( $title, $repo ) { $data = $repo->fetchImageQuery( array( 'titles' => 'File:' . $title->getDBKey(), @@ -31,7 +37,9 @@ class ForeignAPIFile extends File { $info = $repo->getImageInfo( $data ); if( $info ) { - $lastRedirect = count( $data['query']['redirects'] ) - 1; + $lastRedirect = isset( $data['query']['redirects'] ) + ? count( $data['query']['redirects'] ) - 1 + : -1; if( $lastRedirect >= 0 ) { $newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to']); $img = new ForeignAPIFile( $newtitle, $repo, $info, true ); -- 2.20.1