Use existing CSS classes for label and input elements in table for proper aligning
[lhc/web/wiklou.git] / includes / SpecialUpload.php
index 7ad25e6..a8aa91e 100644 (file)
@@ -166,7 +166,7 @@ class UploadForm {
                $url =  trim( $url );
                if( stripos($url, 'http://') !== 0 && stripos($url, 'ftp://') !== 0 ) {
                        # Only HTTP or FTP URLs
-                       $wgOut->errorPage( 'upload-proto-error', 'upload-proto-error-text' );
+                       $wgOut->showErrorPage( 'upload-proto-error', 'upload-proto-error-text' );
                        return true;
                }
 
@@ -174,7 +174,7 @@ class UploadForm {
                $this->mCurlDestHandle = @fopen( $this->mTempPath, "wb" );
                if( $this->mCurlDestHandle === false ) {
                        # Could not open temporary file to write in
-                       $wgOut->errorPage( 'upload-file-error', 'upload-file-error-text');
+                       $wgOut->showErrorPage( 'upload-file-error', 'upload-file-error-text');
                        return true;
                }
 
@@ -195,9 +195,9 @@ class UploadForm {
                if( $error ) {
                        unlink( $dest );
                        if( wfEmptyMsg( "upload-curl-error$errornum", wfMsg("upload-curl-error$errornum") ) )
-                               $wgOut->errorPage( 'upload-misc-error', 'upload-misc-error-text' );
+                               $wgOut->showErrorPage( 'upload-misc-error', 'upload-misc-error-text' );
                        else
-                               $wgOut->errorPage( "upload-curl-error$errornum", "upload-curl-error$errornum-text" );
+                               $wgOut->showErrorPage( "upload-curl-error$errornum", "upload-curl-error$errornum-text" );
                }
 
                return $error;
@@ -280,7 +280,7 @@ class UploadForm {
                $details = null;
                $value = null;
                $value = $this->internalProcessUpload( $details );
-               
+
                switch($value) {
                        case self::SUCCESS:
                                $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
@@ -376,11 +376,6 @@ class UploadForm {
                        return self::BEFORE_PROCESSING;
                }
 
-               /* Check for PHP error if any, requires php 4.2 or newer */
-               if( $this->mCurlError == 1/*UPLOAD_ERR_INI_SIZE*/ ) {
-                       return self::LARGE_FILE_SERVER;
-               }
-
                /**
                 * If there was no filename or a zero size given, give up quick.
                 */
@@ -388,6 +383,11 @@ class UploadForm {
                        return self::EMPTY_FILE;
                }
 
+               /* Check for curl error */
+               if( $this->mCurlError ) {
+                       return self::BEFORE_PROCESSING;
+               }
+
                # Chop off any directories in the given filename
                if( $this->mDesiredDestName ) {
                        $basename = $this->mDesiredDestName;
@@ -832,8 +832,8 @@ class UploadForm {
         */
        function uploadError( $error ) {
                global $wgOut;
-               $wgOut->addHTML( "<h2>" . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
-               $wgOut->addHTML( "<span class='error'>{$error}</span>\n" );
+               $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'uploadwarning' ) . "\n" ) );
+               $wgOut->addHTML( Xml::tags( 'span', array( 'class' => 'error' ), $error ) );
        }
 
        /**
@@ -845,7 +845,7 @@ class UploadForm {
         * @access private
         */
        function uploadWarning( $warning ) {
-               global $wgOut, $wgContLang;
+               global $wgOut;
                global $wgUseCopyrightUpload;
 
                $this->mSessionKey = $this->stashSession();
@@ -854,53 +854,32 @@ class UploadForm {
                        return;
                }
 
-               $wgOut->addHTML( "<h2>" . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
-               $wgOut->addHTML( "<ul class='warning'>{$warning}</ul><br />\n" );
+               $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'uploadwarning' ) ) . "\n" );
+               $wgOut->addHTML( Xml::tags( 'ul', array( 'class' => 'warning' ), $warning ) . "\n" );
 
-               $save = wfMsgHtml( 'savefile' );
-               $reupload = wfMsgHtml( 'reupload' );
-               $iw = wfMsgWikiHtml( 'ignorewarning' );
-               $reup = wfMsgWikiHtml( 'reuploaddesc' );
                $titleObj = SpecialPage::getTitleFor( 'Upload' );
-               $action = $titleObj->escapeLocalURL( 'action=submit' );
-               $align1 = $wgContLang->isRTL() ? 'left' : 'right';
-               $align2 = $wgContLang->isRTL() ? 'right' : 'left';
 
-               if ( $wgUseCopyrightUpload )
-               {
-                       $copyright =  "
-       <input type='hidden' name='wpUploadCopyStatus' value=\"" . htmlspecialchars( $this->mCopyrightStatus ) . "\" />
-       <input type='hidden' name='wpUploadSource' value=\"" . htmlspecialchars( $this->mCopyrightSource ) . "\" />
-       ";
+               if ( $wgUseCopyrightUpload ) {
+                       $copyright = Xml::hidden( 'wpUploadCopyStatus', $this->mCopyrightStatus ) . "\n" .
+                                       Xml::hidden( 'wpUploadSource', $this->mCopyrightSource ) . "\n";
                } else {
-                       $copyright = "";
+                       $copyright = '';
                }
 
-               $wgOut->addHTML( "
-       <form id='uploadwarning' method='post' enctype='multipart/form-data' action='$action'>
-               <input type='hidden' name='wpIgnoreWarning' value='1' />
-               <input type='hidden' name='wpSessionKey' value=\"" . htmlspecialchars( $this->mSessionKey ) . "\" />
-               <input type='hidden' name='wpUploadDescription' value=\"" . htmlspecialchars( $this->mComment ) . "\" />
-               <input type='hidden' name='wpLicense' value=\"" . htmlspecialchars( $this->mLicense ) . "\" />
-               <input type='hidden' name='wpDestFile' value=\"" . htmlspecialchars( $this->mDesiredDestName ) . "\" />
-               <input type='hidden' name='wpWatchthis' value=\"" . htmlspecialchars( intval( $this->mWatchthis ) ) . "\" />
-       {$copyright}
-       <table border='0'>
-               <tr>
-                       <tr>
-                               <td align='$align1'>
-                                       <input tabindex='2' type='submit' name='wpUpload' value=\"$save\" />
-                               </td>
-                               <td align='$align2'>$iw</td>
-                       </tr>
-                       <tr>
-                               <td align='$align1'>
-                                       <input tabindex='2' type='submit' name='wpReUpload' value=\"{$reupload}\" />
-                               </td>
-                               <td align='$align2'>$reup</td>
-                       </tr>
-               </tr>
-       </table></form>\n" );
+               $wgOut->addHTML(
+                       Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 
+                                'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
+                       Xml::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
+                       Xml::hidden( 'wpSessionKey', $this->mSessionKey ) . "\n" .
+                       Xml::hidden( 'wpUploadDescription', $this->mComment ) . "\n" .
+                       Xml::hidden( 'wpLicense', $this->mLicense ) . "\n" .
+                       Xml::hidden( 'wpDestFile', $this->mDesiredDestName ) . "\n" .
+                       Xml::hidden( 'wpWatchthis', $this->mWatchthis ) . "\n" .
+                       "{$copyright}<br />" .
+                       Xml::submitButton( wfMsg( 'ignorewarning' ), array ( 'name' => 'wpUpload', 'id' => 'wpUpload', 'checked' => 'checked' ) ) . ' ' .
+                       Xml::submitButton( wfMsg( 'reuploaddesc' ), array ( 'name' => 'wpReUpload', 'id' => 'wpReUpload' ) ) .
+                       Xml::closeElement( 'form' ) . "\n"
+               );
        }
 
        /**
@@ -911,7 +890,7 @@ class UploadForm {
         * @access private
         */
        function mainUploadForm( $msg='' ) {
-               global $wgOut, $wgUser;
+               global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize;
                global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
                global $wgRequest, $wgAllowCopyUploads;
                global $wgStylePath, $wgStyleVersion;
@@ -1001,6 +980,26 @@ wgUploadAutoFill = {$autofill};
                        }
                }
 
+               # Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
+               # See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
+               $val = trim( ini_get( 'upload_max_filesize' ) );
+               $last = strtoupper( ( substr( $val, -1 ) ) );
+               switch( $last ) {
+                       case 'G':
+                               $val2 = substr( $val, 0, -1 ) * 1024 * 1024 * 1024;
+                               break;
+                       case 'M':
+                               $val2 = substr( $val, 0, -1 ) * 1024 * 1024;
+                               break;
+                       case 'K':
+                               $val2 = substr( $val, 0, -1 ) * 1024;
+                               break;
+                       default:
+                               $val2 = $val;
+               }
+               $val2 = $wgAllowCopyUploads ? min( $wgMaxUploadSize, $val2 ) : $val2;
+               $maxUploadSize = wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ), $wgLang->formatSize( $val2 ) );
+
                $sourcefilename = wfMsgExt( 'sourcefilename', 'escapenoentities' );
                $destfilename = wfMsgExt( 'destfilename', 'escapenoentities' );
                $summary = wfMsgExt( 'fileuploadsummary', 'parseinline' );
@@ -1032,7 +1031,7 @@ wgUploadAutoFill = {$autofill};
                                 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
                                   "onfocus='" . 
                                     "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
-                                    "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")'" .
+                                    "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
                                     "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
                                wfMsgHTML( 'upload_source_file' ) . "<br/>" .
                                "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='web' " .
@@ -1040,7 +1039,7 @@ wgUploadAutoFill = {$autofill};
                                "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
                                  "onfocus='" .
                                    "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
-                                   "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")'" .
+                                   "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
                                    "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' disabled='disabled' />" .
                                wfMsgHtml( 'upload_source_url' ) ;
                } else {
@@ -1078,6 +1077,7 @@ wgUploadAutoFill = {$autofill};
                        <tr>
                                <td></td>
                                <td>
+                                       {$maxUploadSize}
                                        {$extensionsList}
                                </td>
                        </tr>
@@ -1181,7 +1181,7 @@ wgUploadAutoFill = {$autofill};
                                </td>
                        </tr>" .
                        Xml::closeElement( 'table' ) .
-                       Xml::hidden( 'wpDestFileWarningAck', '' ) .
+                       Xml::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
                        Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' )
                );