| Index: trunk/phase3/includes/filerepo/ForeignAPIRepo.php |
| — | — | @@ -103,20 +103,7 @@ |
| 104 | 104 | return false; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | | - protected function queryImage( $query ) { |
| 108 | | - $data = $this->fetchImageQuery( $query ); |
| 109 | | - |
| 110 | | - if( isset( $data['query']['pages'] ) ) { |
| 111 | | - foreach( $data['query']['pages'] as $pageid => $info ) { |
| 112 | | - if( isset( $info['imageinfo'][0] ) ) { |
| 113 | | - return $info['imageinfo'][0]; |
| 114 | | - } |
| 115 | | - } |
| 116 | | - } |
| 117 | | - return false; |
| 118 | | - } |
| 119 | | - |
| 120 | | - protected function fetchImageQuery( $query ) { |
| | 107 | + function fetchImageQuery( $query ) { |
| 121 | 108 | global $wgMemc; |
| 122 | 109 | |
| 123 | 110 | $url = $this->mApiBase . |
| — | — | @@ -125,7 +112,8 @@ |
| 126 | 113 | array_merge( $query, |
| 127 | 114 | array( |
| 128 | 115 | 'format' => 'json', |
| 129 | | - 'action' => 'query' ) ) ); |
| | 116 | + 'action' => 'query', |
| | 117 | + 'redirects' => 'true' ) ) ); |
| 130 | 118 | |
| 131 | 119 | if( !isset( $this->mQueryCache[$url] ) ) { |
| 132 | 120 | $key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) ); |
| — | — | @@ -147,11 +135,15 @@ |
| 148 | 136 | return FormatJson::decode( $this->mQueryCache[$url], true ); |
| 149 | 137 | } |
| 150 | 138 | |
| 151 | | - function getImageInfo( $title, $time = false ) { |
| 152 | | - return $this->queryImage( array( |
| 153 | | - 'titles' => 'Image:' . $title->getText(), |
| 154 | | - 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime', |
| 155 | | - 'prop' => 'imageinfo' ) ); |
| | 139 | + function getImageInfo( $data ) { |
| | 140 | + if( $data && isset( $data['query']['pages'] ) ) { |
| | 141 | + foreach( $data['query']['pages'] as $pageid => $info ) { |
| | 142 | + if( isset( $info['imageinfo'][0] ) ) { |
| | 143 | + return $info['imageinfo'][0]; |
| | 144 | + } |
| | 145 | + } |
| | 146 | + } |
| | 147 | + return false; |
| 156 | 148 | } |
| 157 | 149 | |
| 158 | 150 | function findBySha1( $hash ) { |
| — | — | @@ -169,13 +161,15 @@ |
| 170 | 162 | } |
| 171 | 163 | |
| 172 | 164 | function getThumbUrl( $name, $width=-1, $height=-1 ) { |
| 173 | | - $info = $this->queryImage( array( |
| 174 | | - 'titles' => 'Image:' . $name, |
| | 165 | + $data = $this->fetchImageQuery( array( |
| | 166 | + 'titles' => 'File:' . $name, |
| 175 | 167 | 'iiprop' => 'url', |
| 176 | 168 | 'iiurlwidth' => $width, |
| 177 | 169 | 'iiurlheight' => $height, |
| 178 | 170 | 'prop' => 'imageinfo' ) ); |
| 179 | | - if( $info && $info['thumburl'] ) { |
| | 171 | + $info = $this->getImageInfo( $data ); |
| | 172 | + |
| | 173 | + if( $data && $info && $info['thumburl'] ) { |
| 180 | 174 | wfDebug( __METHOD__ . " got remote thumb " . $info['thumburl'] . "\n" ); |
| 181 | 175 | return $info['thumburl']; |
| 182 | 176 | } else { |
| Index: trunk/phase3/includes/filerepo/ForeignAPIFile.php |
| — | — | @@ -17,9 +17,22 @@ |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | static function newFromTitle( $title, $repo ) { |
| 21 | | - $info = $repo->getImageInfo( $title ); |
| 22 | | - if( $info ) { |
| 23 | | - return new ForeignAPIFile( $title, $repo, $info, true ); |
| | 21 | + $data = $repo->fetchImageQuery( array( |
| | 22 | + 'titles' => 'File:' . $title->getText(), |
| | 23 | + 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime', |
| | 24 | + 'prop' => 'imageinfo' ) ); |
| | 25 | + |
| | 26 | + $info = $repo->getImageInfo( $data ); |
| | 27 | + |
| | 28 | + if( $data && $info) { |
| | 29 | + if( isset( $data['query']['redirects'][0] ) ) { |
| | 30 | + $newtitle = Title::newFromText( $data['query']['redirects'][0]['to']); |
| | 31 | + $img = new ForeignAPIFile( $newtitle, $repo, $info, true ); |
| | 32 | + if( $img ) $img->redirectedFrom( $title->getDBkey() ); |
| | 33 | + } else { |
| | 34 | + $img = new ForeignAPIFile( $title, $repo, $info, true ); |
| | 35 | + } |
| | 36 | + return $img; |
| 24 | 37 | } else { |
| 25 | 38 | return null; |
| 26 | 39 | } |
| Index: trunk/phase3/RELEASE-NOTES |
| — | — | @@ -171,6 +171,7 @@ |
| 172 | 172 | * (bug 23563) Old skins now support $wgUploadNavigationUrl and take into account upload rights. |
| 173 | 173 | * (bug 1347) Render \phi in math using images, in order to create consistent and correct render results. |
| 174 | 174 | * (bug 16573) Render \epsilon in math using images, in order to create consistent and correct render results. |
| | 175 | +* (bug 22541) Support image redirects when using ForeignAPIRepo |
| 175 | 176 | |
| 176 | 177 | === API changes in 1.17 === |
| 177 | 178 | * (bug 22738) Allow filtering by action type on query=logevent |