/** @var array Associative array mapping optional supplementary image files
* from pixel density (eg 1.5 or 2) to additional URLs.
*/
- public $responsiveUrls = array();
+ public $responsiveUrls = [];
/** @var File */
protected $file;
*
* @return string
*/
- abstract public function toHtml( $options = array() );
+ abstract public function toHtml( $options = [] );
/**
* This will be overridden to return true in error classes
} elseif ( FileBackend::isStoragePath( $this->path ) ) {
$be = $this->file->getRepo()->getBackend();
// The temp file will be process cached by FileBackend
- $fsFile = $be->getLocalReference( array( 'src' => $this->path ) );
+ $fsFile = $be->getLocalReference( [ 'src' => $this->path ] );
return $fsFile ? $fsFile->getPath() : false;
} else {
* Stream the file if there were no errors
*
* @param array $headers Additional HTTP headers to send on success
- * @return bool Success
+ * @return Status
+ * @since 1.27
*/
- public function streamFile( $headers = array() ) {
+ public function streamFileWithStatus( $headers = [] ) {
if ( !$this->path ) {
- return false;
+ return Status::newFatal( 'backend-fail-stream', '<no path>' );
} elseif ( FileBackend::isStoragePath( $this->path ) ) {
$be = $this->file->getRepo()->getBackend();
-
- return $be->streamFile( array( 'src' => $this->path, 'headers' => $headers ) )->isOK();
+ return $be->streamFile( [ 'src' => $this->path, 'headers' => $headers ] );
} else { // FS-file
- return StreamFile::stream( $this->getLocalCopyPath(), $headers );
+ $success = StreamFile::stream( $this->getLocalCopyPath(), $headers );
+ return $success ? Status::newGood() : Status::newFatal( 'backend-fail-stream', $this->path );
}
}
+ /**
+ * Stream the file if there were no errors
+ *
+ * @deprecated since 1.26, use streamFileWithStatus
+ * @param array $headers Additional HTTP headers to send on success
+ * @return bool Success
+ */
+ public function streamFile( $headers = [] ) {
+ $this->streamFileWithStatus( $headers )->isOK();
+ }
+
/**
* Wrap some XHTML text in an anchor tag with the given attributes
*
* @param string|array $params Query parameters to add
* @return array
*/
- public function getDescLinkAttribs( $title = null, $params = array() ) {
+ public function getDescLinkAttribs( $title = null, $params = [] ) {
if ( is_array( $params ) ) {
$query = $params;
} else {
- $query = array();
+ $query = [];
}
if ( $this->page && $this->page !== 1 ) {
$query['page'] = $this->page;
$query = $params . '&' . wfArrayToCgi( $query );
}
- $attribs = array(
+ $attribs = [
'href' => $this->file->getTitle()->getLocalURL( $query ),
'class' => 'image',
- );
+ ];
if ( $title ) {
$attribs['title'] = $title;
}
* @param string|bool $path Filesystem path to the thumb
* @param array $parameters Associative array of parameters
*/
- function __construct( $file, $url, $path = false, $parameters = array() ) {
+ function __construct( $file, $url, $path = false, $parameters = [] ) {
# Previous parameters:
# $file, $url, $width, $height, $path = false, $page = false
- $defaults = array(
+ $defaults = [
'page' => false,
'lang' => false
- );
+ ];
if ( is_array( $parameters ) ) {
$actualParams = $parameters + $defaults;
} else {
# Using old format, should convert. Later a warning could be added here.
$numArgs = func_num_args();
- $actualParams = array(
+ $actualParams = [
'width' => $path,
'height' => $parameters,
'page' => ( $numArgs > 5 ) ? func_get_arg( 5 ) : false
- ) + $defaults;
+ ] + $defaults;
$path = ( $numArgs > 4 ) ? func_get_arg( 4 ) : false;
}
* @throws MWException
* @return string
*/
- function toHtml( $options = array() ) {
+ function toHtml( $options = [] ) {
if ( count( func_get_args() ) == 2 ) {
throw new MWException( __METHOD__ . ' called in the old style' );
}
$query = isset( $options['desc-query'] ) ? $options['desc-query'] : '';
- $attribs = array(
+ $attribs = [
'alt' => $alt,
'src' => $this->url,
- );
+ ];
if ( !empty( $options['custom-url-link'] ) ) {
- $linkAttribs = array( 'href' => $options['custom-url-link'] );
+ $linkAttribs = [ 'href' => $options['custom-url-link'] ];
if ( !empty( $options['title'] ) ) {
$linkAttribs['title'] = $options['title'];
}
} elseif ( !empty( $options['custom-title-link'] ) ) {
/** @var Title $title */
$title = $options['custom-title-link'];
- $linkAttribs = array(
+ $linkAttribs = [
'href' => $title->getLinkURL(),
'title' => empty( $options['title'] ) ? $title->getFullText() : $options['title']
- );
+ ];
} elseif ( !empty( $options['desc-link'] ) ) {
$linkAttribs = $this->getDescLinkAttribs(
empty( $options['title'] ) ? null : $options['title'],
$query
);
} elseif ( !empty( $options['file-link'] ) ) {
- $linkAttribs = array( 'href' => $this->file->getURL() );
+ $linkAttribs = [ 'href' => $this->file->getUrl() ];
} else {
$linkAttribs = false;
if ( !empty( $options['title'] ) ) {
$attribs['srcset'] = Html::srcSet( $this->responsiveUrls );
}
- Hooks::run( 'ThumbnailBeforeProduceHTML', array( $this, &$attribs, &$linkAttribs ) );
+ Hooks::run( 'ThumbnailBeforeProduceHTML', [ $this, &$attribs, &$linkAttribs ] );
return $this->linkWrap( $linkAttribs, Xml::element( 'img', $attribs ) );
}
$this->path = false;
}
- function toHtml( $options = array() ) {
+ function toHtml( $options = [] ) {
return "<div class=\"MediaTransformError\" style=\"" .
"width: {$this->width}px; height: {$this->height}px; display:inline-block;\">" .
$this->htmlMsg .