throw new UserBlockedError( $user->getBlock() );
}
+ // Global blocks
+ if ( $user->isBlockedGlobally() ) {
+ throw new UserBlockedError( $user->getGlobalBlock() );
+ }
+
# Check whether we actually want to allow changing stuff
$this->checkReadOnly();
$this->processUpload();
} else {
# Backwards compatibility hook
- if ( !Hooks::run( 'UploadForm:initial', array( &$this ) ) ) {
+ if ( !Hooks::run( 'UploadForm:initial', [ &$this ] ) ) {
wfDebug( "Hook 'UploadForm:initial' broke output of the upload form\n" );
return;
# Initialize form
$context = new DerivativeContext( $this->getContext() );
$context->setTitle( $this->getPageTitle() ); // Remove subpage
- $form = new UploadForm( array(
+ $form = new UploadForm( [
'watch' => $this->getWatchCheck(),
'forreupload' => $this->mForReUpload,
'sessionkey' => $sessionKey,
'texttop' => $this->uploadFormTextTop,
'textaftersummary' => $this->uploadFormTextAfterSummary,
'destfile' => $this->mDesiredDestName,
- ), $context );
+ ], $context );
# Check the token, but only if necessary
if (
$desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
$delNotice = ''; // empty by default
if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) {
- LogEventsList::showLogExtract( $delNotice, array( 'delete', 'move' ),
+ LogEventsList::showLogExtract( $delNotice, [ 'delete', 'move' ],
$desiredTitleObj,
- '', array( 'lim' => 10,
- 'conds' => array( "log_action != 'revision'" ),
+ '', [ 'lim' => 10,
+ 'conds' => [ "log_action != 'revision'" ],
'showIfEmpty' => false,
- 'msgKey' => array( 'upload-recreate-warning' ) )
+ 'msgKey' => [ 'upload-recreate-warning' ] ]
);
}
$form->addPreText( $delNotice );
# Add text to form
$form->addPreText( '<div id="uploadtext">' .
- $this->msg( 'uploadtext', array( $this->mDesiredDestName ) )->parseAsBlock() .
+ $this->msg( 'uploadtext', [ $this->mDesiredDestName ] )->parseAsBlock() .
'</div>' );
# Add upload error message
$form->addPreText( $message );
$sessionKey = $this->mUpload->stashSession();
+ // Add styles for the warning, reused from the live preview
+ $this->getOutput()->addModuleStyles( 'mediawiki.special.upload' );
+
$warningHtml = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . "</h2>\n"
- . '<div class="warningbox"><ul>';
+ . '<div class="mw-destfile-warning"><ul>';
foreach ( $warnings as $warning => $args ) {
if ( $warning == 'badfilename' ) {
$this->mDesiredDestName = Title::makeTitle( NS_FILE, $args )->getText();
$llink = Linker::linkKnown(
$ltitle,
wfMessage( 'deletionlog' )->escaped(),
- array(),
- array(
+ [],
+ [
'type' => 'delete',
'page' => Title::makeTitle( NS_FILE, $args )->getPrefixedText(),
- )
+ ]
);
$msg = "\t<li>" . wfMessage( 'filewasdeleted' )->rawParams( $llink )->parse() . "</li>\n";
} elseif ( $warning == 'duplicate' ) {
}
} else {
if ( $args === true ) {
- $args = array();
+ $args = [];
} elseif ( !is_array( $args ) ) {
- $args = array( $args );
+ $args = [ $args ];
}
$msg = "\t<li>" . $this->msg( $warning, $args )->parse() . "</li>\n";
}
$form = $this->getUploadForm( $warningHtml, $sessionKey, /* $hideIgnoreWarning */ true );
$form->setSubmitText( $this->msg( 'upload-tryagain' )->text() );
- $form->addButton( array(
+ $form->addButton( [
'name' => 'wpUploadIgnoreWarning',
'value' => $this->msg( 'ignorewarning' )->text()
- ) );
- $form->addButton( array(
+ ] );
+ $form->addButton( [
'name' => 'wpCancelUpload',
'value' => $this->msg( 'reuploaddesc' )->text()
- ) );
+ ] );
$this->showUploadForm( $form );
return;
}
- if ( !Hooks::run( 'UploadForm:BeforeProcessing', array( &$this ) ) ) {
+ if ( !Hooks::run( 'UploadForm:BeforeProcessing', [ &$this ] ) ) {
wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
// This code path is deprecated. If you want to break upload processing
// do so by hooking into the appropriate hooks in UploadBase::verifyUpload
$pageText = false;
}
+ $changeTags = $this->getRequest()->getVal( 'wpChangeTags' );
+ if ( is_null( $changeTags ) || $changeTags === '' ) {
+ $changeTags = [];
+ } else {
+ $changeTags = array_filter( array_map( 'trim', explode( ',', $changeTags ) ) );
+ }
+
+ if ( $changeTags ) {
+ $changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange(
+ $changeTags, $this->getUser() );
+ if ( !$changeTagsStatus->isOK() ) {
+ $this->showUploadError( $this->getOutput()->parse( $changeTagsStatus->getWikiText() ) );
+
+ return;
+ }
+ }
+
$status = $this->mUpload->performUpload(
$this->mComment,
$pageText,
$this->mWatchthis,
- $this->getUser()
+ $this->getUser(),
+ $changeTags
);
if ( !$status->isGood() ) {
// Success, redirect to description page
$this->mUploadSuccessful = true;
- Hooks::run( 'SpecialUploadComplete', array( &$this ) );
+ Hooks::run( 'SpecialUploadComplete', [ &$this ] );
$this->getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() );
}
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
}
- $msg = array();
+ $msg = [];
$forceUIMsgAsContentMsg = (array)$config->get( 'ForceUIMsgAsContentMsg' );
/* These messages are transcluded into the actual text of the description page.
* Thus, forcing them as content messages makes the upload to produce an int: template
* instead of hardcoding it there in the uploader language.
*/
- foreach ( array( 'license-header', 'filedesc', 'filestatus', 'filesource' ) as $msgName ) {
+ foreach ( [ 'license-header', 'filedesc', 'filestatus', 'filesource' ] as $msgName ) {
if ( in_array( $msgName, $forceUIMsgAsContentMsg ) ) {
$msg[$msgName] = "{{int:$msgName}}";
} else {
return false;
} else {
// New page should get watched if that's our option.
- return $this->getUser()->getOption( 'watchcreations' );
+ return $this->getUser()->getOption( 'watchcreations' ) ||
+ $this->getUser()->getOption( 'watchuploads' );
}
}
protected $mSourceIds;
- protected $mMaxFileSize = array();
+ protected $mMaxFileSize = [];
- protected $mMaxUploadSize = array();
+ protected $mMaxUploadSize = [];
- public function __construct( array $options = array(), IContextSource $context = null ) {
+ public function __construct( array $options = [], IContextSource $context = null ) {
if ( $context instanceof IContextSource ) {
$this->setContext( $context );
}
+ $this->getDescriptionSection()
+ $this->getOptionsSection();
- Hooks::run( 'UploadFormInitDescriptor', array( &$descriptor ) );
+ Hooks::run( 'UploadFormInitDescriptor', [ &$descriptor ] );
parent::__construct( $descriptor, $context, 'upload' );
# Add a link to edit MediaWik:Licenses
$licensesLink = Linker::linkKnown(
$this->msg( 'licenses' )->inContentLanguage()->getTitle(),
$this->msg( 'licenses-edit' )->escaped(),
- array(),
- array( 'action' => 'edit' )
+ [],
+ [ 'action' => 'edit' ]
);
$editLicenses = '<p class="mw-upload-editlicenses">' . $licensesLink . '</p>';
$this->addFooterText( $editLicenses, 'description' );
$this->setId( 'mw-upload-form' );
# Build a list of IDs for javascript insertion
- $this->mSourceIds = array();
+ $this->mSourceIds = [];
foreach ( $sourceDescriptor as $field ) {
if ( !empty( $field['id'] ) ) {
$this->mSourceIds[] = $field['id'];
*/
protected function getSourceSection() {
if ( $this->mSessionKey ) {
- return array(
- 'SessionKey' => array(
+ return [
+ 'SessionKey' => [
'type' => 'hidden',
'default' => $this->mSessionKey,
- ),
- 'SourceType' => array(
+ ],
+ 'SourceType' => [
'type' => 'hidden',
'default' => 'Stash',
- ),
- );
+ ],
+ ];
}
$canUploadByUrl = UploadFromUrl::isEnabled()
$radio = $canUploadByUrl;
$selectedSourceType = strtolower( $this->getRequest()->getText( 'wpSourceType', 'File' ) );
- $descriptor = array();
+ $descriptor = [];
if ( $this->mTextTop ) {
- $descriptor['UploadFormTextTop'] = array(
+ $descriptor['UploadFormTextTop'] = [
'type' => 'info',
'section' => 'source',
'default' => $this->mTextTop,
'raw' => true,
- );
+ ];
}
$this->mMaxUploadSize['file'] = min(
$help .= $this->msg( 'upload_source_file' )->parse();
}
- $descriptor['UploadFile'] = array(
+ $descriptor['UploadFile'] = [
'class' => 'UploadSourceField',
'section' => 'source',
'type' => 'file',
'radio' => &$radio,
'help' => $help,
'checked' => $selectedSourceType == 'file',
- );
+ ];
if ( $canUploadByUrl ) {
$this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize( 'url' );
- $descriptor['UploadFileURL'] = array(
+ $descriptor['UploadFileURL'] = [
'class' => 'UploadSourceField',
'section' => 'source',
'id' => 'wpUploadFileURL',
$this->msg( 'word-separator' )->escaped() .
$this->msg( 'upload_source_url' )->parse(),
'checked' => $selectedSourceType == 'url',
- );
+ ];
}
- Hooks::run( 'UploadFormSourceDescriptors', array( &$descriptor, &$radio, $selectedSourceType ) );
+ Hooks::run( 'UploadFormSourceDescriptors', [ &$descriptor, &$radio, $selectedSourceType ] );
- $descriptor['Extensions'] = array(
+ $descriptor['Extensions'] = [
'type' => 'info',
'section' => 'source',
'default' => $this->getExtensionsMessage(),
'raw' => true,
- );
+ ];
return $descriptor;
}
if ( $file ) {
global $wgContLang;
- $mto = $file->transform( array( 'width' => 120 ) );
+ $mto = $file->transform( [ 'width' => 120 ] );
$this->addHeaderText(
'<div class="thumb t' . $wgContLang->alignEnd() . '">' .
- Html::element( 'img', array(
+ Html::element( 'img', [
'src' => $mto->getUrl(),
'class' => 'thumbimage',
- ) ) . '</div>', 'description' );
+ ] ) . '</div>', 'description' );
}
}
- $descriptor = array(
- 'DestFile' => array(
+ $descriptor = [
+ 'DestFile' => [
'type' => 'text',
'section' => 'description',
'id' => 'wpDestFile',
'default' => $this->mDestFile,
# @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
'nodata' => strval( $this->mDestFile ) !== '',
- ),
- 'UploadDescription' => array(
+ ],
+ 'UploadDescription' => [
'type' => 'textarea',
'section' => 'description',
'id' => 'wpUploadDescription',
'default' => $this->mComment,
'cols' => $this->getUser()->getIntOption( 'cols' ),
'rows' => 8,
- )
- );
+ ]
+ ];
if ( $this->mTextAfterSummary ) {
- $descriptor['UploadFormTextAfterSummary'] = array(
+ $descriptor['UploadFormTextAfterSummary'] = [
'type' => 'info',
'section' => 'description',
'default' => $this->mTextAfterSummary,
'raw' => true,
- );
+ ];
}
- $descriptor += array(
- 'EditTools' => array(
+ $descriptor += [
+ 'EditTools' => [
'type' => 'edittools',
'section' => 'description',
'message' => 'edittools-upload',
- )
- );
+ ]
+ ];
if ( $this->mForReUpload ) {
$descriptor['DestFile']['readonly'] = true;
} else {
- $descriptor['License'] = array(
+ $descriptor['License'] = [
'type' => 'select',
'class' => 'Licenses',
'section' => 'description',
'id' => 'wpLicense',
'label-message' => 'license',
- );
+ ];
}
if ( $config->get( 'UseCopyrightUpload' ) ) {
- $descriptor['UploadCopyStatus'] = array(
+ $descriptor['UploadCopyStatus'] = [
'type' => 'text',
'section' => 'description',
'id' => 'wpUploadCopyStatus',
'label-message' => 'filestatus',
- );
- $descriptor['UploadSource'] = array(
+ ];
+ $descriptor['UploadSource'] = [
'type' => 'text',
'section' => 'description',
'id' => 'wpUploadSource',
'label-message' => 'filesource',
- );
+ ];
}
return $descriptor;
protected function getOptionsSection() {
$user = $this->getUser();
if ( $user->isLoggedIn() ) {
- $descriptor = array(
- 'Watchthis' => array(
+ $descriptor = [
+ 'Watchthis' => [
'type' => 'check',
'id' => 'wpWatchthis',
'label-message' => 'watchthisupload',
'section' => 'options',
'default' => $this->mWatch,
- )
- );
+ ]
+ ];
}
if ( !$this->mHideIgnoreWarning ) {
- $descriptor['IgnoreWarning'] = array(
+ $descriptor['IgnoreWarning'] = [
'type' => 'check',
'id' => 'wpIgnoreWarning',
'label-message' => 'ignorewarnings',
'section' => 'options',
- );
+ ];
}
- $descriptor['DestFileWarningAck'] = array(
+ $descriptor['DestFileWarningAck'] = [
'type' => 'hidden',
'id' => 'wpDestFileWarningAck',
'default' => $this->mDestWarningAck ? '1' : '',
- );
+ ];
if ( $this->mForReUpload ) {
- $descriptor['ForReUpload'] = array(
+ $descriptor['ForReUpload'] = [
'type' => 'hidden',
'id' => 'wpForReUpload',
'default' => '1',
- );
+ ];
}
return $descriptor;
$config->get( 'AjaxLicensePreview' ) && $config->get( 'EnableAPI' );
$this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
- $scriptVars = array(
+ $scriptVars = [
'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
'wgAjaxLicensePreview' => $useAjaxLicensePreview,
'wgUploadAutoFill' => !$this->mForReUpload &&
'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
'wgMaxUploadSize' => $this->mMaxUploadSize,
'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
- );
+ ];
$out = $this->getOutput();
$out->addJsConfigVars( $scriptVars );
- $out->addModules( array(
+ $out->addModules( [
'mediawiki.action.edit', // For <charinsert> support
'mediawiki.special.upload', // Extras for thumbnail and license preview.
- ) );
+ ] );
}
/**
* @param array $cellAttributes
* @return string
*/
- function getLabelHtml( $cellAttributes = array() ) {
+ function getLabelHtml( $cellAttributes = [] ) {
$id = $this->mParams['id'];
- $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
+ $label = Html::rawElement( 'label', [ 'for' => $id ], $this->mLabel );
if ( !empty( $this->mParams['radio'] ) ) {
if ( isset( $this->mParams['radio-id'] ) ) {
$radioId = 'wpSourceType' . $this->mParams['upload-type'];
}
- $attribs = array(
+ $attribs = [
'name' => 'wpSourceType',
'type' => 'radio',
'id' => $radioId,
'value' => $this->mParams['upload-type'],
- );
+ ];
if ( !empty( $this->mParams['checked'] ) ) {
$attribs['checked'] = 'checked';
$label .= Html::element( 'input', $attribs );
}
- return Html::rawElement( 'td', array( 'class' => 'mw-label' ) + $cellAttributes, $label );
+ return Html::rawElement( 'td', [ 'class' => 'mw-label' ] + $cellAttributes, $label );
}
/**