if ( !$user->isAllowed( 'upload_by_url' ) ) {
return 'upload_by_url';
}
+
return parent::isAllowed( $user );
}
*/
public static function isEnabled() {
global $wgAllowCopyUploads;
+
return $wgAllowCopyUploads && parent::isEnabled();
}
}
*/
}
+
return $valid;
}
public static function isAllowedUrl( $url ) {
if ( !isset( self::$allowedUrls[$url] ) ) {
$allowed = true;
- wfRunHooks( 'IsUploadAllowedFromUrl', array( $url, &$allowed ) );
+ Hooks::run( 'IsUploadAllowedFromUrl', array( $url, &$allowed ) );
self::$allowedUrls[$url] = $allowed;
}
+
return self::$allowedUrls[$url];
}
global $wgUser;
$url = $request->getVal( 'wpUploadFileURL' );
+
return !empty( $url )
&& Http::isValidURI( $url )
&& $wgUser->isAllowed( 'upload_by_url' );
if ( !$this->mAsync ) {
return $this->reallyFetchFile( $httpOptions );
}
+
return Status::newGood();
}
protected function makeTemporaryFile() {
$tmpFile = TempFSFile::factory( 'URL' );
$tmpFile->bind( $this );
+
return $tmpFile->getPath();
}
* @return int Number of bytes handled
*/
public function saveTempFileChunk( $req, $buffer ) {
+ wfDebugLog( 'fileupload', 'Received chunk of ' . strlen( $buffer ) . ' bytes' );
$nbytes = fwrite( $this->mTmpHandle, $buffer );
if ( $nbytes == strlen( $buffer ) ) {
$this->mFileSize += $nbytes;
} else {
// Well... that's not good!
+ wfDebugLog(
+ 'fileupload',
+ 'Short write ' . $this->nbytes . '/' . strlen( $buffer ) .
+ ' bytes, aborting with ' . $this->mFileSize . ' uploaded so far'
+ );
fclose( $this->mTmpHandle );
$this->mTmpHandle = false;
}
if ( !$this->mTmpHandle ) {
return Status::newFatal( 'tmp-create-error' );
}
+ wfDebugLog( 'fileupload', 'Temporary file created "' . $this->mTempPath . '"' );
$this->mRemoveTempFile = true;
$this->mFileSize = 0;
- $options = $httpOptions + array(
- 'followRedirects' => true,
- );
+ $options = $httpOptions + array( 'followRedirects' => true );
+
if ( $wgCopyUploadProxy !== false ) {
$options['proxy'] = $wgCopyUploadProxy;
}
+
if ( $wgCopyUploadTimeout && !isset( $options['timeout'] ) ) {
$options['timeout'] = $wgCopyUploadTimeout;
}
+ wfDebugLog(
+ 'fileupload',
+ 'Starting download from "' . $this->mUrl . '" ' .
+ '<' . implode( ',', array_keys( array_filter( $options ) ) ) . '>'
+ );
$req = MWHttpRequest::factory( $this->mUrl, $options );
$req->setCallback( array( $this, 'saveTempFileChunk' ) );
$status = $req->execute();
return Status::newFatal( 'tmp-write-error' );
}
- if ( !$status->isOk() ) {
- return $status;
+ wfDebugLog( 'fileupload', $status );
+ if ( $status->isOk() ) {
+ wfDebugLog( 'fileupload', 'Download by URL completed successfuly.' );
+ } else {
+ wfDebugLog(
+ 'fileupload',
+ 'Download by URL completed with HTTP status ' . $req->getStatus()
+ );
}
return $status;
if ( $this->mAsync ) {
return array( 'status' => UploadBase::OK );
}
+
return parent::verifyUpload();
}
public function checkWarnings() {
if ( $this->mAsync ) {
$this->mIgnoreWarnings = false;
+
return array();
}
+
return parent::checkWarnings();
}
if ( $this->mAsync ) {
return true;
}
+
return parent::verifyTitlePermissions( $user );
}
) );
$job->initializeSessionData();
JobQueueGroup::singleton()->push( $job );
+
return $sessionKey;
}
-
}