X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fupload%2FUploadBase.php;h=105a42164947004f64c7fc656bb30ed9936c45e1;hb=8c5d8418538328449678150cd60d8aef53e59212;hp=7926861bd5be6b4a79b4ee68efd2354e056badb7;hpb=c601562cff3f5bb2780831cebde36a7d74dd0c99;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 7926861bd5..105a421649 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -22,20 +22,15 @@ abstract class UploadBase { const SUCCESS = 0; const OK = 0; - const BEFORE_PROCESSING = 1; - const LARGE_FILE_SERVER = 2; const EMPTY_FILE = 3; const MIN_LENGTH_PARTNAME = 4; const ILLEGAL_FILENAME = 5; - const PROTECTED_PAGE = 6; const OVERWRITE_EXISTING_FILE = 7; const FILETYPE_MISSING = 8; const FILETYPE_BADTYPE = 9; const VERIFICATION_ERROR = 10; const UPLOAD_VERIFICATION_ERROR = 11; - const UPLOAD_WARNING = 12; - const INTERNAL_ERROR = 13; - const MIN_LENGHT_PARTNAME = 14; + const HOOK_ABORTED = 11; const SESSION_VERSION = 2; @@ -80,10 +75,16 @@ abstract class UploadBase { // Get the upload class $type = ucfirst( $type ); - $className = 'UploadFrom' . $type; - wfDebug( __METHOD__ . ": class name: $className\n" ); - if( !in_array( $type, self::$uploadHandlers ) ) - return null; + + // Give hooks the chance to handle this request + $className = null; + wfRunHooks( 'UploadCreateFromRequest', array( $type, &$className ) ); + if ( is_null( $className ) ) { + $className = 'UploadFrom' . $type; + wfDebug( __METHOD__ . ": class name: $className\n" ); + if( !in_array( $type, self::$uploadHandlers ) ) + return null; + } // Check whether this upload class is enabled if( !call_user_func( array( $className, 'isEnabled' ) ) ) @@ -136,12 +137,12 @@ abstract class UploadBase { public function isEmptyFile(){ return empty( $this->mFileSize ); } - - /* - * getRealPath - * @param string $srcPath the source path - * @returns the real path if it was a virtual url - */ + + /** + * getRealPath + * @param string $srcPath the source path + * @returns the real path if it was a virtual url + */ function getRealPath( $srcPath ){ $repo = RepoGroup::singleton()->getLocalRepo(); if ( $repo->isVirtualUrl( $srcPath ) ) { @@ -160,7 +161,21 @@ abstract class UploadBase { */ if( $this->isEmptyFile() ) return array( 'status' => self::EMPTY_FILE ); + + /** + * Look at the contents of the file; if we can recognize the + * type but it's corrupt or data of the wrong type, we should + * probably not accept it. + */ + $verification = $this->verifyFile(); + if( $verification !== true ) { + if( !is_array( $verification ) ) + $verification = array( $verification ); + return array( 'status' => self::VERIFICATION_ERROR, + 'details' => $verification ); + } + $nt = $this->getTitle(); if( is_null( $nt ) ) { $result = array( 'status' => $this->mTitleError ); @@ -179,26 +194,11 @@ abstract class UploadBase { if( $overwrite !== true ) return array( 'status' => self::OVERWRITE_EXISTING_FILE, 'overwrite' => $overwrite ); - /** - * Look at the contents of the file; if we can recognize the - * type but it's corrupt or data of the wrong type, we should - * probably not accept it. - */ - $verification = $this->verifyFile(); - - if( $verification !== true ) { - if( !is_array( $verification ) ) - $verification = array( $verification ); - return array( 'status' => self::VERIFICATION_ERROR, - 'details' => $verification ); - - } - $error = ''; if( !wfRunHooks( 'UploadVerification', array( $this->mDestName, $this->mTempPath, &$error ) ) ) { // This status needs another name... - return array( 'status' => self::UPLOAD_VERIFICATION_ERROR, 'error' => $error ); + return array( 'status' => self::HOOK_ABORTED, 'error' => $error ); } return array( 'status' => self::OK ); @@ -306,6 +306,7 @@ abstract class UploadBase { */ $comparableName = str_replace( ' ', '_', $this->mDesiredDestName ); $comparableName = Title::capitalize( $comparableName, NS_FILE ); + if( $this->mDesiredDestName != $filename && $comparableName != $filename ) $warnings['badfilename'] = $filename; @@ -468,19 +469,6 @@ abstract class UploadBase { return $status; } - /** - * Append a file to a stashed file. - * - * @param string $srcPath Path to file to append from - * @param string $toAppendPath Path to file to append to - * @return Status Status - */ - public function appendToUploadFile( $srcPath, $toAppendPath ){ - $repo = RepoGroup::singleton()->getLocalRepo(); - $status = $repo->append( $srcPath, $toAppendPath ); - return $status; - } - /** * Stash a file in a temporary directory for later processing, * and save the necessary descriptive info into the session. @@ -516,15 +504,6 @@ abstract class UploadBase { return $key; } - /** - * Remove a temporarily kept file stashed by saveTempUploadedFile(). - * @return success - */ - public function unsaveUploadedFile() { - $repo = RepoGroup::singleton()->getLocalRepo(); - $success = $repo->freeTemp( $this->mTempPath ); - return $success; - } /** * If we've modified the upload file we need to manually remove it @@ -608,7 +587,7 @@ abstract class UploadBase { $match = $magic->isMatchingExtension( $extension, $mime ); - if ( $match === NULL ) { + if ( $match === null ) { wfDebug( __METHOD__ . ": no file extension known for mime type $mime, passing file\n" ); return true; } elseif( $match === true ) { @@ -658,7 +637,7 @@ abstract class UploadBase { elseif( substr( $chunk, 0, 2 ) == "\xff\xfe" ) $enc = "UTF-16LE"; else - $enc = NULL; + $enc = null; if( $enc ) $chunk = iconv( $enc, "ASCII//IGNORE", $chunk ); @@ -781,7 +760,7 @@ abstract class UploadBase { if ( !$wgAntivirus ) { wfDebug( __METHOD__ . ": virus scanner disabled\n" ); - return NULL; + return null; } if ( !$wgAntivirusSetup[$wgAntivirus] ) { @@ -812,13 +791,7 @@ abstract class UploadBase { #NOTE: there's a 50 line workaround to make stderr redirection work on windows, too. # that does not seem to be worth the pain. # Ask me (Duesentrieb) about it if it's ever needed. - $output = array(); - if ( wfIsWindows() ) { - $output = wfRunExternal($command, $exitCode); - } else { - exec( "$command 2>&1", $output, $exitCode ); - } - + $output = wfShellExec( "$command 2>&1", $exitCode ); # map exit code to AV_xxx constants. $mappedCode = $exitCode; @@ -830,7 +803,6 @@ abstract class UploadBase { } } - if ( $mappedCode === AV_SCAN_FAILED ) { # scan failed (code was mapped to false by $exitCodeMap) wfDebug( __METHOD__ . ": failed to scan $file (code $exitCode).\n" ); @@ -838,18 +810,17 @@ abstract class UploadBase { if ( $wgAntivirusRequired ) { return wfMsg( 'virus-scanfailed', array( $exitCode ) ); } else { - return NULL; + return null; } } else if ( $mappedCode === AV_SCAN_ABORTED ) { # scan failed because filetype is unknown (probably imune) wfDebug( __METHOD__ . ": unsupported file type $file (code $exitCode).\n" ); - return NULL; + return null; } else if ( $mappedCode === AV_NO_VIRUS ) { # no virus found wfDebug( __METHOD__ . ": file passed virus scan.\n" ); return false; } else { - $output = join( "\n", $output ); $output = trim( $output ); if ( !$output ) {