From 6d638b24cbd42c17981889802786f305cae39d75 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 23 Sep 2009 20:55:54 +0000 Subject: [PATCH] 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 --- includes/api/ApiQueryImageInfo.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 3494f9134c..aa08ae0363 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -81,6 +81,10 @@ class ApiQueryImageInfo extends ApiQueryBase { $result = $this->getResult(); $images = RepoGroup::singleton()->findFiles( $titles ); foreach ( $images as $img ) { + // Skip redirects + if($img->getOriginalTitle()->isRedirect()) + continue; + $start = $skip ? $fromTimestamp : $params['start']; $pageId = $pageIds[NS_IMAGE][ $img->getOriginalTitle()->getDBkey() ]; @@ -158,13 +162,14 @@ class ApiQueryImageInfo extends ApiQueryBase { $skip = false; } - $missing = array_diff( array_keys( $pageIds[NS_FILE] ), array_keys( $images ) ); - foreach ($missing as $title) { - $result->addValue( - array('query', 'pages', intval($pageIds[NS_FILE][$title])), - 'imagerepository', '' - ); - // The above can't fail because it doesn't increase the result size + $data = $this->getResultData(); + foreach($data['query']['pages'] as $pageid => $arr) { + if(!isset($arr['imagerepository'])) + $result->addValue( + array('query', 'pages', $pageid), + 'imagerepository', '' + ); + // The above can't fail because it doesn't increase the result size } } } -- 2.20.1