Go to the documentation of this file.
51 if ( !MediaWikiServices::getInstance()
53 ->userHasRight( $user,
'upload_by_url' )
55 return 'upload_by_url';
58 return parent::isAllowed( $user );
91 $whitelistedDomainPieces = explode(
'.', $domain );
92 $uploadDomainPieces = explode(
'.', $parsedUrl[
'host'] );
93 if ( count( $whitelistedDomainPieces ) === count( $uploadDomainPieces ) ) {
96 foreach ( $whitelistedDomainPieces as $index => $piece ) {
97 if ( $piece !==
'*' && $piece !== $uploadDomainPieces[$index] ) {
124 if ( !isset( self::$allowedUrls[$url] ) ) {
126 Hooks::run(
'IsUploadAllowedFromUrl', [ $url, &$allowed ] );
127 self::$allowedUrls[$url] = $allowed;
130 return self::$allowedUrls[$url];
144 # File size and removeTempFile will be filled in later
145 $this->initializePathInfo( $name, $tempPath, 0,
false );
153 $desiredDestName = $request->getText(
'wpDestFile' );
154 if ( !$desiredDestName ) {
155 $desiredDestName = $request->getText(
'wpUploadFileURL' );
159 trim( $request->getVal(
'wpUploadFileURL' ) )
170 $url = $request->getVal(
'wpUploadFileURL' );
172 return !empty( $url )
173 && MediaWikiServices::getInstance()
174 ->getPermissionManager()
175 ->userHasRight( $wgUser,
'upload_by_url' );
197 if ( !self::isAllowedHost( $this->mUrl ) ) {
200 if ( !self::isAllowedUrl( $this->mUrl ) ) {
212 $tmpFile = MediaWikiServices::getInstance()->getTempFSFileFactory()
213 ->newTempFSFile(
'URL',
'urlupload_' );
214 $tmpFile->bind( $this );
216 return $tmpFile->getPath();
227 wfDebugLog(
'fileupload',
'Received chunk of ' . strlen( $buffer ) .
' bytes' );
228 $nbytes = fwrite( $this->mTmpHandle, $buffer );
230 if ( $nbytes == strlen( $buffer ) ) {
231 $this->mFileSize += $nbytes;
236 'Short write ' . $nbytes .
'/' . strlen( $buffer ) .
237 ' bytes, aborting with ' . $this->mFileSize .
' uploaded so far'
239 fclose( $this->mTmpHandle );
240 $this->mTmpHandle =
false;
255 if ( $this->mTempPath ===
false ) {
260 $this->mTmpHandle = fopen( $this->mTempPath,
'wb' );
261 if ( !$this->mTmpHandle ) {
264 wfDebugLog(
'fileupload',
'Temporary file created "' . $this->mTempPath .
'"' );
266 $this->mRemoveTempFile =
true;
267 $this->mFileSize = 0;
269 $options = $httpOptions + [
'followRedirects' =>
true ];
280 'Starting download from "' . $this->mUrl .
'" ' .
281 '<' . implode(
',', array_keys( array_filter( $options ) ) ) .
'>'
284 $req->setCallback( [ $this,
'saveTempFileChunk' ] );
287 if ( $this->mTmpHandle ) {
289 fclose( $this->mTmpHandle );
290 $this->mTmpHandle =
null;
298 wfDebugLog(
'fileupload',
'Download by URL completed successfully.' );
302 'Download by URL completed with HTTP status ' . $req->getStatus()
static newFatal( $message,... $parameters)
Factory function for fatal errors.
$wgCopyUploadsDomains
A list of domains copy uploads can come from.
int bool $wgCopyUploadTimeout
Different timeout for upload by url This could be useful since when fetching large files,...
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
saveTempFileChunk( $req, $buffer)
Callback: save a chunk of the result of a HTTP request to the temporary file.
initialize( $name, $url)
Entry point for API upload.
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
Implements uploading from a HTTP resource.
makeTemporaryFile()
Create a new temporary file in the URL subdirectory of wfTempDir().
static isEnabled()
Checks if the upload from URL feature is enabled.
static isValidRequest( $request)
$wgCopyUploadProxy
Proxy to use for copy upload requests.
static isAllowedUrl( $url)
Checks whether the URL is not allowed.
static isAllowedHost( $url)
Checks whether the URL is for an allowed host The domains in the whitelist can include wildcard chara...
fetchFile( $httpOptions=[])
Download the file.
static isValidURI( $uri)
Check that the given URI is a valid one.
$wgAllowCopyUploads
Allow for upload to be copied from an URL.
static isAllowed(UserIdentity $user)
Checks if the user is allowed to use the upload-by-URL feature.
reallyFetchFile( $httpOptions=[])
Download the file, save it to the temporary file and update the file size and set $mRemoveTempFile to...
initializeFromRequest(&$request)
Entry point for SpecialUpload.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
static factory( $url, array $options=null, $caller=__METHOD__)
Generate a new request object.