const VERIFICATION_ERROR = 10;
const UPLOAD_VERIFICATION_ERROR = 11;
const UPLOAD_WARNING = 12;
+ const INTERNAL_ERROR = 13;
/**#@+
* @access private
}
$this->mainUploadForm();
} else if( 'submit' == $this->mAction || $this->mUploadClicked ) {
- $this->processUpload();
+ $this->processUpload();
} else {
$this->mainUploadForm();
}
switch($value) {
case self::SUCCESS:
$wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
- return;
+ break;
case self::BEFORE_PROCESSING:
- return false;
+ break;
case self::LARGE_FILE_SERVER:
$this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
- return;
+ break;
case self::EMPTY_FILE:
$this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
- return;
+ break;
case self::MIN_LENGHT_PARTNAME:
$this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
- return;
+ break;
case self::ILLEGAL_FILENAME:
$filtered = $details['filtered'];
$this->uploadError( wfMsgWikiHtml( 'illegalfilename', htmlspecialchars( $filtered ) ) );
- return;
+ break;
case self::PROTECTED_PAGE:
- return $this->uploadError( wfMsgWikiHtml( 'protectedpage' ) );
+ $this->uploadError( wfMsgWikiHtml( 'protectedpage' ) );
+ break;
case self::OVERWRITE_EXISTING_FILE:
$errorText = $details['overwrite'];
$overwrite = new WikiError( $wgOut->parse( $errorText ) );
- return $this->uploadError( $overwrite->toString() );
+ $this->uploadError( $overwrite->toString() );
+ break;
case self::FILETYPE_MISSING:
- return $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
+ $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
+ break;
case self::FILETYPE_BADTYPE:
$finalExt = $details['finalExt'];
- return $this->uploadError( wfMsgExt( 'filetype-badtype', array ( 'parseinline' ), htmlspecialchars( $finalExt ), implode ( ', ', $wgFileExtensions ) ) );
+ $this->uploadError(
+ wfMsgExt( 'filetype-banned-type',
+ array( 'parseinline' ),
+ htmlspecialchars( $finalExt ),
+ implode(
+ wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
+ $wgFileExtensions
+ )
+ )
+ );
+ break;
case self::VERIFICATION_ERROR:
$veri = $details['veri'];
- return $this->uploadError( $veri->toString() );
+ $this->uploadError( $veri->toString() );
+ break;
case self::UPLOAD_VERIFICATION_ERROR:
$error = $details['error'];
- return $this->uploadError( $error );
+ $this->uploadError( $error );
+ break;
case self::UPLOAD_WARNING:
$warning = $details['warning'];
- return $this->uploadWarning( $warning );
+ $this->uploadWarning( $warning );
+ break;
+
+ case self::INTERNAL_ERROR:
+ $internal = $details['internal'];
+ $this->showError( $internal );
+ break;
+
+ default:
+ throw new MWException( __METHOD__ . ": Unknown value `{$value}`" );
}
-
- /* TODO: Each case returns instead of breaking to maintain the highest level of compatibility during branch merging.
- They should be reviewed and corrected separatelly.
- */
- new MWException( __METHOD__ . ": Unknown value `{$value}`" );
}
/**
* If the image is protected, non-sysop users won't be able
* to modify it by uploading a new revision.
*/
- if( !$nt->userCan( 'edit' ) ) {
+ if( !$nt->userCan( 'edit' ) || !$nt->userCan( 'create' ) ) {
return self::PROTECTED_PAGE;
}
global $wgCheckFileExtensions;
if ( $wgCheckFileExtensions ) {
- if ( ! $this->checkFileExtension( $finalExt, $wgFileExtensions ) ) {
- $warning .= '<li>'.wfMsgExt( 'filetype-badtype', array ( 'parseinline' ),
- htmlspecialchars( $finalExt ), implode ( ', ', $wgFileExtensions ) ).'</li>';
+ if ( !$this->checkFileExtension( $finalExt, $wgFileExtensions ) ) {
+ $warning .= '<li>' .
+ wfMsgExt( 'filetype-unwanted-type',
+ array( 'parseinline' ),
+ htmlspecialchars( $finalExt ),
+ implode(
+ wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
+ $wgFileExtensions
+ )
+ ) . '</li>';
}
}
$status = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText,
File::DELETE_SOURCE, $this->mFileProps );
if ( !$status->isGood() ) {
- $this->showError( $status->getWikiText() );
+ $resultDetails = array( 'internal' => $status->getWikiText() );
+ return self::INTERNAL_ERROR;
} else {
if ( $this->mWatchthis ) {
global $wgUser;
}
$cols = intval($wgUser->getOption( 'cols' ));
- $ew = $wgUser->getOption( 'editwidth' );
- if ( $ew ) $ew = " style=\"width:100%\"";
- else $ew = '';
+
+ if( $wgUser->getOption( 'editwidth' ) ) {
+ $width = " style=\"width:100%\"";
+ } else {
+ $width = '';
+ }
if ( '' != $msg ) {
$sub = wfMsgHtml( 'uploaderror' );
}
$wgOut->addHTML( '<div id="uploadtext">' );
$wgOut->addWikiText( wfMsgNoTrans( 'uploadtext', $this->mDesiredDestName ) );
- $wgOut->addHTML( '</div>' );
+ $wgOut->addHTML( "</div>\n" );
+
+ # Print a list of allowed file extensions, if so configured. We ignore
+ # MIME type here, it's incomprehensible to most people and too long.
+ global $wgCheckFileExtensions, $wgStrictFileExtensions,
+ $wgFileExtensions, $wgFileBlacklist;
+ if( $wgCheckFileExtensions ) {
+ $delim = wfMsgExt( 'comma-separator', array( 'escapenoentities' ) );
+ if( $wgStrictFileExtensions ) {
+ # Everything not permitted is banned
+ $wgOut->addHTML(
+ '<div id="mw-upload-permitted">' .
+ wfMsgWikiHtml( 'upload-permitted', implode( $wgFileExtensions, $delim ) ) .
+ "</div>\n"
+ );
+ } else {
+ # We have to list both preferred and prohibited
+ $wgOut->addHTML(
+ '<div id="mw-upload-preferred">' .
+ wfMsgWikiHtml( 'upload-preferred', implode( $wgFileExtensions, $delim ) ) .
+ "</div>\n" .
+ '<div id="mw-upload-prohibited">' .
+ wfMsgWikiHtml( 'upload-prohibited', implode( $wgFileBlacklist, $delim ) ) .
+ "</div>\n"
+ );
+ }
+ }
$sourcefilename = wfMsgHtml( 'sourcefilename' );
$destfilename = wfMsgHtml( 'destfilename' );
<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>
+ cols='{$cols}'{$width}>$encComment</textarea>
{$this->uploadFormTextAfterSummary}
</td>
</tr>