r79708 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79707‎ | r79708 | r79709 >
Date:03:21, 6 January 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Fixup minor FIXME on r66724
Modified paths:
  • /trunk/phase3/includes/filerepo/ForeignAPIFile.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/ForeignAPIFile.php
@@ -30,11 +30,14 @@
3131
3232 $info = $repo->getImageInfo( $data );
3333
34 - if( $data && $info) {
35 - if( isset( $data['query']['redirects'][0] ) ) {
36 - $newtitle = Title::newFromText( $data['query']['redirects'][0]['to']);
 34+ if( $info ) {
 35+ $lastRedirect = count( $data['query']['redirects'] ) - 1;
 36+ if( $lastRedirect >= 0 ) {
 37+ $newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to']);
3738 $img = new ForeignAPIFile( $newtitle, $repo, $info, true );
38 - if( $img ) $img->redirectedFrom( $title->getDBkey() );
 39+ if( $img ) {
 40+ $img->redirectedFrom( $title->getDBkey() );
 41+ }
3942 } else {
4043 $img = new ForeignAPIFile( $title, $repo, $info, true );
4144 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r79725Fixup my FIXME on r79708...reedy15:47, 6 January 2011
r798151.17: MFT r78327, r78560, r79131, r79708, r79713, r79725, r79758, r79759, r79...catrope13:55, 7 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r66724Bug 22541. Support image redirects on Commons for ForeignAPIRepo...hartman15:59, 21 May 2010

Comments

#Comment by Raymond (talk | contribs)   08:15, 6 January 2011

PHP Notice: Undefined index: redirects in /www/w/includes/filerepo/ForeignAPIFile.php on line 34

#Comment by Reedy (talk | contribs)   15:31, 6 January 2011

Wondering if this might be the best solution:

		if( $info ) {
			if ( isset( $data['query']['redirects'] ) ) {
				$lastRedirect = count( $data['query']['redirects'] ) - 1;
				if( $lastRedirect >= 0 ) {
					$newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to']);
					$img = new ForeignAPIFile( $newtitle, $repo, $info, true );
					if( $img ) {
						$img->redirectedFrom( $title->getDBkey() );
					}
				}
			} else {
				$img = new ForeignAPIFile( $title, $repo, $info, true );
			}
			return $img;
		} else {
			return null;
		}
#Comment by Reedy (talk | contribs)   15:43, 6 January 2011

Except that'd make $img undefined in some cases

/sigh

#Comment by Reedy (talk | contribs)   15:46, 6 January 2011
		if( $info ) {
			$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 );
				if( $img ) {
					$img->redirectedFrom( $title->getDBkey() );
				}
			} else {
				$img = new ForeignAPIFile( $title, $repo, $info, true );
			}
			return $img;
		} else {
			return null;
		}
#Comment by Bryan (talk | contribs)   15:53, 6 January 2011

Please describe in your commit summary what you fixed, not only that you fixed something. Not specifying what you have fixed makes reviewing much harder.

Status & tagging log