Fixup my FIXME on r79708
authorSam Reed <reedy@users.mediawiki.org>
Thu, 6 Jan 2011 15:47:57 +0000 (15:47 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Thu, 6 Jan 2011 15:47:57 +0000 (15:47 +0000)
Check inner array set, before doing count

Also add method documentation

includes/filerepo/ForeignAPIFile.php

index 055d378..56fed75 100644 (file)
@@ -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 );