/* This version string is used in the user agent for requests and will help
* server maintainers in identify ForeignAPI usage.
* Update the version every time you make breaking or significant changes. */
- public static $foreignAPIRepoVersion = "2.0";
+ const VERSION = "2.1";
var $fileFactory = array( 'ForeignAPIFile', 'newFromTitle' );
/* Check back with Commons after a day */
- var $apiThumbCacheExpiry = 86400;
+ var $apiThumbCacheExpiry = 86400; /* 24*60*60 */
/* Redownload thumbnail files after a month */
- var $fileCacheExpiry = 2629743;
+ var $fileCacheExpiry = 2592000; /* 86400*30 */
/* Local image directory */
var $directory;
var $thumbDir;
return false;
}
-
function fileExistsBatch( $files, $flags = 0 ) {
$results = array();
foreach ( $files as $k => $f ) {
}
}
- $results = $this->fetchImageQuery( array( 'titles' => implode( $files, '|' ),
+ $data = $this->fetchImageQuery( array( 'titles' => implode( $files, '|' ),
'prop' => 'imageinfo' ) );
if( isset( $data['query']['pages'] ) ) {
$i = 0;
$i++;
}
}
+ return $results;
}
+
function getFileProps( $virtualUrl ) {
return false;
}
return $ret;
}
- function getThumbUrl( $name, $width=-1, $height=-1, &$result ) {
+ 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 );
* @param $name String is a dbkey form of a title
* @param $width
* @param $height
+ * @param String $param Other rendering parameters (page number, etc) from handler's makeParamString.
*/
- 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);
$knownThumbUrls = array();
} else {
if( isset( $knownThumbUrls[$sizekey] ) ) {
- wfDebug("Got thumburl from local cache. $thumbUrl \n");
+ wfDebug( __METHOD__ . ': Got thumburl from local cache: ' .
+ "{$knownThumbUrls[$sizekey]} \n");
return $knownThumbUrls[$sizekey];
}
/* This size is not yet known */
}
$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" );
$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;
}
* The user agent the ForeignAPIRepo will use.
*/
public static function getUserAgent() {
- return Http::userAgent() . " ForeignAPIRepo/" . self::$foreignAPIRepoVersion;
+ return Http::userAgent() . " ForeignAPIRepo/" . self::VERSION;
}
/**
$options['timeout'] = 'default';
}
- $req = HttpRequest::factory( $url, $options );
+ $req = MWHttpRequest::factory( $url, $options );
$req->setUserAgent( ForeignAPIRepo::getUserAgent() );
$status = $req->execute();