Convert all array() syntax to []
[lhc/web/wiklou.git] / includes / specials / SpecialUpload.php
index 6692bb6..2754b13 100644 (file)
@@ -38,6 +38,10 @@ class SpecialUpload extends SpecialPage {
                parent::__construct( 'Upload', 'upload' );
        }
 
+       public function doesWrites() {
+               return true;
+       }
+
        /** Misc variables **/
 
        /** @var WebRequest|FauxRequest The request this form is supposed to handle */
@@ -197,7 +201,7 @@ class SpecialUpload extends SpecialPage {
                        $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;
@@ -241,7 +245,7 @@ class SpecialUpload extends SpecialPage {
                # 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,
@@ -252,7 +256,7 @@ class SpecialUpload extends SpecialPage {
                        'texttop' => $this->uploadFormTextTop,
                        'textaftersummary' => $this->uploadFormTextAfterSummary,
                        'destfile' => $this->mDesiredDestName,
-               ), $context );
+               ], $context );
 
                # Check the token, but only if necessary
                if (
@@ -267,19 +271,19 @@ class SpecialUpload extends SpecialPage {
                $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 );
@@ -372,11 +376,11 @@ class SpecialUpload extends SpecialPage {
                                $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' ) {
@@ -392,9 +396,9 @@ class SpecialUpload extends SpecialPage {
                                }
                        } 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";
                        }
@@ -405,8 +409,14 @@ class SpecialUpload extends SpecialPage {
 
                $form = $this->getUploadForm( $warningHtml, $sessionKey, /* $hideIgnoreWarning */ true );
                $form->setSubmitText( $this->msg( 'upload-tryagain' )->text() );
-               $form->addButton( 'wpUploadIgnoreWarning', $this->msg( 'ignorewarning' )->text() );
-               $form->addButton( 'wpCancelUpload', $this->msg( 'reuploaddesc' )->text() );
+               $form->addButton( [
+                       'name' => 'wpUploadIgnoreWarning',
+                       'value' => $this->msg( 'ignorewarning' )->text()
+               ] );
+               $form->addButton( [
+                       'name' => 'wpCancelUpload',
+                       'value' => $this->msg( 'reuploaddesc' )->text()
+               ] );
 
                $this->showUploadForm( $form );
 
@@ -438,7 +448,7 @@ class SpecialUpload extends SpecialPage {
                        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
@@ -491,11 +501,29 @@ class SpecialUpload extends SpecialPage {
                        $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() ) {
@@ -506,7 +534,7 @@ class SpecialUpload extends SpecialPage {
 
                // Success, redirect to description page
                $this->mUploadSuccessful = true;
-               Hooks::run( 'SpecialUploadComplete', array( &$this ) );
+               Hooks::run( 'SpecialUploadComplete', [ &$this ] );
                $this->getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() );
        }
 
@@ -527,13 +555,13 @@ class SpecialUpload extends SpecialPage {
                        $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 {
@@ -792,11 +820,11 @@ class UploadForm extends HTMLForm {
 
        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 );
                }
@@ -822,7 +850,7 @@ class UploadForm extends HTMLForm {
                        + $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
@@ -831,8 +859,8 @@ class UploadForm extends HTMLForm {
                        $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' );
@@ -846,7 +874,7 @@ class UploadForm extends HTMLForm {
                $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'];
@@ -862,16 +890,16 @@ class UploadForm extends HTMLForm {
         */
        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()
@@ -880,25 +908,20 @@ class UploadForm extends HTMLForm {
                $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'] = UploadBase::getMaxUploadSize( 'file' );
-               # Limit to upload_max_filesize unless we are running under HipHop and
-               # that setting doesn't exist
-               if ( !wfIsHHVM() ) {
-                       $this->mMaxUploadSize['file'] = min( $this->mMaxUploadSize['file'],
-                               wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
-                               wfShorthandToInteger( ini_get( 'post_max_size' ) )
-                       );
-               }
+               $this->mMaxUploadSize['file'] = min(
+                       UploadBase::getMaxUploadSize( 'file' ),
+                       UploadBase::getMaxPhpUploadSize()
+               );
 
                $help = $this->msg( 'upload-maxfilesize',
                                $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['file'] )
@@ -911,7 +934,7 @@ class UploadForm extends HTMLForm {
                        $help .= $this->msg( 'upload_source_file' )->parse();
                }
 
-               $descriptor['UploadFile'] = array(
+               $descriptor['UploadFile'] = [
                        'class' => 'UploadSourceField',
                        'section' => 'source',
                        'type' => 'file',
@@ -922,11 +945,11 @@ class UploadForm extends HTMLForm {
                        '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',
@@ -940,16 +963,16 @@ class UploadForm extends HTMLForm {
                                        $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;
        }
@@ -1018,18 +1041,18 @@ class UploadForm extends HTMLForm {
                        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',
@@ -1038,8 +1061,8 @@ class UploadForm extends HTMLForm {
                                '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',
@@ -1049,50 +1072,50 @@ class UploadForm extends HTMLForm {
                                '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;
@@ -1107,37 +1130,37 @@ class UploadForm extends HTMLForm {
        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;
@@ -1162,7 +1185,7 @@ class UploadForm extends HTMLForm {
                        $config->get( 'AjaxLicensePreview' ) && $config->get( 'EnableAPI' );
                $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
 
-               $scriptVars = array(
+               $scriptVars = [
                        'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
                        'wgAjaxLicensePreview' => $useAjaxLicensePreview,
                        'wgUploadAutoFill' => !$this->mForReUpload &&
@@ -1176,15 +1199,15 @@ class UploadForm extends HTMLForm {
                        '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.
-               ) );
+               ] );
        }
 
        /**
@@ -1206,9 +1229,9 @@ class UploadSourceField extends HTMLTextField {
         * @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'] ) ) {
@@ -1219,12 +1242,12 @@ class UploadSourceField extends HTMLTextField {
                                $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';
@@ -1233,7 +1256,7 @@ class UploadSourceField extends HTMLTextField {
                        $label .= Html::element( 'input', $attribs );
                }
 
-               return Html::rawElement( 'td', array( 'class' => 'mw-label' ) + $cellAttributes, $label );
+               return Html::rawElement( 'td', [ 'class' => 'mw-label' ] + $cellAttributes, $label );
        }
 
        /**