X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialUpload.php;h=24081ffe40fb67332670cff367d8f86decca3d91;hb=2896d1c83cf36ceeedb1e73880fe607bd909053d;hp=d5946f303ee9241740eef2bb2dd7155455552d22;hpb=1dcd516ed615677aa69338504644c33a5d7605dd;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php
index d5946f303e..24081ffe40 100644
--- a/includes/specials/SpecialUpload.php
+++ b/includes/specials/SpecialUpload.php
@@ -1,12 +1,33 @@
mDesiredDestName = $request->getText( 'wpDestFile' );
- if( !$this->mDesiredDestName ) {
- $this->mDesiredDestName = $request->getText( 'wpUploadFile' );
+ if( !$this->mDesiredDestName && $request->getFileName( 'wpUploadFile' ) !== null ) {
+ $this->mDesiredDestName = $request->getFileName( 'wpUploadFile' );
}
$this->mComment = $request->getText( 'wpUploadDescription' );
$this->mLicense = $request->getText( 'wpLicense' );
@@ -117,7 +138,7 @@ class SpecialUpload extends SpecialPage {
* Special page entry point
*/
public function execute( $par ) {
- global $wgUser, $wgOut, $wgRequest;
+ global $wgUser, $wgOut;
$this->setHeaders();
$this->outputHeader();
@@ -130,13 +151,14 @@ class SpecialUpload extends SpecialPage {
# Check permissions
global $wgGroupPermissions;
- if( !$wgUser->isAllowed( 'upload' ) ) {
+ $permissionRequired = UploadBase::isAllowed( $wgUser );
+ if( $permissionRequired !== true ) {
if( !$wgUser->isLoggedIn() && ( $wgGroupPermissions['user']['upload']
|| $wgGroupPermissions['autoconfirmed']['upload'] ) ) {
// Custom message if logged-in users without any special rights can upload
$wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
} else {
- $wgOut->permissionRequired( 'upload' );
+ $wgOut->permissionRequired( $permissionRequired );
}
return;
}
@@ -174,6 +196,7 @@ class SpecialUpload extends SpecialPage {
wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
return;
}
+
$this->showUploadForm( $this->getUploadForm() );
}
@@ -225,6 +248,7 @@ class SpecialUpload extends SpecialPage {
'texttop' => $this->uploadFormTextTop,
'textaftersummary' => $this->uploadFormTextAfterSummary,
+ 'destfile' => $this->mDesiredDestName,
) );
$form->setTitle( $this->getTitle() );
@@ -237,6 +261,21 @@ class SpecialUpload extends SpecialPage {
$form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) );
}
+ # Give a notice if the user is uploading a file that has been deleted or moved
+ # Note that this is independent from the message 'filewasdeleted' that requires JS
+ $desiredTitleObj = Title::newFromText( $this->mDesiredDestName, NS_FILE );
+ $delNotice = ''; // empty by default
+ if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) {
+ LogEventsList::showLogExtract( $delNotice, array( 'delete', 'move' ),
+ $desiredTitleObj->getPrefixedText(),
+ '', array( 'lim' => 10,
+ 'conds' => array( "log_action != 'revision'" ),
+ 'showIfEmpty' => false,
+ 'msgKey' => array( 'upload-recreate-warning' ) )
+ );
+ }
+ $form->addPreText( $delNotice );
+
# Add text to form
$form->addPreText( '
' .
wfMsgExt( 'uploadtext', 'parse', array( $this->mDesiredDestName ) ) .
@@ -365,7 +404,7 @@ class SpecialUpload extends SpecialPage {
/**
* Show the upload form with error message, but do not stash the file.
*
- * @param $message String
+ * @param $message HTML string
*/
protected function showUploadError( $message ) {
$message = '
' . wfMsgHtml( 'uploadwarning' ) . "
\n" .
@@ -380,24 +419,20 @@ class SpecialUpload extends SpecialPage {
protected function processUpload() {
global $wgUser, $wgOut;
- // Verify permissions
- $permErrors = $this->mUpload->verifyPermissions( $wgUser );
- if( $permErrors !== true ) {
- $wgOut->showPermissionsErrorPage( $permErrors );
- return;
- }
-
// Fetch the file if required
$status = $this->mUpload->fetchFile();
if( !$status->isOK() ) {
- $this->showUploadForm( $this->getUploadForm( $wgOut->parse( $status->getWikiText() ) ) );
+ $this->showUploadError( $wgOut->parse( $status->getWikiText() ) );
return;
}
// Deprecated backwards compatibility hook
if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) ) {
wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
- return array( 'status' => UploadBase::BEFORE_PROCESSING );
+ // Return without notifying the user of an error. This sucks, but
+ // this was the previous behaviour as well, and as this hook is
+ // deprecated we're not going to do anything about it.
+ return;
}
@@ -407,6 +442,15 @@ class SpecialUpload extends SpecialPage {
$this->processVerificationError( $details );
return;
}
+
+ // Verify permissions for this title
+ $permErrors = $this->mUpload->verifyPermissions( $wgUser );
+ if( $permErrors !== true ) {
+ $code = array_shift( $permErrors[0] );
+ $this->showRecoverableUploadError( wfMsgExt( $code,
+ 'parseinline', $permErrors[0] ) );
+ return;
+ }
$this->mLocalFile = $this->mUpload->getLocalFile();
@@ -511,10 +555,6 @@ class SpecialUpload extends SpecialPage {
$this->showRecoverableUploadError( wfMsgExt( 'illegalfilename',
'parseinline', $details['filtered'] ) );
break;
- case UploadBase::OVERWRITE_EXISTING_FILE:
- $this->showRecoverableUploadError( wfMsgExt( $details['overwrite'],
- 'parseinline' ) );
- break;
case UploadBase::FILETYPE_MISSING:
$this->showRecoverableUploadError( wfMsgExt( 'filetype-missing',
'parseinline' ) );
@@ -522,7 +562,10 @@ class SpecialUpload extends SpecialPage {
/** Statuses that require reuploading **/
case UploadBase::EMPTY_FILE:
- $this->showUploadForm( $this->getUploadForm( wfMsgHtml( 'emptyfile' ) ) );
+ $this->showUploadError( wfMsgHtml( 'emptyfile' ) );
+ break;
+ case UploadBase::FILE_TOO_LARGE:
+ $this->showUploadError( wfMsgHtml( 'largefileserver' ) );
break;
case UploadBase::FILETYPE_BADTYPE:
$finalExt = $details['finalExt'];
@@ -588,7 +631,7 @@ class SpecialUpload extends SpecialPage {
* @return String: empty string if there is no warning or an HTML fragment
*/
public static function getExistsWarning( $exists ) {
- global $wgUser, $wgContLang;
+ global $wgUser;
if ( !$exists ) {
return '';
@@ -651,7 +694,7 @@ class SpecialUpload extends SpecialPage {
// if there isn't an exact match...
$file = wfLocalFile( $filename );
}
- $s = ' ';
+ $s = ' ';
if ( $file ) {
$exists = UploadBase::getExistsWarning( $file );
$warning = self::getExistsWarning( $exists );
@@ -695,6 +738,7 @@ class UploadForm extends HTMLForm {
protected $mSessionKey;
protected $mHideIgnoreWarning;
protected $mDestWarningAck;
+ protected $mDestFile;
protected $mTextTop;
protected $mTextAfterSummary;
@@ -708,9 +752,13 @@ class UploadForm extends HTMLForm {
? $options['sessionkey'] : '';
$this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
$this->mDestWarningAck = !empty( $options['destwarningack'] );
+ $this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : '';
+
+ $this->mTextTop = isset( $options['texttop'] )
+ ? $options['texttop'] : '';
- $this->mTextTop = $options['texttop'];
- $this->mTextAfterSummary = $options['textaftersummary'];
+ $this->mTextAfterSummary = isset( $options['textaftersummary'] )
+ ? $options['textaftersummary'] : '';
$sourceDescriptor = $this->getSourceSection();
$descriptor = $sourceDescriptor
@@ -723,6 +771,7 @@ class UploadForm extends HTMLForm {
# Set some form properties
$this->setSubmitText( wfMsg( 'uploadbtn' ) );
$this->setSubmitName( 'wpUpload' );
+ # Used message keys: 'accesskey-upload', 'tooltip-upload'
$this->setSubmitTooltip( 'upload' );
$this->setId( 'mw-upload-form' );
@@ -744,6 +793,7 @@ class UploadForm extends HTMLForm {
*/
protected function getSourceSection() {
global $wgLang, $wgUser, $wgRequest;
+ global $wgMaxUploadSize;
if ( $this->mSessionKey ) {
return array(
@@ -783,13 +833,16 @@ class UploadForm extends HTMLForm {
'help' => wfMsgExt( 'upload-maxfilesize',
array( 'parseinline', 'escapenoentities' ),
$wgLang->formatSize(
- wfShorthandToInteger( ini_get( 'upload_max_filesize' ) )
+ wfShorthandToInteger( min(
+ wfShorthandToInteger(
+ ini_get( 'upload_max_filesize' )
+ ), $wgMaxUploadSize
+ ) )
)
) . ' ' . wfMsgHtml( 'upload_source_file' ),
'checked' => $selectedSourceType == 'file',
);
if ( $canUploadByUrl ) {
- global $wgMaxUploadSize;
$descriptor['UploadFileURL'] = array(
'class' => 'UploadSourceField',
'section' => 'source',
@@ -826,7 +879,6 @@ class UploadForm extends HTMLForm {
global $wgLang, $wgCheckFileExtensions, $wgStrictFileExtensions,
$wgFileExtensions, $wgFileBlacklist;
- $allowedExtensions = '';
if( $wgCheckFileExtensions ) {
if( $wgStrictFileExtensions ) {
# Everything not permitted is banned
@@ -872,6 +924,9 @@ class UploadForm extends HTMLForm {
'id' => 'wpDestFile',
'label-message' => 'destfilename',
'size' => 60,
+ 'default' => $this->mDestFile,
+ # FIXME: hack to work around poor handling of the 'default' option in HTMLForm
+ 'nodata' => strval( $this->mDestFile ) !== '',
),
'UploadDescription' => array(
'type' => 'textarea',
@@ -897,17 +952,19 @@ class UploadForm extends HTMLForm {
'EditTools' => array(
'type' => 'edittools',
'section' => 'description',
- ),
- 'License' => array(
+ )
+ );
+
+ if ( $this->mForReUpload ) {
+ $descriptor['DestFile']['readonly'] = true;
+ } else {
+ $descriptor['License'] = array(
'type' => 'select',
'class' => 'Licenses',
'section' => 'description',
'id' => 'wpLicense',
'label-message' => 'license',
- ),
- );
- if ( $this->mForReUpload ) {
- $descriptor['DestFile']['readonly'] = true;
+ );
}
global $wgUseCopyrightUpload;
@@ -958,14 +1015,14 @@ class UploadForm extends HTMLForm {
);
}
- $descriptor['DestFileWarningAck'] = array(
+ $descriptor['wpDestFileWarningAck'] = array(
'type' => 'hidden',
'id' => 'wpDestFileWarningAck',
'default' => $this->mDestWarningAck ? '1' : '',
);
if ( $this->mForReUpload ) {
- $descriptor['ForReUpload'] = array(
+ $descriptor['wpForReUpload'] = array(
'type' => 'hidden',
'id' => 'wpForReUpload',
'default' => '1',
@@ -987,7 +1044,7 @@ class UploadForm extends HTMLForm {
* Add upload JS to $wgOut
*/
protected function addUploadJS() {
- global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI;
+ global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI, $wgStrictFileExtensions;
global $wgOut;
$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
@@ -996,15 +1053,19 @@ class UploadForm extends HTMLForm {
$scriptVars = array(
'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
'wgAjaxLicensePreview' => $useAjaxLicensePreview,
- 'wgUploadAutoFill' => !$this->mForReUpload,
+ 'wgUploadAutoFill' => !$this->mForReUpload &&
+ // If we received mDestFile from the request, don't autofill
+ // the wpDestFile textbox
+ $this->mDestFile === '',
'wgUploadSourceIds' => $this->mSourceIds,
+ 'wgStrictFileExtensions' => $wgStrictFileExtensions,
+ 'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
);
$wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
// For support
- $wgOut->addScriptFile( 'edit.js' );
- $wgOut->addScriptFile( 'upload.js' );
+ $wgOut->addModules( array( 'mediawiki.legacy.edit', 'mediawiki.legacy.upload' ) );
}
/**
@@ -1022,7 +1083,7 @@ class UploadForm extends HTMLForm {
* A form field that contains a radio box in the label
*/
class UploadSourceField extends HTMLTextField {
- function getLabelHtml() {
+ function getLabelHtml( $cellAttributes = array() ) {
$id = "wpSourceType{$this->mParams['upload-type']}";
$label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
@@ -1039,7 +1100,7 @@ class UploadSourceField extends HTMLTextField {
$label .= Html::element( 'input', $attribs );
}
- return Html::rawElement( 'td', array( 'class' => 'mw-label' ), $label );
+ return Html::rawElement( 'td', array( 'class' => 'mw-label' ) + $cellAttributes, $label );
}
function getSize() {