MediaWiki master
UploadStashFile.php
Go to the documentation of this file.
1<?php
22
28 private $fileKey;
30 private $urlName;
32 protected $url;
34 private $sha1;
35
49 public function __construct( $repo, $path, $key, $sha1 = null ) {
50 $this->fileKey = $key;
51 $this->sha1 = $sha1;
52
53 // resolve mwrepo:// urls
56 } else {
57 // check if path appears to be correct, no parent traversals,
58 // and is in this repo's temp zone.
59 $repoTempPath = $repo->getZonePath( 'temp' );
60 if ( ( !$repo->validateFilename( $path ) ) ||
61 !str_starts_with( $path, $repoTempPath )
62 ) {
63 wfDebug( "UploadStash: tried to construct an UploadStashFile "
64 . "from a file that should already exist at '$path', but path is not valid" );
66 wfMessage( 'uploadstash-bad-path-invalid' )
67 );
68 }
69
70 // check if path exists! and is a plain file.
71 if ( !$repo->fileExists( $path ) ) {
72 wfDebug( "UploadStash: tried to construct an UploadStashFile from "
73 . "a file that should already exist at '$path', but path is not found" );
75 wfMessage( 'uploadstash-file-not-found-not-exists' )
76 );
77 }
78 }
79
80 parent::__construct( false, $repo, $path, false );
81
82 $this->name = basename( $this->path );
83 }
84
91 public function getSha1() {
92 if ( !$this->sha1 ) {
93 $this->sha1 = parent::getSha1();
94 }
95 return $this->sha1;
96 }
97
106 public function getDescriptionUrl() {
107 return $this->getUrl();
108 }
109
120 public function getThumbPath( $thumbName = false ) {
121 $path = dirname( $this->path );
122 if ( $thumbName !== false ) {
123 $path .= "/$thumbName";
124 }
125
126 return $path;
127 }
128
138 public function thumbName( $params, $flags = 0 ) {
139 return $this->generateThumbName( $this->getUrlName(), $params );
140 }
141
148 private function getSpecialUrl( $subPage ) {
149 return SpecialPage::getTitleFor( 'UploadStash', $subPage )->getLocalURL();
150 }
151
162 public function getThumbUrl( $thumbName = false ) {
163 wfDebug( __METHOD__ . " getting for $thumbName" );
164
165 return $this->getSpecialUrl( 'thumb/' . $this->getUrlName() . '/' . $thumbName );
166 }
167
174 public function getUrlName() {
175 if ( !$this->urlName ) {
176 $this->urlName = $this->fileKey;
177 }
178
179 return $this->urlName;
180 }
181
188 public function getUrl() {
189 if ( $this->url === null ) {
190 $this->url = $this->getSpecialUrl( 'file/' . $this->getUrlName() );
191 }
192
193 return $this->url;
194 }
195
203 public function getFullUrl() {
204 return $this->getUrl();
205 }
206
213 public function getFileKey() {
214 return $this->fileKey;
215 }
216
221 public function remove() {
222 if ( !$this->repo->fileExists( $this->path ) ) {
223 // Maybe the file's already been removed? This could totally happen in UploadBase.
224 return true;
225 }
226
227 return $this->repo->freeTemp( $this->path );
228 }
229
230 public function exists() {
231 return $this->repo->fileExists( $this->path );
232 }
233}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
array $params
The job parameters.
resolveVirtualUrl( $url)
Get the backend storage path corresponding to a virtual URL.
Definition FileRepo.php:363
fileExists( $file)
Checks existence of a file.
getZonePath( $zone)
Get the storage path corresponding to one of the zones.
Definition FileRepo.php:403
static isVirtualUrl( $url)
Determine if a string is an mwrepo:// URL.
Definition FileRepo.php:293
validateFilename( $filename)
Determine if a relative path is valid, i.e.
FileRepo LocalRepo ForeignAPIRepo false $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:126
generateThumbName( $name, $params)
Generate a thumbnail file name from a name and specified parameters.
Definition File.php:1114
Parent class for all special pages.
File without associated database record.
exists()
Returns true if file exists in the repository.
getThumbPath( $thumbName=false)
Get the path for the thumbnail (actually any transformation of this file) The actual argument is the ...
getDescriptionUrl()
A method needed by the file transforming and scaling routines in File.php We do not necessarily care ...
getUrl()
Return the URL of the file, if for some reason we wanted to download it We tend not to do this for th...
string null $url
Lazy set as in-memory cache.
__construct( $repo, $path, $key, $sha1=null)
A LocalFile wrapper around a file that has been temporarily stashed, so we can do things like create ...
getThumbUrl( $thumbName=false)
Get a URL to access the thumbnail This is required because the model of how files work requires that ...
getFullUrl()
Parent classes use this method, for no obvious reason, to return the path (relative to wiki root,...
getUrlName()
The basename for the URL, which we want to not be related to the filename.
getSha1()
Get the SHA-1 base 36 hash.
getFileKey()
Getter for file key (the unique id by which this file's location & metadata is stored in the db)
thumbName( $params, $flags=0)
Return the file/url base name of a thumbnail with the specified parameters.