MediaWiki REL1_33
MediaTransformOutput.php
Go to the documentation of this file.
1<?php
29abstract class MediaTransformOutput {
33 public $responsiveUrls = [];
34
36 protected $file;
37
39 protected $width;
40
42 protected $height;
43
45 protected $url;
46
48 protected $page;
49
51 protected $path;
52
54 protected $lang;
55
57 protected $storagePath = false;
58
62 public function getWidth() {
63 return $this->width;
64 }
65
69 public function getHeight() {
70 return $this->height;
71 }
72
76 public function getFile() {
77 return $this->file;
78 }
79
85 public function getExtension() {
86 return $this->path ? FileBackend::extensionFromPath( $this->path ) : false;
87 }
88
92 public function getUrl() {
93 return $this->url;
94 }
95
99 public function getStoragePath() {
100 return $this->storagePath;
101 }
102
107 public function setStoragePath( $storagePath ) {
108 $this->storagePath = $storagePath;
109 if ( $this->path === false ) {
110 $this->path = $storagePath;
111 }
112 }
113
134 abstract public function toHtml( $options = [] );
135
140 public function isError() {
141 return false;
142 }
143
155 public function hasFile() {
156 // If TRANSFORM_LATER, $this->path will be false.
157 // Note: a null path means "use the source file".
158 return ( !$this->isError() && ( $this->path || $this->path === null ) );
159 }
160
167 public function fileIsSource() {
168 return ( !$this->isError() && $this->path === null );
169 }
170
177 public function getLocalCopyPath() {
178 if ( $this->isError() ) {
179 return false;
180 } elseif ( $this->path === null ) {
181 return $this->file->getLocalRefPath(); // assume thumb was not scaled
182 } elseif ( FileBackend::isStoragePath( $this->path ) ) {
183 $be = $this->file->getRepo()->getBackend();
184 // The temp file will be process cached by FileBackend
185 $fsFile = $be->getLocalReference( [ 'src' => $this->path ] );
186
187 return $fsFile ? $fsFile->getPath() : false;
188 } else {
189 return $this->path; // may return false
190 }
191 }
192
200 public function streamFileWithStatus( $headers = [] ) {
201 if ( !$this->path ) {
202 return Status::newFatal( 'backend-fail-stream', '<no path>' );
203 } elseif ( FileBackend::isStoragePath( $this->path ) ) {
204 $be = $this->file->getRepo()->getBackend();
205 return $be->streamFile( [ 'src' => $this->path, 'headers' => $headers ] );
206 } else { // FS-file
207 $success = StreamFile::stream( $this->getLocalCopyPath(), $headers );
208 return $success ? Status::newGood() : Status::newFatal( 'backend-fail-stream', $this->path );
209 }
210 }
211
219 public function streamFile( $headers = [] ) {
220 return $this->streamFileWithStatus( $headers )->isOK();
221 }
222
230 protected function linkWrap( $linkAttribs, $contents ) {
231 if ( $linkAttribs ) {
232 return Xml::tags( 'a', $linkAttribs, $contents );
233 } else {
234 return $contents;
235 }
236 }
237
243 public function getDescLinkAttribs( $title = null, $params = [] ) {
244 if ( is_array( $params ) ) {
245 $query = $params;
246 } else {
247 $query = [];
248 }
249 if ( $this->page && $this->page !== 1 ) {
250 $query['page'] = $this->page;
251 }
252 if ( $this->lang ) {
253 $query['lang'] = $this->lang;
254 }
255
256 if ( is_string( $params ) && $params !== '' ) {
257 $query = $params . '&' . wfArrayToCgi( $query );
258 }
259
260 $attribs = [
261 'href' => $this->file->getTitle()->getLocalURL( $query ),
262 'class' => 'image',
263 ];
264 if ( $title ) {
265 $attribs['title'] = $title;
266 }
267
268 return $attribs;
269 }
270}
target page
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:52
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.
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.
array $responsiveUrls
Associative array mapping optional supplementary image files from pixel density (eg 1....
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.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:1999
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition hooks.txt:2012
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
Definition hooks.txt:106
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1617
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$params