Page MenuHomePhabricator

instantcommons-paged-media.diff

Authored By
bzimport
Nov 21 2014, 11:24 PM
Size
8 KB
Referenced Files
None
Subscribers
None

instantcommons-paged-media.diff

Index: filerepo/ForeignAPIRepo.php
===================================================================
--- filerepo/ForeignAPIRepo.php (revision 81199)
+++ filerepo/ForeignAPIRepo.php (working copy)
@@ -197,12 +197,13 @@
return $ret;
}
- function getThumbUrl( $name, $width = -1, $height = -1, &$result = null ) {
+ function getThumbUrl( $name, $width = -1, $height = -1, &$result = null, $otherParams = '' ) {
$data = $this->fetchImageQuery( array(
'titles' => 'File:' . $name,
'iiprop' => 'url|timestamp',
'iiurlwidth' => $width,
'iiurlheight' => $height,
+ 'iiurlparam' => $otherParams,
'prop' => 'imageinfo' ) );
$info = $this->getImageInfo( $data );
@@ -224,15 +225,16 @@
* @param $name String is a dbkey form of a title
* @param $width
* @param $height
+ * @param String $param Other rendering parameters (page number, etc). | seperated.
*/
- function getThumbUrlFromCache( $name, $width, $height ) {
+ function getThumbUrlFromCache( $name, $width, $height, $params="" ) {
global $wgMemc;
if ( !$this->canCacheThumbs() ) {
- return $this->getThumbUrl( $name, $width, $height );
+ return $this->getThumbUrl( $name, $width, $height, null, $params );
}
$key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'ThumbUrl', $name );
- $sizekey = "$width:$height";
+ $sizekey = "$width:$height:$params";
/* Get the array of urls that we already know */
$knownThumbUrls = $wgMemc->get($key);
@@ -248,7 +250,7 @@
}
$metadata = null;
- $foreignUrl = $this->getThumbUrl( $name, $width, $height, $metadata );
+ $foreignUrl = $this->getThumbUrl( $name, $width, $height, $metadata, $params );
if( !$foreignUrl ) {
wfDebug( __METHOD__ . " Could not find thumburl\n" );
@@ -273,7 +275,7 @@
$diff = abs( $modified - $current );
if( $remoteModified < $modified && $diff < $this->fileCacheExpiry ) {
/* Use our current and already downloaded thumbnail */
- $knownThumbUrls["$width:$height"] = $localUrl;
+ $knownThumbUrls[$sizekey] = $localUrl;
$wgMemc->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry );
return $localUrl;
}
Index: filerepo/ForeignAPIFile.php
===================================================================
--- filerepo/ForeignAPIFile.php (revision 81199)
+++ filerepo/ForeignAPIFile.php (working copy)
@@ -76,10 +76,25 @@
// show icon
return parent::transform( $params, $flags );
}
+
+ $otherParams = "";
+ // Not using implode, since associative array.
+ foreach ( $params as $name => $value ) {
+ if ( $name === 'width' || $name === 'height' ) {
+ continue;
+ }
+ $otherParams .= "{$name}={$value}|";
+ }
+ // Remove the last |
+ if ( $otherParams !== "" ) {
+ $otherParams = substr( $otherParams, 0, -1 );
+ }
+
$thumbUrl = $this->repo->getThumbUrlFromCache(
$this->getName(),
isset( $params['width'] ) ? $params['width'] : -1,
- isset( $params['height'] ) ? $params['height'] : -1 );
+ isset( $params['height'] ) ? $params['height'] : -1,
+ $otherParams );
return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );
}
Index: api/ApiQueryImageInfo.php
===================================================================
--- api/ApiQueryImageInfo.php (revision 81199)
+++ api/ApiQueryImageInfo.php (working copy)
@@ -50,7 +50,7 @@
$prop = array_flip( $params['prop'] );
- $scale = $this->getScale( $params );
+ $thumbParams = $this->makeThumbParams( $params );
$pageIds = $this->getPageSet()->getAllTitlesByNamespace();
if ( !empty( $pageIds[NS_FILE] ) ) {
@@ -118,7 +118,7 @@
{
$gotOne = true;
$fit = $this->addPageSubItem( $pageId,
- self::getInfo( $img, $prop, $result, $scale ) );
+ self::getInfo( $img, $prop, $result, $thumbParams ) );
if ( !$fit ) {
if ( count( $pageIds[NS_IMAGE] ) == 1 ) {
// See the 'the user is screwed' comment above
@@ -184,9 +184,25 @@
* @return Array or Null: key-val array of 'width' and 'height', or null
*/
public function getScale( $params ) {
+ wfDeprecated( __METHOD__ );
+ if ( !isset( $params['urlparam'] ) ) {
+ // In case there are subclasses that
+ // don't have this param set to anything.
+ $params['urlparam'] = null;
+ }
+ return $this->makeThumbParams( $params );
+ }
+
+ /* Take parameters for transforming thumbnail, validate and turn into array.
+ * @param $params Array: Parameters from the request.
+ * @return Array or null: If array, suitable to passing to $file->transform.
+ */
+ public function makeThumbParams( $params ) {
$p = $this->getModulePrefix();
+
+ // Height and width.
if ( $params['urlheight'] != -1 && $params['urlwidth'] == -1 ) {
- $this->dieUsage( "${p}urlheight cannot be used without {$p}urlwidth", "{$p}urlwidth" );
+ $this->dieUsage( "{$p}urlheight cannot be used without {$p}urlwidth", "{$p}urlwidth" );
}
if ( $params['urlwidth'] != -1 ) {
@@ -195,21 +211,39 @@
$scale['height'] = $params['urlheight'];
} else {
$scale = null;
+ if ( $params['urlparam'] ) {
+ $this->dieUsage( "{$p}urlparam requires {$p}urlwidth", "{$p}urlparam_no_width" );
+ }
+ return $scale;
}
+
+ // Other parameters.
+ if ( is_array( $params['urlparam'] ) ) {
+ foreach( $params['urlparam'] as $item ) {
+ $parameter = explode( '=', $item, 2 );
+
+ if ( count( $parameter ) !== 2
+ || $parameter[0] === 'width'
+ || $parameter[0] === 'height'
+ ) {
+ $this->dieUsage( "Invalid value for {$p}urlparam", "{$p}urlparam" );
+ }
+ $scale[$parameter[0]] = $parameter[1];
+ }
+ }
return $scale;
}
-
/**
* Get result information for an image revision
*
* @param $file File object
* @param $prop Array of properties to get (in the keys)
* @param $result ApiResult object
- * @param $scale Array containing 'width' and 'height' items, or null
+ * @param $thumbParams Array containing 'width' and 'height' items, or null
* @return Array: result array
*/
- static function getInfo( $file, $prop, $result, $scale = null ) {
+ static function getInfo( $file, $prop, $result, $thumbParams = null ) {
$vals = array();
if ( isset( $prop['timestamp'] ) ) {
$vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
@@ -237,8 +271,8 @@
}
}
if ( isset( $prop['url'] ) ) {
- if ( !is_null( $scale ) && !$file->isOld() ) {
- $mto = $file->transform( array( 'width' => $scale['width'], 'height' => $scale['height'] ) );
+ if ( !is_null( $thumbParams ) && !$file->isOld() ) {
+ $mto = $file->transform( $thumbParams );
if ( $mto && !$mto->isError() ) {
$vals['thumburl'] = wfExpandUrl( $mto->getUrl() );
@@ -352,6 +386,9 @@
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_DFLT => -1
),
+ 'urlparam' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ),
'continue' => null,
);
}
@@ -406,6 +443,8 @@
'urlwidth' => array( "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
'Only the current version of the image can be scaled' ),
'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth",
+ 'urlparam' => array( "Other rending parameters, such as page=2 for multipaged documents.",
+ "Multiple parameters should be seperated with a |. {$p}urlwidth must also be used"),
'limit' => 'How many image revisions to return',
'start' => 'Timestamp to start listing from',
'end' => 'Timestamp to stop listing at',
@@ -420,6 +459,8 @@
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'iiurlwidth', 'info' => 'iiurlheight cannot be used without iiurlwidth' ),
+ array( 'code' => 'iiurlparam', 'info' => 'Invalid value for iiurlparam' ),
+ array( 'code' => 'iiurlparam_no_width', 'info' => "iiurlparam requires iiurlwidth" ),
) );
}
Index: api/ApiQueryStashImageInfo.php
===================================================================
--- api/ApiQueryStashImageInfo.php (revision 81199)
+++ api/ApiQueryStashImageInfo.php (working copy)
@@ -37,7 +37,7 @@
$prop = array_flip( $params['prop'] );
- $scale = $this->getScale( $params );
+ $scale = $this->makeThumbParams( $params );
$result = $this->getResult();
@@ -97,7 +97,10 @@
'urlheight' => array(
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_DFLT => -1
- )
+ ),
+ 'urlparam' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ),
);
}
@@ -122,7 +125,9 @@
),
'sessionkey' => 'Session key that identifies a previous upload that was stashed temporarily.',
'urlwidth' => "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
- 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth"
+ 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth",
+ 'urlparam' => array( "Other rending parameters, such as page=2 for multipaged documents.",
+ "Multiple parameters should be seperated with a |. {$p}urlwidth must also be used" ),
);
}

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6958
Default Alt Text
instantcommons-paged-media.diff (8 KB)

Event Timeline