* Confirmation is now required when deleting old versions of files
[lhc/web/wiklou.git] / includes / SpecialUpload.php
index a1f5771..1c738cc 100644 (file)
@@ -26,7 +26,7 @@ class UploadForm {
        var $mDestName, $mTempPath, $mFileSize, $mFileProps;
        var $mCopyrightStatus, $mCopyrightSource, $mReUpload, $mAction, $mUploadClicked;
        var $mSrcName, $mSessionKey, $mStashed, $mDesiredDestName, $mRemoveTempFile, $mSourceType;
-       var $mCurlDestHandle;
+       var $mDestWarningAck, $mCurlDestHandle;
        var $mLocalFile;
 
        # Placeholders for text injection by hooks (must be HTML)
@@ -46,9 +46,11 @@ class UploadForm {
                global $wgAllowCopyUploads;
                $this->mDesiredDestName   = $request->getText( 'wpDestFile' );
                $this->mIgnoreWarning     = $request->getCheck( 'wpIgnoreWarning' );
+               $this->mComment           = $request->getText( 'wpUploadDescription' );
 
                if( !$request->wasPosted() ) {
-                       # GET requests just give the main form; no data except wpDestfile.
+                       # GET requests just give the main form; no data except destination
+                       # filename and description
                        return;
                }
 
@@ -59,13 +61,12 @@ class UploadForm {
                $this->mReUpload          = $request->getCheck( 'wpReUpload' );
                $this->mUploadClicked     = $request->getCheck( 'wpUpload' );
 
-               $this->mComment           = $request->getText( 'wpUploadDescription' );
                $this->mLicense           = $request->getText( 'wpLicense' );
                $this->mCopyrightStatus   = $request->getText( 'wpUploadCopyStatus' );
                $this->mCopyrightSource   = $request->getText( 'wpUploadSource' );
                $this->mWatchthis         = $request->getBool( 'wpWatchthis' );
                $this->mSourceType        = $request->getText( 'wpSourceType' );
-               wfDebug( "UploadForm: watchthis is: '$this->mWatchthis'\n" );
+               $this->mDestWarningAck    = $request->getText( 'wpDestFileWarningAck' );
 
                $this->mAction            = $request->getVal( 'action' );
 
@@ -284,16 +285,17 @@ class UploadForm {
 
                # Chop off any directories in the given filename
                if( $this->mDesiredDestName ) {
-                       $basename = wfBaseName( $this->mDesiredDestName );
+                       $basename = $this->mDesiredDestName;
                } else {
-                       $basename = wfBaseName( $this->mSrcName );
+                       $basename = $this->mSrcName;
                }
+               $filtered = wfBaseName( $basename );
 
                /**
                 * We'll want to blacklist against *any* 'extension', and use
                 * only the final one for the whitelist.
                 */
-               list( $partname, $ext ) = $this->splitExtensions( $basename );
+               list( $partname, $ext ) = $this->splitExtensions( $filtered );
 
                if( count( $ext ) ) {
                        $finalExt = $ext[count( $ext ) - 1];
@@ -317,7 +319,7 @@ class UploadForm {
                 * Filter out illegal characters, and try to make a legible name
                 * out of it. We'll strip some silently that Title would die on.
                 */
-               $filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $basename );
+               $filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $filtered );
                $nt = Title::makeTitleSafe( NS_IMAGE, $filtered );
                if( is_null( $nt ) ) {
                        $this->uploadError( wfMsgWikiHtml( 'illegalfilename', htmlspecialchars( $filtered ) ) );
@@ -368,7 +370,7 @@ class UploadForm {
                        }
 
                        /**
-                        * Provide an opportunity for extensions to add futher checks
+                        * Provide an opportunity for extensions to add further checks
                         */
                        $error = '';
                        if( !wfRunHooks( 'UploadVerification',
@@ -388,7 +390,7 @@ class UploadForm {
                        if( $wgCapitalLinks ) {
                                $filtered = ucfirst( $filtered );
                        }
-                       if( $this->mDestName != $filtered ) {
+                       if( $basename != $filtered ) {
                                $warning .=  '<li>'.wfMsgHtml( 'badfilename', htmlspecialchars( $this->mDestName ) ).'</li>';
                        }
 
@@ -411,89 +413,9 @@ class UploadForm {
                                $warning .= '<li>'.wfMsgHtml( 'emptyfile' ).'</li>';
                        }
 
-                       global $wgUser;
-                       $sk = $wgUser->getSkin();
-
-                       // Check for uppercase extension. We allow these filenames but check if an image
-                       // with lowercase extension exists already
-                       if ( $finalExt != strtolower( $finalExt ) ) {
-                               $nt_lc = Title::newFromText( $partname . '.' . strtolower( $finalExt ) );
-                               $image_lc = wfLocalFile( $nt_lc );
-                       }
-
-                       if( $this->mLocalFile->exists() ) {
-                               $dlink = $sk->makeKnownLinkObj( $nt );
-                               if ( $this->mLocalFile->allowInlineDisplay() ) {
-                                       $dlink2 = $sk->makeImageLinkObj( $nt, wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
-                                               $nt->getText(), 'right', array(), false, true );
-                               } elseif ( !$this->mLocalFile->allowInlineDisplay() && $this->mLocalFile->isSafeFile() ) {
-                                       $icon = $this->mLocalFile->iconThumb();
-                                       $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $this->mLocalFile->getURL() . '">' . 
-                                               $icon->toHtml() . '</a><br />' . $dlink . '</div>';
-                               } else {
-                                       $dlink2 = '';
-                               }
-
-                               $warning .= '<li>' . wfMsgExt( 'fileexists', 'parseline', $dlink ) . '</li>' . $dlink2;
-
-                       } elseif ( isset( $image_lc) && $image_lc->exists() ) {
-                               # Check if image with lowercase extension exists.
-                               # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
-                               $dlink = $sk->makeKnownLinkObj( $nt_lc );
-                               if ( $image_lc->allowInlineDisplay() ) {
-                                       $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
-                                               $nt_lc->getText(), 'right', array(), false, true );
-                               } elseif ( !$image_lc->allowInlineDisplay() && $image_lc->isSafeFile() ) {
-                                       $icon = $image_lc->iconThumb();
-                                       $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $image_lc->getURL() . '">' . 
-                                               $icon->toHtml() . '</a><br />' . $dlink . '</div>';
-                               } else {
-                                       $dlink2 = '';
-                               }
-
-                               $warning .= '<li>' . wfMsgExt( 'fileexists-extension', 'parsemag' , $partname . '.' 
-                                       . $finalExt , $dlink ) . '</li>' . $dlink2;                             
-
-                       } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' ) 
-                               && ereg( "[0-9]{2}" , substr( $partname , 0, 2) ) )
-                       {
-                               # Check for filenames like 50px- or 180px-, these are mostly thumbnails
-                               $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $finalExt );
-                               $image_thb = wfLocalFile( $nt_thb );
-                               if ($image_thb->exists() ) {
-                                       # Check if an image without leading '180px-' (or similiar) exists
-                                       $dlink = $sk->makeKnownLinkObj( $nt_thb);
-                                       if ( $image_thb->allowInlineDisplay() ) {
-                                               $dlink2 = $sk->makeImageLinkObj( $nt_thb, 
-                                                       wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
-                                                       $nt_thb->getText(), 'right', array(), false, true );
-                                       } elseif ( !$image_thb->allowInlineDisplay() && $image_thb->isSafeFile() ) {
-                                               $icon = $image_thb->iconThumb();
-                                               $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . 
-                                                       $image_thb->getURL() . '">' . $icon->toHtml() . '</a><br />' . 
-                                                       $dlink . '</div>';
-                                       } else {
-                                               $dlink2 = '';
-                                       }
-
-                                       $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) . 
-                                               '</li>' . $dlink2;      
-                               } else {
-                                       # Image w/o '180px-' does not exists, but we do not like these filenames
-                                       $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' , 
-                                               substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>';
-                               }
-                       }
-                       if ( $this->mLocalFile->wasDeleted() ) {
-                               # If the file existed before and was deleted, warn the user of this
-                               # Don't bother doing so if the image exists now, however
-                               $ltitle = SpecialPage::getTitleFor( 'Log' );
-                               $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ), 
-                                       'type=delete&page=' . $nt->getPrefixedUrl() );
-                               $warning .= wfOpenElement( 'li' ) . wfMsgWikiHtml( 'filewasdeleted', $llink ) . 
-                                       wfCloseElement( 'li' );
+                       if ( !$this->mDestWarningAck ) {
+                               $warning .= self::getExistsWarning( $this->mLocalFile );
                        }
-
                        if( $warning != '' ) {
                                /**
                                 * Stash the file in a temporary location; the user can choose
@@ -510,20 +432,152 @@ class UploadForm {
                $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
                        $this->mCopyrightStatus, $this->mCopyrightSource );
 
-               $error = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText, 
+               $status = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText, 
                        File::DELETE_SOURCE, $this->mFileProps );
-               if ( WikiError::isError( $error ) ) {
-                       $this->showError( $error );
+               if ( !$status->isGood() ) {
+                       $this->showError( $status->getWikiText() );
                } else {
                        if ( $this->mWatchthis ) {
                                global $wgUser;
                                $wgUser->addWatch( $this->mLocalFile->getTitle() );
                        }
-                       $this->showSuccess();
+                       // Success, redirect to description page
+                       $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
                        wfRunHooks( 'UploadComplete', array( &$img ) );
                }
        }
 
+       /**
+        * Do existence checks on a file and produce a warning
+        * This check is static and can be done pre-upload via AJAX
+        * Returns an HTML fragment consisting of one or more LI elements if there is a warning
+        * Returns an empty string if there is no warning
+        */
+       static function getExistsWarning( $file ) {
+               global $wgUser;
+               // Check for uppercase extension. We allow these filenames but check if an image
+               // with lowercase extension exists already
+               $warning = '';
+               $ext = $file->getExtension();
+               $sk = $wgUser->getSkin();
+               if ( $ext !== '' ) {
+                       $partname = substr( $file->getName(), 0, -strlen( $ext ) - 1 );
+               } else {
+                       $partname = $file->getName();
+               }
+
+               if ( $ext != strtolower( $ext ) ) {
+                       $nt_lc = Title::newFromText( $partname . '.' . strtolower( $ext ) );
+                       $file_lc = wfLocalFile( $nt_lc );
+               } else {
+                       $file_lc = false;
+               }
+
+               if( $file->exists() ) {
+                       $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
+                       if ( $file->allowInlineDisplay() ) {
+                               $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
+                                       $file->getName(), 'right', array(), false, true );
+                       } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
+                               $icon = $file->iconThumb();
+                               $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $file->getURL() . '">' . 
+                                       $icon->toHtml() . '</a><br />' . $dlink . '</div>';
+                       } else {
+                               $dlink2 = '';
+                       }
+
+                       $warning .= '<li>' . wfMsgExt( 'fileexists', 'parseline', $dlink ) . '</li>' . $dlink2;
+
+               } elseif ( $file_lc && $file_lc->exists() ) {
+                       # Check if image with lowercase extension exists.
+                       # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
+                       $dlink = $sk->makeKnownLinkObj( $nt_lc );
+                       if ( $file_lc->allowInlineDisplay() ) {
+                               $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
+                                       $nt_lc->getText(), 'right', array(), false, true );
+                       } elseif ( !$file_lc->allowInlineDisplay() && $file_lc->isSafeFile() ) {
+                               $icon = $file_lc->iconThumb();
+                               $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $file_lc->getURL() . '">' . 
+                                       $icon->toHtml() . '</a><br />' . $dlink . '</div>';
+                       } else {
+                               $dlink2 = '';
+                       }
+
+                       $warning .= '<li>' . wfMsgExt( 'fileexists-extension', 'parsemag' , $partname . '.' 
+                               . $ext , $dlink ) . '</li>' . $dlink2;                          
+
+               } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' ) 
+                       && ereg( "[0-9]{2}" , substr( $partname , 0, 2) ) )
+               {
+                       # Check for filenames like 50px- or 180px-, these are mostly thumbnails
+                       $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $ext );
+                       $file_thb = wfLocalFile( $nt_thb );
+                       if ($file_thb->exists() ) {
+                               # Check if an image without leading '180px-' (or similiar) exists
+                               $dlink = $sk->makeKnownLinkObj( $nt_thb);
+                               if ( $file_thb->allowInlineDisplay() ) {
+                                       $dlink2 = $sk->makeImageLinkObj( $nt_thb, 
+                                               wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
+                                               $nt_thb->getText(), 'right', array(), false, true );
+                               } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) {
+                                       $icon = $file_thb->iconThumb();
+                                       $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . 
+                                               $file_thb->getURL() . '">' . $icon->toHtml() . '</a><br />' . 
+                                               $dlink . '</div>';
+                               } else {
+                                       $dlink2 = '';
+                               }
+
+                               $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) . 
+                                       '</li>' . $dlink2;      
+                       } else {
+                               # Image w/o '180px-' does not exists, but we do not like these filenames
+                               $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' , 
+                                       substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>';
+                       }
+               }
+               if ( $file->wasDeleted() ) {
+                       # If the file existed before and was deleted, warn the user of this
+                       # Don't bother doing so if the image exists now, however
+                       $ltitle = SpecialPage::getTitleFor( 'Log' );
+                       $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ), 
+                               'type=delete&page=' . $file->getTitle()->getPrefixedUrl() );
+                       $warning .= '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
+               }
+               return $warning;
+       }
+
+       static function ajaxGetExistsWarning( $filename ) {
+               $file = wfFindFile( $filename );
+               $s = '&nbsp;';
+               if ( $file ) {
+                       $warning = self::getExistsWarning( $file );
+                       if ( $warning !== '' ) {
+                               $s = "<ul>$warning</ul>";
+                       }
+               }
+               return $s;
+       }
+       
+       /**
+        * Render a preview of a given license for the AJAX preview on upload
+        *
+        * @param string $license
+        * @return string
+        */
+       public static function ajaxGetLicensePreview( $license ) {
+               global $wgParser, $wgUser;
+               $text = '{{' . $license . '}}';
+               $title = Title::makeTitle( NS_IMAGE, 'Sample.jpg' );
+               $options = ParserOptions::newFromUser( $wgUser );
+               
+               // Expand subst: first, then live templates...
+               $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
+               $output = $wgParser->parse( $text, $title, $options );
+               
+               return $output->getText();
+       }
+
        /**
         * Stash a file in a temporary directory for later processing
         * after the user has confirmed it.
@@ -539,12 +593,12 @@ class UploadForm {
        function saveTempUploadedFile( $saveName, $tempName ) {
                global $wgOut;
                $repo = RepoGroup::singleton()->getLocalRepo();
-               $result = $repo->storeTemp( $saveName, $tempName );
-               if ( WikiError::isError( $result ) ) {
-                       $this->showError( $result );
+               $status = $repo->storeTemp( $saveName, $tempName );
+               if ( !$status->isGood() ) {
+                       $this->showError( $status->getWikiText() );
                        return false;
                } else {
-                       return $result;
+                       return $status->value;
                }
        }
 
@@ -595,24 +649,6 @@ class UploadForm {
 
        /* -------------------------------------------------------------- */
 
-       /**
-        * Show some text and linkage on successful upload.
-        * @access private
-        */
-       function showSuccess() {
-               global $wgUser, $wgOut, $wgContLang;
-
-               $sk = $wgUser->getSkin();
-               $ilink = $sk->makeMediaLinkObj( $this->mLocalFile->getTitle() );
-               $dname = $wgContLang->getNsText( NS_IMAGE ) . ':'.$this->mDestName;
-               $dlink = $sk->makeKnownLink( $dname, $dname );
-
-               $wgOut->addHTML( '<h2>' . wfMsgHtml( 'successfulupload' ) . "</h2>\n" );
-               $text = wfMsgWikiHtml( 'fileuploaded', $ilink, $dlink );
-               $wgOut->addHTML( $text );
-               $wgOut->returnToMain( false );
-       }
-
        /**
         * @param string $error as HTML
         * @access private
@@ -632,7 +668,7 @@ class UploadForm {
         * @access private
         */
        function uploadWarning( $warning ) {
-               global $wgOut;
+               global $wgOut, $wgContLang;
                global $wgUseCopyrightUpload;
 
                $this->mSessionKey = $this->stashSession();
@@ -650,6 +686,8 @@ class UploadForm {
                $reup = wfMsgWikiHtml( 'reuploaddesc' );
                $titleObj = SpecialPage::getTitleFor( 'Upload' );
                $action = $titleObj->escapeLocalURL( 'action=submit' );
+               $align1 = $wgContLang->isRTL() ? 'left' : 'right';
+               $align2 = $wgContLang->isRTL() ? 'right' : 'left';
 
                if ( $wgUseCopyrightUpload )
                {
@@ -673,16 +711,16 @@ class UploadForm {
        <table border='0'>
                <tr>
                        <tr>
-                               <td align='right'>
+                               <td align='$align1'>
                                        <input tabindex='2' type='submit' name='wpUpload' value=\"$save\" />
                                </td>
-                               <td align='left'>$iw</td>
+                               <td align='$align2'>$iw</td>
                        </tr>
                        <tr>
-                               <td align='right'>
+                               <td align='$align1'>
                                        <input tabindex='2' type='submit' name='wpReUpload' value=\"{$reupload}\" />
                                </td>
-                               <td align='left'>$reup</td>
+                               <td align='$align2'>$reup</td>
                        </tr>
                </tr>
        </table></form>\n" );
@@ -696,9 +734,23 @@ class UploadForm {
         * @access private
         */
        function mainUploadForm( $msg='' ) {
-               global $wgOut, $wgUser;
-               global $wgUseCopyrightUpload;
-               global $wgRequest, $wgAllowCopyUploads;
+               global $wgOut, $wgUser, $wgContLang;
+               global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
+               global $wgRequest, $wgAllowCopyUploads, $wgEnableAPI;
+               global $wgStylePath, $wgStyleVersion;
+
+               $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
+               $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
+               
+               $adc = wfBoolToStr( $useAjaxDestCheck );
+               $alp = wfBoolToStr( $useAjaxLicensePreview );
+               
+               $wgOut->addScript( "<script type=\"text/javascript\">
+wgAjaxUploadDestCheck = {$adc};
+wgAjaxLicensePreview = {$alp};
+</script>
+<script type=\"text/javascript\" src=\"{$wgStylePath}/common/upload.js?{$wgStyleVersion}\"></script>
+               " );
 
                if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
                {
@@ -770,27 +822,38 @@ class UploadForm {
                                "size='40' />" .
                                "<input type='hidden' name='wpSourceType' value='file' />" ;
                }
+               if ( $useAjaxDestCheck ) {
+                       $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'>&nbsp</td></tr>";
+                       $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
+               } else {
+                       $warningRow = '';
+                       $destOnkeyup = '';
+               }
+
                $encComment = htmlspecialchars( $this->mComment );
+               $align1 = $wgContLang->isRTL() ? 'left' : 'right';
+               $align2 = $wgContLang->isRTL() ? 'right' : 'left';
 
                $wgOut->addHTML( <<<EOT
        <form id='upload' method='post' enctype='multipart/form-data' action="$action">
                <table border='0'>
                <tr>
          {$this->uploadFormTextTop}
-                       <td align='right' valign='top'><label for='wpUploadFile'>{$sourcefilename}</label></td>
-                       <td align='left'>
+                       <td align='$align1' valign='top'><label for='wpUploadFile'>{$sourcefilename}:</label></td>
+                       <td align='$align2'>
                                {$filename_form}
                        </td>
                </tr>
                <tr>
-                       <td align='right'><label for='wpDestFile'>{$destfilename}</label></td>
-                       <td align='left'>
-                               <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' value="$encDestName" />
+                       <td align='$align1'><label for='wpDestFile'>{$destfilename}:</label></td>
+                       <td align='$align2'>
+                               <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' 
+                                       value="$encDestName" $destOnkeyup />
                        </td>
                </tr>
                <tr>
-                       <td align='right'><label for='wpUploadDescription'>{$summary}</label></td>
-                       <td align='left'>
+                       <td align='$align1'><label for='wpUploadDescription'>{$summary}</label></td>
+                       <td align='$align2'>
                                <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6' 
                                        cols='{$cols}'{$ew}>$encComment</textarea>
           {$this->uploadFormTextAfterSummary}
@@ -803,9 +866,8 @@ EOT
                if ( $licenseshtml != '' ) {
                        global $wgStylePath;
                        $wgOut->addHTML( "
-                       <td align='right'><label for='wpLicense'>$license</label></td>
-                       <td align='left'>
-                               <script type='text/javascript' src=\"$wgStylePath/common/upload.js\"></script>
+                       <td align='$align1'><label for='wpLicense'>$license:</label></td>
+                       <td align='$align2'>
                                <select name='wpLicense' id='wpLicense' tabindex='4'
                                        onchange='licenseSelectorCheck()'>
                                        <option value=''>$nolicense</option>
@@ -813,8 +875,14 @@ EOT
                                </select>
                        </td>
                        </tr>
-                       <tr>
-               ");
+                       <tr>" );
+                       if( $useAjaxLicensePreview ) {
+                               $wgOut->addHtml( "
+                                       <td></td>
+                                       <td id=\"mw-license-preview\"></td>
+                               </tr>
+                               <tr>" );
+                       }
                }
 
                if ( $wgUseCopyrightUpload ) {
@@ -824,12 +892,12 @@ EOT
                        $uploadsource = htmlspecialchars( $this->mCopyrightSource );
 
                        $wgOut->addHTML( "
-                               <td align='right' nowrap='nowrap'><label for='wpUploadCopyStatus'>$filestatus</label></td>
+                               <td align='$align1' nowrap='nowrap'><label for='wpUploadCopyStatus'>$filestatus:</label></td>
                                        <td><input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus' 
                                          value=\"$copystatus\" size='40' /></td>
                        </tr>
                        <tr>
-                               <td align='right'><label for='wpUploadCopyStatus'>$filesource</label></td>
+                               <td align='$align1'><label for='wpUploadCopyStatus'>$filesource:</label></td>
                                        <td><input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus' 
                                          value=\"$uploadsource\" size='40' /></td>
                        </tr>
@@ -837,7 +905,6 @@ EOT
                ");
                }
 
-
                $wgOut->addHtml( "
                <td></td>
                <td>
@@ -847,14 +914,14 @@ EOT
                        <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
                </td>
        </tr>
+       $warningRow
        <tr>
                <td></td>
-               <td align='left'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
+               <td align='$align2'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
        </tr>
-
        <tr>
                <td></td>
-               <td align='left'>
+               <td align='$align2'>
                " );
                $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
                $wgOut->addHTML( "
@@ -862,6 +929,7 @@ EOT
        </tr>
 
        </table>
+       <input type='hidden' name='wpDestFileWarningAck' id='wpDestFileWarningAck' value=''/>
        </form>" );
        }
 
@@ -926,6 +994,7 @@ EOT
                global $wgVerifyMimeType;
                if ($wgVerifyMimeType) {
 
+                 wfDebug ( "\n\nmime: <$mime> extension: <$extension>\n\n");
                        #check mime type against file extension
                        if( !$this->verifyExtension( $mime, $extension ) ) {
                                return new WikiErrorMsg( 'uploadcorrupt' );
@@ -1290,15 +1359,15 @@ EOT
        }
 
        /**
-        * Display an error from a wikitext-formatted WikiError object
+        * Display an error with a wikitext description
         */
-       function showError( WikiError $error ) {
+       function showError( $description ) {
                global $wgOut;
                $wgOut->setPageTitle( wfMsg( "internalerror" ) );
                $wgOut->setRobotpolicy( "noindex,nofollow" );
                $wgOut->setArticleRelated( false );
                $wgOut->enableClientCache( false );
-               $wgOut->addWikiText( $error->getMessage() );
+               $wgOut->addWikiText( $description );
        }
 
        /**
@@ -1326,4 +1395,5 @@ EOT
                return $pageText;
        }
 }
-?>
+
+