Index: trunk/phase3/includes/filerepo/ForeignAPIRepo.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | /* This version string is used in the user agent for requests and will help |
27 | 27 | * server maintainers in identify ForeignAPI usage. |
28 | 28 | * Update the version every time you make breaking or significant changes. */ |
29 | | - const VERSION = "2.0"; |
| 29 | + const VERSION = "2.1"; |
30 | 30 | |
31 | 31 | var $fileFactory = array( 'ForeignAPIFile', 'newFromTitle' ); |
32 | 32 | /* Check back with Commons after a day */ |
— | — | @@ -225,7 +225,7 @@ |
226 | 226 | * @param $name String is a dbkey form of a title |
227 | 227 | * @param $width |
228 | 228 | * @param $height |
229 | | - * @param String $param Other rendering parameters (page number, etc). | separated. |
| 229 | + * @param String $param Other rendering parameters (page number, etc) from handler's makeParamString. |
230 | 230 | */ |
231 | 231 | function getThumbUrlFromCache( $name, $width, $height, $params="" ) { |
232 | 232 | global $wgMemc; |
Index: trunk/phase3/includes/filerepo/ForeignAPIFile.php |
— | — | @@ -77,18 +77,9 @@ |
78 | 78 | return parent::transform( $params, $flags ); |
79 | 79 | } |
80 | 80 | |
81 | | - $otherParams = ""; |
82 | | - // Not using implode, since associative array. |
83 | | - foreach ( $params as $name => $value ) { |
84 | | - if ( $name === 'width' || $name === 'height' ) { |
85 | | - continue; |
86 | | - } |
87 | | - $otherParams .= "{$name}={$value}|"; |
88 | | - } |
89 | | - // Remove the last | |
90 | | - if ( $otherParams !== "" ) { |
91 | | - $otherParams = substr( $otherParams, 0, -1 ); |
92 | | - } |
| 81 | + // Note, the this->canRender() check above implies |
| 82 | + // that we have a handler, and it can do makeParamString. |
| 83 | + $otherParams = $this->handler->makeParamString( $params ); |
93 | 84 | |
94 | 85 | $thumbUrl = $this->repo->getThumbUrlFromCache( |
95 | 86 | $this->getName(), |
Index: trunk/phase3/includes/api/ApiQueryImageInfo.php |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | |
52 | 52 | $prop = array_flip( $params['prop'] ); |
53 | 53 | |
54 | | - $thumbParams = $this->makeThumbParams( $params ); |
| 54 | + $scale = $this->getScale( $params ); |
55 | 55 | |
56 | 56 | $pageIds = $this->getPageSet()->getAllTitlesByNamespace(); |
57 | 57 | if ( !empty( $pageIds[NS_FILE] ) ) { |
— | — | @@ -108,8 +108,8 @@ |
109 | 109 | break; |
110 | 110 | } |
111 | 111 | |
112 | | - // Check if we can make the requested thumbnail |
113 | | - $this->validateThumbParams( $img, $thumbParams ); |
| 112 | + // Check if we can make the requested thumbnail, and get transform parameters. |
| 113 | + $finalThumbParams = $this->mergeThumbParams( $img, $scale, $params['urlparam'] ); |
114 | 114 | |
115 | 115 | // Get information about the current version first |
116 | 116 | // Check that the current version is within the start-end boundaries |
— | — | @@ -122,7 +122,7 @@ |
123 | 123 | $gotOne = true; |
124 | 124 | |
125 | 125 | $fit = $this->addPageSubItem( $pageId, |
126 | | - self::getInfo( $img, $prop, $result, $thumbParams ) ); |
| 126 | + self::getInfo( $img, $prop, $result, $finalThumbParams ) ); |
127 | 127 | if ( !$fit ) { |
128 | 128 | if ( count( $pageIds[NS_IMAGE] ) == 1 ) { |
129 | 129 | // See the 'the user is screwed' comment above |
— | — | @@ -151,7 +151,7 @@ |
152 | 152 | break; |
153 | 153 | } |
154 | 154 | $fit = $this->addPageSubItem( $pageId, |
155 | | - self::getInfo( $oldie, $prop, $result, $thumbParams ) ); |
| 155 | + self::getInfo( $oldie, $prop, $result, $finalThumbParams ) ); |
156 | 156 | if ( !$fit ) { |
157 | 157 | if ( count( $pageIds[NS_IMAGE] ) == 1 ) { |
158 | 158 | $this->setContinueEnumParameter( 'start', |
— | — | @@ -184,24 +184,10 @@ |
185 | 185 | |
186 | 186 | /** |
187 | 187 | * From parameters, construct a 'scale' array |
188 | | - * @param $params Array: |
| 188 | + * @param $params Array: Parameters passed to api. |
189 | 189 | * @return Array or Null: key-val array of 'width' and 'height', or null |
190 | 190 | */ |
191 | 191 | public function getScale( $params ) { |
192 | | - wfDeprecated( __METHOD__ ); |
193 | | - if ( !isset( $params['urlparam'] ) ) { |
194 | | - // In case there are subclasses that |
195 | | - // don't have this param set to anything. |
196 | | - $params['urlparam'] = null; |
197 | | - } |
198 | | - return $this->makeThumbParams( $params ); |
199 | | - } |
200 | | - |
201 | | - /* Take parameters for transforming thumbnail, validate and turn into array. |
202 | | - * @param $params Array: Parameters from the request. |
203 | | - * @return Array or null: If array, suitable to passing to $file->transform. |
204 | | - */ |
205 | | - public function makeThumbParams( $params ) { |
206 | 192 | $p = $this->getModulePrefix(); |
207 | 193 | |
208 | 194 | // Height and width. |
— | — | @@ -221,50 +207,54 @@ |
222 | 208 | return $scale; |
223 | 209 | } |
224 | 210 | |
225 | | - // Other parameters. |
226 | | - if ( is_array( $params['urlparam'] ) ) { |
227 | | - foreach( $params['urlparam'] as $item ) { |
228 | | - $parameter = explode( '=', $item, 2 ); |
229 | | - |
230 | | - if ( count( $parameter ) !== 2 |
231 | | - || $parameter[0] === 'width' |
232 | | - || $parameter[0] === 'height' |
233 | | - ) { |
234 | | - $this->dieUsage( "Invalid value for {$p}urlparam ($item)", "urlparam" ); |
235 | | - } |
236 | | - $scale[$parameter[0]] = $parameter[1]; |
237 | | - } |
238 | | - } |
239 | 211 | return $scale; |
240 | 212 | } |
241 | 213 | |
242 | | - /** Validate the thumb parameters, give error if invalid. |
| 214 | + /** Validate and merge scale parameters with handler thumb parameters, give error if invalid. |
243 | 215 | * |
244 | | - * We do this later than makeThumbParams, since we need the image |
| 216 | + * We do this later than getScale, since we need the image |
245 | 217 | * to know which handler, since handlers can make their own parameters. |
246 | 218 | * @param File $image Image that params are for. |
247 | | - * @param Array $thumbParams thumbnail parameters |
| 219 | + * @param Array $thumbParams thumbnail parameters from getScale |
| 220 | + * @param String String of otherParams (iiurlparam). |
| 221 | + * @return Array of parameters for transform. |
248 | 222 | */ |
249 | | - protected function validateThumbParams ( $image, $thumbParams ) { |
250 | | - if ( !$thumbParams ) return; |
| 223 | + protected function mergeThumbParams ( $image, $thumbParams, $otherParams ) { |
| 224 | + if ( !$otherParams ) return $thumbParams; |
251 | 225 | $p = $this->getModulePrefix(); |
252 | 226 | |
253 | 227 | $h = $image->getHandler(); |
254 | 228 | if ( !$h ) { |
255 | 229 | $this->setWarning( 'Could not create thumbnail because ' . |
256 | 230 | $image->getName() . ' does not have an associated image handler' ); |
257 | | - return; |
| 231 | + return $thumbParams; |
258 | 232 | } |
259 | | - foreach ( $thumbParams as $name => $value ) { |
| 233 | + |
| 234 | + $paramList = $h->parseParamString( $otherParams ); |
| 235 | + if ( !$paramList ) { |
| 236 | + // Just set a warning (instead of dieUsage), as in many cases |
| 237 | + // we could still render the image using width and height parameters, |
| 238 | + // and this type of thing could happen between different versions of |
| 239 | + // handlers. |
| 240 | + $this->setWarning( "Could not parse {$p}urlparam for " . $image->getName() |
| 241 | + . '. Using only width and height' ); |
| 242 | + return $thumbParams; |
| 243 | + } |
| 244 | + |
| 245 | + if ( isset( $paramList['width'] ) ) { |
| 246 | + if ( $paramList['width'] !== $thumbParams['width'] ) { |
| 247 | + $this->dieUsage( "{$p}urlparam had width of {$paramList['width']} but " |
| 248 | + . "{$p}urlwidth was {$thumbParams['width']}", "urlparam_urlwidth_mismatch" ); |
| 249 | + } |
| 250 | + } |
| 251 | + |
| 252 | + foreach ( $paramList as $name => $value ) { |
260 | 253 | if ( !$h->validateParam( $name, $value ) ) { |
261 | | - /* This doesn't work well with height=-1 placeholder */ |
262 | | - if ( $name === 'height' ) continue; |
263 | 254 | $this->dieUsage( "Invalid value for {$p}urlparam ($name=$value)", "urlparam" ); |
264 | 255 | } |
265 | 256 | } |
266 | | - // This could also potentially check normaliseParams as well, However that seems |
267 | | - // to fall more into a thumbnail rendering error than a user input error, and |
268 | | - // will be checked by the transform functions. |
| 257 | + |
| 258 | + return $thumbParams + $paramList; |
269 | 259 | } |
270 | 260 | |
271 | 261 | /** |
— | — | @@ -423,7 +413,8 @@ |
424 | 414 | ApiBase::PARAM_DFLT => -1 |
425 | 415 | ), |
426 | 416 | 'urlparam' => array( |
427 | | - ApiBase::PARAM_ISMULTI => true, |
| 417 | + ApiBase::PARAM_DFLT => '', |
| 418 | + ApiBase::PARAM_TYPE => 'string', |
428 | 419 | ), |
429 | 420 | 'continue' => null, |
430 | 421 | ); |
— | — | @@ -490,8 +481,8 @@ |
491 | 482 | 'urlwidth' => array( "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.", |
492 | 483 | 'Only the current version of the image can be scaled' ), |
493 | 484 | 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth", |
494 | | - 'urlparam' => array( "Other rending parameters, such as page=2 for multipaged documents.", |
495 | | - "Multiple parameters should be seperated with a |. {$p}urlwidth must also be used"), |
| 485 | + 'urlparam' => array( "A handler specific parameter string. For example, pdf's ", |
| 486 | + "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ), |
496 | 487 | 'limit' => 'How many image revisions to return', |
497 | 488 | 'start' => 'Timestamp to start listing from', |
498 | 489 | 'end' => 'Timestamp to stop listing at', |
— | — | @@ -508,7 +499,9 @@ |
509 | 500 | return array_merge( parent::getPossibleErrors(), array( |
510 | 501 | array( 'code' => 'iiurlwidth', 'info' => 'iiurlheight cannot be used without iiurlwidth' ), |
511 | 502 | array( 'code' => 'urlparam', 'info' => "Invalid value for {$p}urlparam" ), |
512 | | - array( 'code' => 'urlparam_no_width', 'info' => "iiurlparam requires {$p}urlwidth" ), |
| 503 | + array( 'code' => 'urlparam_no_width', 'info' => "{$p}urlparam requires {$p}urlwidth" ), |
| 504 | + array( 'code' => 'urlparam_urlwidth_mismatch', 'info' => "The width set in {$p}urlparm doesnt't " . |
| 505 | + "match the one in {$p}urlwidth" ), |
513 | 506 | ) ); |
514 | 507 | } |
515 | 508 | |
Index: trunk/phase3/includes/api/ApiQueryStashImageInfo.php |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | |
39 | 39 | $prop = array_flip( $params['prop'] ); |
40 | 40 | |
41 | | - $scale = $this->makeThumbParams( $params ); |
| 41 | + $scale = $this->getScale( $params ); |
42 | 42 | |
43 | 43 | $result = $this->getResult(); |
44 | 44 | |
— | — | @@ -46,8 +46,8 @@ |
47 | 47 | |
48 | 48 | foreach ( $params['sessionkey'] as $sessionkey ) { |
49 | 49 | $file = $stash->getFile( $sessionkey ); |
50 | | - $this->validateThumbParams( $file, $scale ); |
51 | | - $imageInfo = self::getInfo( $file, $prop, $result, $scale ); |
| 50 | + $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] ); |
| 51 | + $imageInfo = self::getInfo( $file, $prop, $result, $finalThumbParam ); |
52 | 52 | $result->addValue( array( 'query', $this->getModuleName() ), null, $imageInfo ); |
53 | 53 | $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $modulePrefix ); |
54 | 54 | } |
— | — | @@ -100,7 +100,8 @@ |
101 | 101 | ApiBase::PARAM_DFLT => -1 |
102 | 102 | ), |
103 | 103 | 'urlparam' => array( |
104 | | - ApiBase::PARAM_ISMULTI => true, |
| 104 | + ApiBase::PARAM_TYPE => 'string', |
| 105 | + ApiBase::PARAM_DFLT => '', |
105 | 106 | ), |
106 | 107 | ); |
107 | 108 | } |
— | — | @@ -127,8 +128,8 @@ |
128 | 129 | 'sessionkey' => 'Session key that identifies a previous upload that was stashed temporarily.', |
129 | 130 | 'urlwidth' => "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.", |
130 | 131 | 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth", |
131 | | - 'urlparam' => array( "Other rending parameters, such as page=2 for multipaged documents.", |
132 | | - "Multiple parameters should be seperated with a |. {$p}urlwidth must also be used" ), |
| 132 | + 'urlparam' => array( "A handler specific parameter string. For example, pdf's ", |
| 133 | + "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ), |
133 | 134 | ); |
134 | 135 | } |
135 | 136 | |