MediaWiki master
UploadStashFile.php
Go to the documentation of this file.
1<?php
22
27 private $fileKey;
28 private $urlName;
29 protected $url;
30 private $sha1;
31
45 public function __construct( $repo, $path, $key, $sha1 = null ) {
46 $this->fileKey = $key;
47 $this->sha1 = $sha1;
48
49 // resolve mwrepo:// urls
52 } else {
53 // check if path appears to be correct, no parent traversals,
54 // and is in this repo's temp zone.
55 $repoTempPath = $repo->getZonePath( 'temp' );
56 if ( ( !$repo->validateFilename( $path ) ) ||
57 !str_starts_with( $path, $repoTempPath )
58 ) {
59 wfDebug( "UploadStash: tried to construct an UploadStashFile "
60 . "from a file that should already exist at '$path', but path is not valid" );
62 wfMessage( 'uploadstash-bad-path-invalid' )
63 );
64 }
65
66 // check if path exists! and is a plain file.
67 if ( !$repo->fileExists( $path ) ) {
68 wfDebug( "UploadStash: tried to construct an UploadStashFile from "
69 . "a file that should already exist at '$path', but path is not found" );
71 wfMessage( 'uploadstash-file-not-found-not-exists' )
72 );
73 }
74 }
75
76 parent::__construct( false, $repo, $path, false );
77
78 $this->name = basename( $this->path );
79 }
80
87 public function getSha1() {
88 if ( !$this->sha1 ) {
89 $this->sha1 = parent::getSha1();
90 }
91 return $this->sha1;
92 }
93
102 public function getDescriptionUrl() {
103 return $this->getUrl();
104 }
105
116 public function getThumbPath( $thumbName = false ) {
117 $path = dirname( $this->path );
118 if ( $thumbName !== false ) {
119 $path .= "/$thumbName";
120 }
121
122 return $path;
123 }
124
134 public function thumbName( $params, $flags = 0 ) {
135 return $this->generateThumbName( $this->getUrlName(), $params );
136 }
137
144 private function getSpecialUrl( $subPage ) {
145 return SpecialPage::getTitleFor( 'UploadStash', $subPage )->getLocalURL();
146 }
147
158 public function getThumbUrl( $thumbName = false ) {
159 wfDebug( __METHOD__ . " getting for $thumbName" );
160
161 return $this->getSpecialUrl( 'thumb/' . $this->getUrlName() . '/' . $thumbName );
162 }
163
170 public function getUrlName() {
171 if ( !$this->urlName ) {
172 $this->urlName = $this->fileKey;
173 }
174
175 return $this->urlName;
176 }
177
184 public function getUrl() {
185 if ( !isset( $this->url ) ) {
186 $this->url = $this->getSpecialUrl( 'file/' . $this->getUrlName() );
187 }
188
189 return $this->url;
190 }
191
199 public function getFullUrl() {
200 return $this->getUrl();
201 }
202
209 public function getFileKey() {
210 return $this->fileKey;
211 }
212
217 public function remove() {
218 if ( !$this->repo->fileExists( $this->path ) ) {
219 // Maybe the file's already been removed? This could totally happen in UploadBase.
220 return true;
221 }
222
223 return $this->repo->freeTemp( $this->path );
224 }
225
226 public function exists() {
227 return $this->repo->fileExists( $this->path );
228 }
229}
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:357
fileExists( $file)
Checks existence of a file.
getZonePath( $zone)
Get the storage path corresponding to one of the zones.
Definition FileRepo.php:397
static isVirtualUrl( $url)
Determine if a string is an mwrepo:// URL.
Definition FileRepo.php:287
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:120
generateThumbName( $name, $params)
Generate a thumbnail file name from a name and specified parameters.
Definition File.php:1094
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...
__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.