MediaWiki REL1_35
MediaTransformOutput.php
Go to the documentation of this file.
1<?php
30abstract class MediaTransformOutput {
34 public $responsiveUrls = [];
35
37 protected $file;
38
40 protected $width;
41
43 protected $height;
44
46 protected $url;
47
49 protected $page;
50
52 protected $path;
53
55 protected $lang;
56
58 protected $storagePath = false;
59
63 public function getWidth() {
64 return $this->width;
65 }
66
70 public function getHeight() {
71 return $this->height;
72 }
73
77 public function getFile() {
78 return $this->file;
79 }
80
88 public function getExtension() {
89 return $this->path ? FileBackend::extensionFromPath( $this->path ) : false;
90 }
91
97 public function getUrl() {
98 return $this->url;
99 }
100
106 public function getStoragePath() {
107 return $this->storagePath;
108 }
109
116 public function setStoragePath( $storagePath ) {
117 $this->storagePath = $storagePath;
118 if ( $this->path === false ) {
119 $this->path = $storagePath;
120 }
121 }
122
143 abstract public function toHtml( $options = [] );
144
149 public function isError() {
150 return false;
151 }
152
164 public function hasFile() {
165 // If TRANSFORM_LATER, $this->path will be false.
166 // Note: a null path means "use the source file".
167 return ( !$this->isError() && ( $this->path || $this->path === null ) );
168 }
169
176 public function fileIsSource() {
177 return ( !$this->isError() && $this->path === null );
178 }
179
186 public function getLocalCopyPath() {
187 if ( $this->isError() ) {
188 return false;
189 } elseif ( $this->path === null ) {
190 return $this->file->getLocalRefPath(); // assume thumb was not scaled
191 } elseif ( FileBackend::isStoragePath( $this->path ) ) {
192 $be = $this->file->getRepo()->getBackend();
193 // The temp file will be process cached by FileBackend
194 $fsFile = $be->getLocalReference( [ 'src' => $this->path ] );
195
196 return $fsFile ? $fsFile->getPath() : false;
197 } else {
198 return $this->path; // may return false
199 }
200 }
201
209 public function streamFileWithStatus( $headers = [] ) {
210 if ( !$this->path ) {
211 return Status::newFatal( 'backend-fail-stream', '<no path>' );
212 } elseif ( FileBackend::isStoragePath( $this->path ) ) {
213 $be = $this->file->getRepo()->getBackend();
214 return Status::wrap(
215 $be->streamFile( [ 'src' => $this->path, 'headers' => $headers ] ) );
216 } else { // FS-file
217 $success = StreamFile::stream( $this->getLocalCopyPath(), $headers );
218 return $success ? Status::newGood() : Status::newFatal( 'backend-fail-stream', $this->path );
219 }
220 }
221
229 public function streamFile( $headers = [] ) {
230 return $this->streamFileWithStatus( $headers )->isOK();
231 }
232
240 protected function linkWrap( $linkAttribs, $contents ) {
241 if ( $linkAttribs ) {
242 return Xml::tags( 'a', $linkAttribs, $contents );
243 } else {
244 return $contents;
245 }
246 }
247
253 public function getDescLinkAttribs( $title = null, $params = [] ) {
254 if ( is_array( $params ) ) {
255 $query = $params;
256 } else {
257 $query = [];
258 }
259 if ( $this->page && $this->page !== 1 ) {
260 $query['page'] = $this->page;
261 }
262 if ( $this->lang ) {
263 $query['lang'] = $this->lang;
264 }
265
266 if ( is_string( $params ) && $params !== '' ) {
267 $query = $params . '&' . wfArrayToCgi( $query );
268 }
269
270 $attribs = [
271 'href' => $this->file->getTitle()->getLocalURL( $query ),
272 'class' => 'image',
273 ];
274 if ( $title ) {
275 $attribs['title'] = $title;
276 }
277
278 return $attribs;
279 }
280}
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
static isStoragePath( $path)
Check if a given path is a "mwstore://" path.
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:63
Base class for the output of MediaHandler::doTransform() and File::transform().
streamFileWithStatus( $headers=[])
Stream the file if there were no errors.
string $url
URL path to the thumb.
hasFile()
Check if an output thumbnail file actually exists.
getLocalCopyPath()
Get the path of a file system copy of the thumbnail.
bool string $lang
Language code, false if not set.
getUrl()
Stable to override.
fileIsSource()
Check if the output thumbnail is the same as the source.
linkWrap( $linkAttribs, $contents)
Wrap some XHTML text in an anchor tag with the given attributes.
getExtension()
Get the final extension of the thumbnail.
streamFile( $headers=[])
Stream the file if there were no errors.
getStoragePath()
Stable to override.
array $responsiveUrls
Associative array mapping optional supplementary image files from pixel density (eg 1....
setStoragePath( $storagePath)
Stable to override.
bool string $path
Filesystem path to the thumb.
isError()
This will be overridden to return true in error classes.
getDescLinkAttribs( $title=null, $params=[])
bool string $storagePath
Permanent storage path.
toHtml( $options=[])
Fetch HTML for this transform output.
static stream( $fname, $headers=[], $sendErrors=true, $optHeaders=[], $flags=0)
Stream a file to the browser, adding all the headings and fun stuff.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42
if(!isset( $args[0])) $lang