From 72e90545454c0e014318fa3c81658e035aac58c1 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 10 Jun 2009 13:00:47 +0200 Subject: applying patch to version 1.15.0 --- includes/specials/SpecialUpload.php | 106 ++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 34 deletions(-) (limited to 'includes/specials/SpecialUpload.php') diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 450c8728..4c5bb160 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -62,6 +62,8 @@ class UploadForm { $this->mDesiredDestName = $request->getText( 'wpDestFile' ); $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' ); $this->mComment = $request->getText( 'wpUploadDescription' ); + $this->mForReUpload = $request->getBool( 'wpForReUpload' ); + $this->mReUpload = $request->getCheck( 'wpReUpload' ); if( !$request->wasPosted() ) { # GET requests just give the main form; no data except destination @@ -72,8 +74,6 @@ class UploadForm { # Placeholders for text injection by hooks (empty per default) $this->uploadFormTextTop = ""; $this->uploadFormTextAfterSummary = ""; - - $this->mReUpload = $request->getCheck( 'wpReUpload' ); $this->mUploadClicked = $request->getCheck( 'wpUpload' ); $this->mLicense = $request->getText( 'wpLicense' ); @@ -155,7 +155,7 @@ class UploadForm { * Returns true if there was an error, false otherwise */ private function curlCopy( $url, $dest ) { - global $wgUser, $wgOut; + global $wgUser, $wgOut, $wgHTTPProxy; if( !$wgUser->isAllowed( 'upload_by_url' ) ) { $wgOut->permissionRequired( 'upload_by_url' ); @@ -183,6 +183,9 @@ class UploadForm { curl_setopt( $ch, CURLOPT_TIMEOUT, 10); # 10 seconds timeout curl_setopt( $ch, CURLOPT_LOW_SPEED_LIMIT, 512); # 0.5KB per second minimum transfer speed curl_setopt( $ch, CURLOPT_URL, $url); + if( $wgHTTPProxy ) { + curl_setopt( $ch, CURLOPT_PROXY, $wgHTTPProxy ); + } curl_setopt( $ch, CURLOPT_WRITEFUNCTION, array( $this, 'uploadCurlCallback' ) ); curl_exec( $ch ); $error = curl_errno( $ch ) ? true : false; @@ -228,6 +231,12 @@ class UploadForm { global $wgUser, $wgOut; global $wgEnableUploads; + # Check php's file_uploads setting + if( !wfIniGetBool( 'file_uploads' ) ) { + $wgOut->showErrorPage( 'uploaddisabled', 'php-uploaddisabledtext', array( $this->mDesiredDestName ) ); + return; + } + # Check uploading enabled if( !$wgEnableUploads ) { $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext', array( $this->mDesiredDestName ) ); @@ -372,7 +381,7 @@ class UploadForm { if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) ) { - wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file." ); + wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" ); return self::BEFORE_PROCESSING; } @@ -504,11 +513,13 @@ class UploadForm { if ( ! $this->mIgnoreWarning ) { $warning = ''; - global $wgCapitalLinks; - if( $wgCapitalLinks ) { - $filtered = ucfirst( $filtered ); + $comparableName = str_replace( ' ', '_', $basename ); + global $wgCapitalLinks, $wgContLang; + if ( $wgCapitalLinks ) { + $comparableName = $wgContLang->ucfirst( $comparableName ); } - if( $basename != $filtered ) { + + if( $comparableName !== $filtered ) { $warning .= '
  • '.wfMsgHtml( 'badfilename', htmlspecialchars( $this->mDestName ) ).'
  • '; } @@ -541,7 +552,7 @@ class UploadForm { $warning .= self::getExistsWarning( $this->mLocalFile ); } - $warning .= $this->getDupeWarning( $this->mTempPath, $finalExt ); + $warning .= $this->getDupeWarning( $this->mTempPath, $finalExt, $nt ); if( $warning != '' ) { /** @@ -557,8 +568,10 @@ class UploadForm { * Try actually saving the thing... * It will show an error form on failure. */ - $pageText = self::getInitialPageText( $this->mComment, $this->mLicense, - $this->mCopyrightStatus, $this->mCopyrightSource ); + if( !$this->mForReUpload ) { + $pageText = self::getInitialPageText( $this->mComment, $this->mLicense, + $this->mCopyrightStatus, $this->mCopyrightSource ); + } $status = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText, File::DELETE_SOURCE, $this->mFileProps ); @@ -748,7 +761,7 @@ class UploadForm { * Check for duplicate files and throw up a warning before the upload * completes. */ - function getDupeWarning( $tempfile, $extension ) { + function getDupeWarning( $tempfile, $extension, $destinationTitle ) { $hash = File::sha1Base36( $tempfile ); $dupes = RepoGroup::singleton()->findBySha1( $hash ); $archivedImage = new ArchivedFile( null, 0, $hash.".$extension" ); @@ -757,8 +770,12 @@ class UploadForm { $msg = ""; foreach( $dupes as $file ) { $title = $file->getTitle(); - $msg .= $title->getPrefixedText() . - "|" . $title->getText() . "\n"; + # Don't throw the warning when the titles are the same, it's a reupload + # and highly redundant. + if ( !$title->equals( $destinationTitle ) || !$this->mForReUpload ) { + $msg .= $title->getPrefixedText() . + "|" . $title->getText() . "\n"; + } } $msg .= ""; return "
  • " . @@ -860,6 +877,7 @@ class UploadForm { */ function unsaveUploadedFile() { global $wgOut; + if( !$this->mTempPath ) return true; // nothing to delete $repo = RepoGroup::singleton()->getLocalRepo(); $success = $repo->freeTemp( $this->mTempPath ); if ( ! $success ) { @@ -958,7 +976,7 @@ wgUploadAutoFill = {$autofill}; if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) ) { - wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" ); + wfDebug( "Hook 'UploadForm:initial' broke output of the upload form\n" ); return false; } @@ -978,7 +996,7 @@ wgUploadAutoFill = {$autofill}; } // Show the relevant lines from deletion log (for still deleted files only) - if( $title instanceof Title && $title->isDeleted() > 0 && !$title->exists() ) { + if( $title instanceof Title && $title->isDeletedQuick() && !$title->exists() ) { $this->showDeletionLog( $wgOut, $title->getPrefixedText() ); } } @@ -1054,7 +1072,8 @@ wgUploadAutoFill = {$autofill}; $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) ); $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) ); - $summary = wfMsgExt( 'fileuploadsummary', 'parseinline' ); + $msg = $this->mForReUpload ? 'filereuploadsummary' : 'fileuploadsummary'; + $summary = wfMsgExt( $msg, 'parseinline' ); $licenses = new Licenses(); $license = wfMsgExt( 'license', array( 'parseinline' ) ); @@ -1068,10 +1087,9 @@ wgUploadAutoFill = {$autofill}; $encDestName = htmlspecialchars( $this->mDesiredDestName ); - $watchChecked = $this->watchCheck() - ? 'checked="checked"' - : ''; - $warningChecked = $this->mIgnoreWarning ? 'checked' : ''; + $watchChecked = $this->watchCheck() ? 'checked="checked"' : ''; + # Re-uploads should not need "file exist already" warnings + $warningChecked = ($this->mIgnoreWarning || $this->mForReUpload) ? 'checked="checked"' : ''; // Prepare form for upload or upload/copy if( $wgAllowCopyUploads && $wgUser->isAllowed( 'upload_by_url' ) ) { @@ -1106,8 +1124,8 @@ wgUploadAutoFill = {$autofill}; $warningRow = ''; $destOnkeyup = ''; } - $encComment = htmlspecialchars( $this->mComment ); + $wgOut->addHTML( Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL(), @@ -1135,10 +1153,26 @@ wgUploadAutoFill = {$autofill}; - - - + " + ); + if( $this->mForReUpload ) { + $wgOut->addHTML( + Xml::hidden( 'wpDestFile', $this->mDesiredDestName, array('id'=>'wpDestFile','tabindex'=>2) ) . + "" . + $encDestName . + "" + ); + } + else { + $wgOut->addHTML( + "" + ); + } + + + $wgOut->addHTML( + " @@ -1152,8 +1186,8 @@ wgUploadAutoFill = {$autofill}; " ); - - if ( $licenseshtml != '' ) { + # Re-uploads should not need license info + if ( !$this->mForReUpload && $licenseshtml != '' ) { global $wgStylePath; $wgOut->addHTML( " @@ -1179,7 +1213,7 @@ wgUploadAutoFill = {$autofill}; } } - if ( $wgUseCopyrightUpload ) { + if ( !$this->mForReUpload && $wgUseCopyrightUpload ) { $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' ); $copystatus = htmlspecialchars( $this->mCopyrightStatus ); $filesource = wfMsgExt( 'filesource', 'escapenoentities' ); @@ -1211,7 +1245,7 @@ wgUploadAutoFill = {$autofill}; - + @@ -1219,19 +1253,23 @@ wgUploadAutoFill = {$autofill}; - getSkin()->tooltipAndAccesskey( 'upload' ) . " /> + getSkin()->tooltipAndAccesskey( 'upload' ) . " /> " ); - $wgOut->addWikiText( wfMsgForContent( 'edittools' ) ); + $wgOut->addHTML( '
    ' ); + $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) ); + $wgOut->addHTML( '
    ' ); $wgOut->addHTML( " " . Xml::closeElement( 'table' ) . Xml::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) . + Xml::hidden( 'wpForReUpload', $this->mForReUpload, array( 'id' => 'wpForReUpload' ) ) . Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ) ); @@ -1648,7 +1686,7 @@ wgUploadAutoFill = {$autofill}; } } - wfDebug( __METHOD__.": FOUND VIRUS! scanner feedback: $output" ); + wfDebug( __METHOD__.": FOUND VIRUS! scanner feedback: $output \n" ); return $output; } } @@ -1685,7 +1723,7 @@ wgUploadAutoFill = {$autofill}; * @access private */ function cleanupTempFile() { - if ( $this->mRemoveTempFile && file_exists( $this->mTempPath ) ) { + if ( $this->mRemoveTempFile && $this->mTempPath && file_exists( $this->mTempPath ) ) { wfDebug( "SpecialUpload::cleanupTempFile: Removing temporary file {$this->mTempPath}\n" ); unlink( $this->mTempPath ); } -- cgit v1.2.3-54-g00ecf