* List of iiprop values for the thumbnail fetch queries.
* @since 1.23
*/
- protected static $imageInfoProps = array(
+ protected static $imageInfoProps = [
'url',
- 'thumbnail',
'timestamp',
- );
+ ];
- protected $fileFactory = array( 'ForeignAPIFile', 'newFromTitle' );
+ protected $fileFactory = [ 'ForeignAPIFile', 'newFromTitle' ];
/** @var int Check back with Commons after this expiry */
protected $apiThumbCacheExpiry = 86400; // 1 day (24*3600)
protected $fileCacheExpiry = 2592000; // 1 month (30*24*3600)
/** @var array */
- protected $mFileExists = array();
+ protected $mFileExists = [];
/** @var array */
- private $mQueryCache = array();
+ private $mQueryCache = [];
/**
* @param array|null $info
* @return array
*/
function fileExistsBatch( array $files ) {
- $results = array();
+ $results = [];
foreach ( $files as $k => $f ) {
if ( isset( $this->mFileExists[$f] ) ) {
$results[$k] = $this->mFileExists[$f];
}
}
- $data = $this->fetchImageQuery( array(
+ $data = $this->fetchImageQuery( [
'titles' => implode( $files, '|' ),
- 'prop' => 'imageinfo' )
+ 'prop' => 'imageinfo' ]
);
if ( isset( $data['query']['pages'] ) ) {
global $wgLanguageCode;
$query = array_merge( $query,
- array(
+ [
'format' => 'json',
'action' => 'query',
'redirects' => 'true'
- ) );
+ ] );
if ( !isset( $query['uselang'] ) ) { // uselang is unset or null
$query['uselang'] = $wgLanguageCode;
* @return array
*/
function findBySha1( $hash ) {
- $results = $this->fetchImageQuery( array(
+ $results = $this->fetchImageQuery( [
'aisha1base36' => $hash,
'aiprop' => ForeignAPIFile::getProps(),
'list' => 'allimages',
- ) );
- $ret = array();
+ ] );
+ $ret = [];
if ( isset( $results['query']['allimages'] ) ) {
foreach ( $results['query']['allimages'] as $img ) {
// 1.14 was broken, doesn't return name attribute
* @return bool
*/
function getThumbUrl( $name, $width = -1, $height = -1, &$result = null, $otherParams = '' ) {
- $data = $this->fetchImageQuery( array(
+ $data = $this->fetchImageQuery( [
'titles' => 'File:' . $name,
'iiprop' => self::getIIProps(),
'iiurlwidth' => $width,
'iiurlheight' => $height,
'iiurlparam' => $otherParams,
- 'prop' => 'imageinfo' ) );
+ 'prop' => 'imageinfo' ] );
$info = $this->getImageInfo( $data );
if ( $data && $info && isset( $info['thumburl'] ) ) {
* @since 1.22
*/
function getThumbError( $name, $width = -1, $height = -1, $otherParams = '', $lang = null ) {
- $data = $this->fetchImageQuery( array(
+ $data = $this->fetchImageQuery( [
'titles' => 'File:' . $name,
'iiprop' => self::getIIProps(),
'iiurlwidth' => $width,
'iiurlparam' => $otherParams,
'prop' => 'imageinfo',
'uselang' => $lang,
- ) );
+ ] );
$info = $this->getImageInfo( $data );
if ( $data && $info && isset( $info['thumberror'] ) ) {
$knownThumbUrls = $cache->get( $key );
if ( !$knownThumbUrls ) {
/* No knownThumbUrls for this file */
- $knownThumbUrls = array();
+ $knownThumbUrls = [];
} else {
if ( isset( $knownThumbUrls[$sizekey] ) ) {
wfDebug( __METHOD__ . ': Got thumburl from local cache: ' .
$localUrl = $this->getZoneUrl( 'thumb' ) . "/" . $this->getHashPath( $name ) .
rawurlencode( $name ) . "/" . rawurlencode( $fileName );
- if ( $backend->fileExists( array( 'src' => $localFilename ) )
+ if ( $backend->fileExists( [ 'src' => $localFilename ] )
&& isset( $metadata['timestamp'] )
) {
wfDebug( __METHOD__ . " Thumbnail was already downloaded before\n" );
- $modified = $backend->getFileTimestamp( array( 'src' => $localFilename ) );
+ $modified = $backend->getFileTimestamp( [ 'src' => $localFilename ] );
$remoteModified = strtotime( $metadata['timestamp'] );
$current = time();
$diff = abs( $modified - $current );
}
# @todo FIXME: Delete old thumbs that aren't being used. Maintenance script?
- $backend->prepare( array( 'dir' => dirname( $localFilename ) ) );
- $params = array( 'dst' => $localFilename, 'content' => $thumb );
+ $backend->prepare( [ 'dir' => dirname( $localFilename ) ] );
+ $params = [ 'dst' => $localFilename, 'content' => $thumb ];
if ( !$backend->quickCreate( $params )->isOK() ) {
wfDebug( __METHOD__ . " could not write to thumb path '$localFilename'\n" );
* @return bool|null|string
*/
function getZonePath( $zone ) {
- $supported = array( 'public', 'thumb' );
+ $supported = [ 'public', 'thumb' ];
if ( in_array( $zone, $supported ) ) {
return parent::getZonePath( $zone );
}
$info = parent::getInfo();
$info['apiurl'] = $this->getApiUrl();
- $query = array(
+ $query = [
'format' => 'json',
'action' => 'query',
'meta' => 'siteinfo',
'siprop' => 'general',
- );
+ ];
$data = $this->httpGetCached( 'SiteInfo', $query, 7200 );
* @param array $options
* @return bool|string
*/
- public static function httpGet( $url, $timeout = 'default', $options = array() ) {
+ public static function httpGet( $url, $timeout = 'default', $options = [] ) {
$options['timeout'] = $timeout;
/* Http::get */
$url = wfExpandUrl( $url, PROTO_HTTP );
return $req->getContent();
} else {
$logger = LoggerFactory::getInstance( 'http' );
- $logger->warning( $status->getWikiText(), array( 'caller' => 'ForeignAPIRepo::httpGet' ) );
+ $logger->warning(
+ $status->getWikiText( false, false, 'en' ),
+ [ 'caller' => 'ForeignAPIRepo::httpGet' ]
+ );
return false;
}
}
* @since 1.23
*/
protected static function getIIProps() {
- return join( '|', self::$imageInfoProps );
+ return implode( '|', self::$imageInfoProps );
}
/**
if ( count( $this->mQueryCache ) > 100 ) {
// Keep the cache from growing infinitely
- $this->mQueryCache = array();
+ $this->mQueryCache = [];
}
$this->mQueryCache[$url] = $data;