Merge "(bug 37181) Removed hard coded parentheses in SpecialMIMEsearch.php"
[lhc/web/wiklou.git] / includes / specials / SpecialUpload.php
index 724e77a..91631f8 100644 (file)
@@ -111,14 +111,7 @@ class SpecialUpload extends SpecialPage {
 
                // If it was posted check for the token (no remote POST'ing with user credentials)
                $token = $request->getVal( 'wpEditToken' );
-               if( $this->mSourceType == 'file' && $token == null ) {
-                       // Skip token check for file uploads as that can't be faked via JS...
-                       // Some client-side tools don't expect to need to send wpEditToken
-                       // with their submissions, as that's new in 1.16.
-                       $this->mTokenOk = true;
-               } else {
-                       $this->mTokenOk = $this->getUser()->matchEditToken( $token );
-               }
+               $this->mTokenOk = $this->getUser()->matchEditToken( $token );
 
                $this->uploadFormTextTop = '';
                $this->uploadFormTextAfterSummary = '';
@@ -140,8 +133,6 @@ class SpecialUpload extends SpecialPage {
         * Special page entry point
         */
        public function execute( $par ) {
-               global $wgGroupPermissions;
-
                $this->setHeaders();
                $this->outputHeader();
 
@@ -154,25 +145,16 @@ class SpecialUpload extends SpecialPage {
                $user = $this->getUser();
                $permissionRequired = UploadBase::isAllowed( $user );
                if( $permissionRequired !== true ) {
-                       if( !$user->isLoggedIn() && ( $wgGroupPermissions['user']['upload']
-                               || $wgGroupPermissions['autoconfirmed']['upload'] ) ) {
-                               // Custom message if logged-in users without any special rights can upload
-                               throw new ErrorPageError( 'uploadnologin', 'uploadnologintext' );
-                       } else {
-                               throw new PermissionsError( $permissionRequired );
-                       }
+                       throw new PermissionsError( $permissionRequired );
                }
 
                # Check blocks
                if( $user->isBlocked() ) {
-                       $this->getOutput()->blockedPage();
-                       return;
+                       throw new UserBlockedError( $user->getBlock() );
                }
 
                # Check whether we actually want to allow changing stuff
-               if( wfReadOnly() ) {
-                       throw new ReadOnlyError;
-               }
+               $this->checkReadOnly();
 
                $this->loadRequest();
 
@@ -188,8 +170,7 @@ class SpecialUpload extends SpecialPage {
                if (
                        $this->mTokenOk && !$this->mCancelUpload &&
                        ( $this->mUpload && $this->mUploadClicked )
-               )
-               {
+               ) {
                        $this->processUpload();
                } else {
                        # Backwards compatibility hook
@@ -197,8 +178,6 @@ class SpecialUpload extends SpecialPage {
                                wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
                                return;
                        }
-
-
                        $this->showUploadForm( $this->getUploadForm() );
                }
 
@@ -255,8 +234,7 @@ class SpecialUpload extends SpecialPage {
                if(
                        !$this->mTokenOk && !$this->mCancelUpload &&
                        ( $this->mUpload && $this->mUploadClicked )
-               )
-               {
+               ) {
                        $form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) );
                }
 
@@ -290,7 +268,6 @@ class SpecialUpload extends SpecialPage {
                }
 
                return $form;
-
        }
 
        /**
@@ -329,7 +306,7 @@ class SpecialUpload extends SpecialPage {
         */
        protected function showRecoverableUploadError( $message ) {
                $sessionKey = $this->mUpload->stashSession();
-               $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
+               $message = '<h2>' . wfMsgHtml( 'uploaderror' ) . "</h2>\n" .
                        '<div class="error">' . $message . "</div>\n";
 
                $form = $this->getUploadForm( $message, $sessionKey );
@@ -396,7 +373,7 @@ class SpecialUpload extends SpecialPage {
        /**
         * Show the upload form with error message, but do not stash the file.
         *
-        * @param $message HTML string
+        * @param $message string HTML string
         */
        protected function showUploadError( $message ) {
                $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
@@ -473,11 +450,17 @@ class SpecialUpload extends SpecialPage {
 
        /**
         * Get the initial image page text based on a comment and optional file status information
+        * @param $comment string
+        * @param $license string
+        * @param $copyStatus string
+        * @param $source string
+        * @return string
         */
        public static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
                global $wgUseCopyrightUpload, $wgForceUIMsgAsContentMsg;
                $wgForceUIMsgAsContentMsg = (array) $wgForceUIMsgAsContentMsg;
 
+               $msg = array();
                /* 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.
@@ -521,6 +504,7 @@ class SpecialUpload extends SpecialPage {
         *
         * Note that the page target can be changed *on the form*, so our check
         * state can get out of sync.
+        * @return Bool|String
         */
        protected function getWatchCheck() {
                if( $this->getUser()->getOption( 'watchdefault' ) ) {
@@ -580,11 +564,11 @@ class SpecialUpload extends SpecialPage {
                        case UploadBase::FILETYPE_BADTYPE:
                                $msg = wfMessage( 'filetype-banned-type' );
                                if ( isset( $details['blacklistedExt'] ) ) {
-                                       $msg->params( $this->getLang()->commaList( $details['blacklistedExt'] ) );
+                                       $msg->params( $this->getLanguage()->commaList( $details['blacklistedExt'] ) );
                                } else {
                                        $msg->params( $details['finalExt'] );
                                }
-                               $msg->params( $this->getLang()->commaList( $wgFileExtensions ),
+                               $msg->params( $this->getLanguage()->commaList( $wgFileExtensions ),
                                        count( $wgFileExtensions ) );
 
                                // Add PLURAL support for the first parameter. This results
@@ -719,6 +703,8 @@ class SpecialUpload extends SpecialPage {
 
        /**
         * Construct a warning and a gallery from an array of duplicate files.
+        * @param $dupes array
+        * @return string
         */
        public static function getDupeWarning( $dupes ) {
                global $wgOut;
@@ -760,6 +746,8 @@ class UploadForm extends HTMLForm {
 
        protected $mMaxFileSize = array();
 
+       protected $mMaxUploadSize = array();
+
        public function __construct( array $options = array(), IContextSource $context = null ) {
                $this->mWatch = !empty( $options['watch'] );
                $this->mForReUpload = !empty( $options['forreupload'] );
@@ -823,7 +811,7 @@ class UploadForm extends HTMLForm {
                        );
                }
 
-               $canUploadByUrl = UploadFromUrl::isEnabled() && $this->getUser()->isAllowed( 'upload_by_url' );
+               $canUploadByUrl = UploadFromUrl::isEnabled() && UploadFromUrl::isAllowed( $this->getUser() );
                $radio = $canUploadByUrl;
                $selectedSourceType = strtolower( $this->getRequest()->getText( 'wpSourceType', 'File' ) );
 
@@ -842,7 +830,9 @@ class UploadForm extends HTMLForm {
                # that setting doesn't exist
                if ( !wfIsHipHop() ) {
                        $this->mMaxUploadSize['file'] = min( $this->mMaxUploadSize['file'],
-                               wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ) );
+                               wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
+                               wfShorthandToInteger( ini_get( 'post_max_size' ) )
+                       );
                }
 
                $descriptor['UploadFile'] = array(
@@ -855,7 +845,7 @@ class UploadForm extends HTMLForm {
                        'radio' => &$radio,
                        'help' => wfMsgExt( 'upload-maxfilesize',
                                        array( 'parseinline', 'escapenoentities' ),
-                                       $this->getContext()->getLang()->formatSize( $this->mMaxUploadSize['file'] )
+                                       $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['file'] )
                                ) . ' ' . wfMsgHtml( 'upload_source_file' ),
                        'checked' => $selectedSourceType == 'file',
                );
@@ -870,7 +860,7 @@ class UploadForm extends HTMLForm {
                                'radio' => &$radio,
                                'help' => wfMsgExt( 'upload-maxfilesize',
                                                array( 'parseinline', 'escapenoentities' ),
-                                               $this->getContext()->getLang()->formatSize( $this->mMaxUploadSize['url'] )
+                                               $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['url'] )
                                        ) . ' ' . wfMsgHtml( 'upload_source_url' ),
                                'checked' => $selectedSourceType == 'url',
                        );
@@ -902,16 +892,16 @@ class UploadForm extends HTMLForm {
                                # Everything not permitted is banned
                                $extensionsList =
                                        '<div id="mw-upload-permitted">' .
-                                       wfMsgExt( 'upload-permitted', 'parse', $this->getContext()->getLang()->commaList( $wgFileExtensions ) ) .
+                                       wfMsgExt( 'upload-permitted', 'parse', $this->getContext()->getLanguage()->commaList( $wgFileExtensions ) ) .
                                        "</div>\n";
                        } else {
                                # We have to list both preferred and prohibited
                                $extensionsList =
                                        '<div id="mw-upload-preferred">' .
-                                       wfMsgExt( 'upload-preferred', 'parse', $this->getContext()->getLang()->commaList( $wgFileExtensions ) ) .
+                                       wfMsgExt( 'upload-preferred', 'parse', $this->getContext()->getLanguage()->commaList( $wgFileExtensions ) ) .
                                        "</div>\n" .
                                        '<div id="mw-upload-prohibited">' .
-                                       wfMsgExt( 'upload-prohibited', 'parse', $this->getContext()->getLang()->commaList( $wgFileBlacklist ) ) .
+                                       wfMsgExt( 'upload-prohibited', 'parse', $this->getContext()->getLanguage()->commaList( $wgFileBlacklist ) ) .
                                        "</div>\n";
                        }
                } else {
@@ -1096,7 +1086,7 @@ class UploadForm extends HTMLForm {
                );
 
                $out = $this->getOutput();
-               $out->addScript( Skin::makeVariablesScript( $scriptVars ) );
+               $out->addJsConfigVars( $scriptVars );
 
 
                $out->addModules( array(
@@ -1121,6 +1111,11 @@ class UploadForm extends HTMLForm {
  * A form field that contains a radio box in the label
  */
 class UploadSourceField extends HTMLTextField {
+
+       /**
+        * @param $cellAttributes array
+        * @return string
+        */
        function getLabelHtml( $cellAttributes = array() ) {
                $id = "wpSourceType{$this->mParams['upload-type']}";
                $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
@@ -1141,6 +1136,9 @@ class UploadSourceField extends HTMLTextField {
                return Html::rawElement( 'td', array( 'class' => 'mw-label' ) + $cellAttributes, $label );
        }
 
+       /**
+        * @return int
+        */
        function getSize() {
                return isset( $this->mParams['size'] )
                        ? $this->mParams['size']