Kill a bunch of unused $wgUser
[lhc/web/wiklou.git] / includes / specials / SpecialUpload.php
index 207f44e..232064d 100644 (file)
@@ -62,6 +62,7 @@ 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() ) {
@@ -73,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' );
@@ -156,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, $wgCopyUploadTimeout;
 
                if( !$wgUser->isAllowed( 'upload_by_url' ) ) {
                        $wgOut->permissionRequired( 'upload_by_url' );
@@ -181,9 +180,12 @@ class UploadForm {
 
                $ch = curl_init();
                curl_setopt( $ch, CURLOPT_HTTP_VERSION, 1.0); # Probably not needed, but apparently can work around some bug
-               curl_setopt( $ch, CURLOPT_TIMEOUT, 10); # 10 seconds timeout
+               curl_setopt( $ch, CURLOPT_TIMEOUT, $wgCopyUploadTimeout); # Default 30 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;
@@ -286,7 +288,7 @@ class UploadForm {
         * @access private
         */
        function processUpload(){
-               global $wgUser, $wgOut, $wgFileExtensions, $wgLang;
+               global $wgOut, $wgFileExtensions, $wgLang;
                $details = null;
                $value = null;
                $value = $this->internalProcessUpload( $details );
@@ -550,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 != '' ) {
                                /**
@@ -566,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 );
@@ -757,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" );
@@ -766,8 +770,12 @@ class UploadForm {
                        $msg = "<gallery>";
                        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 .= "</gallery>";
                        return "<li>" .
@@ -988,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() );
                        }
                }
@@ -1064,7 +1072,7 @@ wgUploadAutoFill = {$autofill};
                $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
         $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) ); 
                
-               $msg = $this->mReUpload ? 'filereuploadsummary' : 'fileuploadsummary';
+               $msg = $this->mForReUpload ? 'filereuploadsummary' : 'fileuploadsummary';
                $summary = wfMsgExt( $msg, 'parseinline' );
 
                $licenses = new Licenses();
@@ -1081,7 +1089,7 @@ wgUploadAutoFill = {$autofill};
 
                $watchChecked = $this->watchCheck() ? 'checked="checked"' : '';
                # Re-uploads should not need "file exist already" warnings
-               $warningChecked = ($this->mIgnoreWarning || $this->mReUpload) ? 'checked="checked"' : '';
+               $warningChecked = ($this->mIgnoreWarning || $this->mForReUpload) ? 'checked="checked"' : '';
 
                // Prepare form for upload or upload/copy
                if( $wgAllowCopyUploads && $wgUser->isAllowed( 'upload_by_url' ) ) {
@@ -1116,10 +1124,8 @@ wgUploadAutoFill = {$autofill};
                        $warningRow = '';
                        $destOnkeyup = '';
                }
-               # Uploading a new version? If so, the name is fixed.
-               $on = $this->mReUpload ? "disabled='disabled'" : "";
-
                $encComment = htmlspecialchars( $this->mComment );
+               
 
                $wgOut->addHTML(
                         Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL(),
@@ -1147,10 +1153,26 @@ wgUploadAutoFill = {$autofill};
                                <td class='mw-label'>
                                        <label for='wpDestFile'>{$destfilename}</label>
                                </td>
-                               <td class='mw-input'>
-                                       <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
-                                               value=\"{$encDestName}\" onchange='toggleFilenameFiller()' $on $destOnkeyup />
-                               </td>
+                               <td class='mw-input'>"
+               );
+               if( $this->mForReUpload ) {
+                       $wgOut->addHTML(
+                               Xml::hidden( 'wpDestFile', $this->mDesiredDestName, array('id'=>'wpDestFile','tabindex'=>2) ) .
+                               "<tt>" .
+                               $encDestName .
+                               "</tt>"
+                       );
+               }
+               else {
+                       $wgOut->addHTML(
+                               "<input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
+                                               value=\"{$encDestName}\" onchange='toggleFilenameFiller()' $destOnkeyup />"
+                       );
+               }
+               
+
+               $wgOut->addHTML(
+                               "</td>
                        </tr>
                        <tr>
                                <td class='mw-label'>
@@ -1165,7 +1187,7 @@ wgUploadAutoFill = {$autofill};
                        <tr>"
                );
                # Re-uploads should not need license info
-               if ( !$this->mReUpload && $licenseshtml != '' ) {
+               if ( !$this->mForReUpload && $licenseshtml != '' ) {
                        global $wgStylePath;
                        $wgOut->addHTML( "
                                        <td class='mw-label'>
@@ -1191,7 +1213,7 @@ wgUploadAutoFill = {$autofill};
                        }
                }
 
-               if ( !$this->mReUpload && $wgUseCopyrightUpload ) {
+               if ( !$this->mForReUpload && $wgUseCopyrightUpload ) {
                        $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
                        $copystatus =  htmlspecialchars( $this->mCopyrightStatus );
                        $filesource = wfMsgExt( 'filesource', 'escapenoentities' );
@@ -1231,19 +1253,23 @@ wgUploadAutoFill = {$autofill};
                        <tr>
                                <td></td>
                                        <td class='mw-input'>
-                                               <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" . $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
+                                               <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" .
+                                                       $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
                                        </td>
                        </tr>
                        <tr>
                                <td></td>
                                <td class='mw-input'>"
                );
-               $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
+               $wgOut->addHTML( '<div class="mw-editTools">' );
+               $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
+               $wgOut->addHTML( '</div>' );
                $wgOut->addHTML( "
                                </td>
                        </tr>" .
                        Xml::closeElement( 'table' ) .
                        Xml::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
+                       Xml::hidden( 'wpForReUpload', $this->mForReUpload, array( 'id' => 'wpForReUpload' ) ) .
                        Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' )
                );