* (bug 4679) Work around buggy basename() function in PHP5, which breaks
[lhc/web/wiklou.git] / includes / SpecialUpload.php
index 97f3d97..8ca7657 100644 (file)
@@ -99,17 +99,29 @@ class UploadForm {
                global $wgUser, $wgOut;
                global $wgEnableUploads, $wgUploadDirectory;
 
-               /** Show an error message if file upload is disabled */
-               if( ! $wgEnableUploads ) {
-                       $wgOut->addWikiText( wfMsg( 'uploaddisabled' ) );
+               # Check uploading enabled
+               if( !$wgEnableUploads ) {
+                       $wgOut->errorPage( 'uploaddisabled', 'uploaddisabledtext' );
                        return;
                }
 
-               /** Various rights checks */
-               if( !$wgUser->isAllowed( 'upload' ) || $wgUser->isBlocked() ) {
-                       $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
+               # Check permissions
+               if( $wgUser->isLoggedIn() ) {
+                       if( !$wgUser->isAllowed( 'upload' ) ) {
+                               $wgOut->permissionRequired( 'upload' );
+                               return;
+                       }
+               } else {
+                       $wgOut->errorPage( 'uploadnologin', 'uploadnologintext' );
+                       return;
+               }       
+
+               # Check blocks
+               if( $wgUser->isBlocked() ) {
+                       $wgOut->blockedPage();
                        return;
                }
+
                if( wfReadOnly() ) {
                        $wgOut->readOnlyPage();
                        return;
@@ -141,9 +153,7 @@ class UploadForm {
         * @access private
         */
        function processUpload() {
-               global $wgUser, $wgOut, $wgLang, $wgContLang;
-               global $wgUploadDirectory;
-               global $wgUseCopyrightUpload, $wgCheckCopyrightUpload;
+               global $wgUser, $wgOut, $wgUploadDirectory;
 
                /* Check for PHP error if any, requires php 4.2 or newer */
                if ( $this->mUploadError == 1/*UPLOAD_ERR_INI_SIZE*/ ) {
@@ -161,9 +171,9 @@ class UploadForm {
 
                # Chop off any directories in the given filename
                if ( $this->mDestFile ) {
-                       $basename = basename( $this->mDestFile );
+                       $basename = wfBaseName( $this->mDestFile );
                } else {
-                       $basename = basename( $this->mOname );
+                       $basename = wfBaseName( $this->mOname );
                }
 
                /**
@@ -203,7 +213,7 @@ class UploadForm {
                if( !$nt->userCanEdit() ) {
                        return $this->uploadError( wfMsgWikiHtml( 'protectedpage' ) );
                }
-               
+
                /**
                 * In some cases we may forbid overwriting of existing files.
                 */
@@ -234,7 +244,7 @@ class UploadForm {
                                return $this->uploadError( $veri->toString() );
                        }
                }
-               
+
                /**
                 * Provide an opportunity for extensions to add futher checks
                 */
@@ -249,7 +259,7 @@ class UploadForm {
                 */
                if ( ! $this->mIgnoreWarning ) {
                        $warning = '';
-                       
+
                        global $wgCapitalLinks;
                        if( $wgCapitalLinks ) {
                                $filtered = ucfirst( $filtered );
@@ -483,7 +493,7 @@ class UploadForm {
         * @access private
         */
        function uploadWarning( $warning ) {
-               global $wgOut, $wgUser, $wgLang, $wgUploadDirectory, $wgRequest;
+               global $wgOut, $wgUser, $wgUploadDirectory, $wgRequest;
                global $wgUseCopyrightUpload;
 
                $this->mSessionKey = $this->stashSession();
@@ -547,7 +557,7 @@ class UploadForm {
         * @access private
         */
        function mainUploadForm( $msg='' ) {
-               global $wgOut, $wgUser, $wgLang, $wgUploadDirectory, $wgRequest;
+               global $wgOut, $wgUser, $wgUploadDirectory, $wgRequest;
                global $wgUseCopyrightUpload;
 
                $cols = intval($wgUser->getOption( 'cols' ));
@@ -560,7 +570,9 @@ class UploadForm {
                        $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
                          "<span class='error'>{$msg}</span>\n" );
                }
+               $wgOut->addHTML( '<div id="uploadtext">' );
                $wgOut->addWikiText( wfMsg( 'uploadtext' ) );
+               $wgOut->addHTML( '</div>' );
                $sk = $wgUser->getSkin();
 
 
@@ -572,7 +584,7 @@ class UploadForm {
                $license = wfMsgHtml( 'license' );
                $nolicense = wfMsgHtml( 'nolicense' );
                $licenseshtml = $licenses->getHtml();
-               
+
                $ulb = wfMsgHtml( 'uploadbtn' );
 
 
@@ -584,35 +596,38 @@ class UploadForm {
                $watchChecked = $wgUser->getOption( 'watchdefault' )
                        ? 'checked="checked"'
                        : '';
-               
+
                $wgOut->addHTML( "
        <form id='upload' method='post' enctype='multipart/form-data' action=\"$action\">
-               <table border='1'>
+               <table border='0'>
                <tr>
-                       <td align='right'>{$sourcefilename}:</td>
+                       <td align='right'><label for='wpUploadFile'>{$sourcefilename}:</label></td>
                        <td align='left'>
                                <input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " . ($this->mDestFile?"":"onchange='fillDestFilename()' ") . "size='40' />
                        </td>
                </tr>
                <tr>
-                       <td align='right'>{$destfilename}:</td>
+                       <td align='right'><label for='wpDestFile'>{$destfilename}:</label></td>
                        <td align='left'>
                                <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' value=\"$encDestFile\" />
                        </td>
                </tr>
                <tr>
-                       <td align='right'>{$summary}</td>
+                       <td align='right'><label for='wpUploadDescription'>{$summary}</label></td>
                        <td align='left'>
-                               <textarea tabindex='3' name='wpUploadDescription' rows='6' cols='{$cols}'{$ew}>" . htmlspecialchars( $this->mUploadDescription ) . "</textarea>
+                               <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6' cols='{$cols}'{$ew}>" . htmlspecialchars( $this->mUploadDescription ) . "</textarea>
                        </td>
                </tr>
                <tr>" );
-       
+
        if ( $licenseshtml != '' ) {
+               global $wgStylePath;
                $wgOut->addHTML( "
-                       <td align='right'>$license:</td>
+                       <td align='right'><label for='wpLicense'>$license:</label></td>
                        <td align='left'>
-                               <select name='wpLicense' tabindex='4'>
+                               <script type='text/javascript' src=\"$wgStylePath/common/upload.js\"></script>
+                               <select name='wpLicense' id='wpLicense' tabindex='4'
+                                       onchange='licenseSelectorCheck()'>
                                        <option value=''>$nolicense</option>
                                        $licenseshtml
                                </select>
@@ -627,27 +642,27 @@ class UploadForm {
                $copystatus =  htmlspecialchars( $this->mUploadCopyStatus );
                $filesource = wfMsgHtml ( 'filesource' );
                $uploadsource = htmlspecialchars( $this->mUploadSource );
-               
+
                $wgOut->addHTML( "
-                               <td align='right' nowrap='nowrap'>$filestatus:</td>
-                               <td><input tabindex='5' type='text' name='wpUploadCopyStatus' value=\"$copystatus\" size='40' /></td>
+                               <td align='right' 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'>$filesource:</td>
-                               <td><input tabindex='6' type='text' name='wpUploadSource' value=\"$uploadsource\" size='40' /></td>
+                               <td align='right'><label for='wpUploadCopyStatus'>$filesource:</label></td>
+                               <td><input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus' value=\"$uploadsource\" size='40' /></td>
                        </tr>
                        <tr>
                ");
        }
-       
-       
+
+
        $wgOut->addHtml( "
                <td></td>
                <td>
                        <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
                        <label for='wpWatchthis'>" . wfMsgHtml( 'watchthis' ) . "</label>
                        <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' />
-                       <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarning' ) . "</label>
+                       <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
                </td>
        </tr>
        <tr>
@@ -657,6 +672,16 @@ class UploadForm {
                <td></td>
                <td align='left'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
        </tr>
+
+       <tr>
+               <td></td>
+               <td align='left'>
+               " );
+       $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
+       $wgOut->addHTML( "
+               </td>
+       </tr>
+
        </table>
        </form>" );
        }
@@ -1009,7 +1034,7 @@ class UploadForm {
                        unlink( $this->mUploadTempName );
                }
        }
-       
+
        /**
         * Check if there's an overwrite conflict and, if so, if restrictions
         * forbid this user from performing the upload.
@@ -1024,7 +1049,7 @@ class UploadForm {
                        // But if it does, fall through to previous behavior
                        return false;
                }
-               
+
                $error = '';
                if( $img->exists() ) {
                        global $wgUser, $wgOut;
@@ -1039,12 +1064,12 @@ class UploadForm {
                                }
                        }
                }
-               
+
                if( $error ) {
                        $errorText = wfMsg( $error, wfEscapeWikiText( $img->getName() ) );
                        return new WikiError( $wgOut->parse( $errorText ) );
                }
-               
+
                // Rockin', go ahead and upload
                return true;
        }