r56837 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56836‎ | r56837 | r56838 >
Date:20:55, 23 September 2009
Author:catrope
Status:ok (Comments)
Tags:
Comment:
API: Handle image redirects properly in imageinfo, based on reports of API requests dying with backtraces on Commons, e.g. http://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=user&titles=File:Semaphore_Alfa.svg
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryImageInfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryImageInfo.php
@@ -81,6 +81,10 @@
8282 $result = $this->getResult();
8383 $images = RepoGroup::singleton()->findFiles( $titles );
8484 foreach ( $images as $img ) {
 85+ // Skip redirects
 86+ if($img->getOriginalTitle()->isRedirect())
 87+ continue;
 88+
8589 $start = $skip ? $fromTimestamp : $params['start'];
8690 $pageId = $pageIds[NS_IMAGE][ $img->getOriginalTitle()->getDBkey() ];
8791
@@ -158,13 +162,14 @@
159163 $skip = false;
160164 }
161165
162 - $missing = array_diff( array_keys( $pageIds[NS_FILE] ), array_keys( $images ) );
163 - foreach ($missing as $title) {
164 - $result->addValue(
165 - array('query', 'pages', intval($pageIds[NS_FILE][$title])),
166 - 'imagerepository', ''
167 - );
168 - // The above can't fail because it doesn't increase the result size
 166+ $data = $this->getResultData();
 167+ foreach($data['query']['pages'] as $pageid => $arr) {
 168+ if(!isset($arr['imagerepository']))
 169+ $result->addValue(
 170+ array('query', 'pages', $pageid),
 171+ 'imagerepository', ''
 172+ );
 173+ // The above can't fail because it doesn't increase the result size
169174 }
170175 }
171176 }

Comments

#Comment by Brion VIBBER (talk | contribs)   23:14, 23 September 2009

This sounds like it won't return imageinfo for a redirect. Is that correct? Seems to me like that'll break use of redirected images via remote clients.

#Comment by Catrope (talk | contribs)   09:26, 24 September 2009
  1. It's better than dying with a backtrace for redirects ;)
  2. If you want info for redirect targets, use &redirects

Status & tagging log