Fix for r79874: only set $mRevIdFetched from fetchContent(), it was overriden by...
[lhc/web/wiklou.git] / includes / specials / SpecialUpload.php
index a4aa086..7021ef6 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 /**
+ * Implements Special:Upload
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
+ * @ingroup Upload
  */
 
 /**
- * @file
+ * Form for handling uploads and special page.
+ *
  * @ingroup SpecialPage
  * @ingroup Upload
- *
- * Form for handling uploads and special page.
  */
-
 class SpecialUpload extends SpecialPage {
        /**
         * Constructor : initialise object
@@ -40,29 +43,29 @@ class SpecialUpload extends SpecialPage {
        }
 
        /** Misc variables **/
-       protected $mRequest;                    // The WebRequest or FauxRequest this form is supposed to handle
-       protected $mSourceType;
-       protected $mUpload;
-       protected $mLocalFile;
-       protected $mUploadClicked;
+       public $mRequest;                       // The WebRequest or FauxRequest this form is supposed to handle
+       public $mSourceType;
+       public $mUpload;
+       public $mLocalFile;
+       public $mUploadClicked;
 
        /** User input variables from the "description" section **/
-       public    $mDesiredDestName;    // The requested target file name
-       protected $mComment;
-       protected $mLicense;
+       public $mDesiredDestName;       // The requested target file name
+       public $mComment;
+       public $mLicense;
 
        /** User input variables from the root section **/
-       protected $mIgnoreWarning;
-       protected $mWatchThis;
-       protected $mCopyrightStatus;
-       protected $mCopyrightSource;
+       public $mIgnoreWarning;
+       public $mWatchThis;
+       public $mCopyrightStatus;
+       public $mCopyrightSource;
 
        /** Hidden variables **/
-       protected $mDestWarningAck;
-       protected $mForReUpload;                // The user followed an "overwrite this file" link
-       protected $mCancelUpload;               // The user clicked "Cancel and return to upload form" button
-       protected $mTokenOk;
-       protected $mUploadSuccessful = false;   // Subclasses can use this to determine whether a file was uploaded
+       public $mDestWarningAck;
+       public $mForReUpload;           // The user followed an "overwrite this file" link
+       public $mCancelUpload;          // The user clicked "Cancel and return to upload form" button
+       public $mTokenOk;
+       public $mUploadSuccessful = false;      // Subclasses can use this to determine whether a file was uploaded
 
        /** Text injection points for hooks not using HTMLForm **/
        public $uploadFormTextTop;
@@ -243,6 +246,7 @@ class SpecialUpload extends SpecialPage {
                        'hideignorewarning' => $hideIgnoreWarning,
                        'destwarningack' => (bool)$this->mDestWarningAck,
 
+                       'description' => $this->mComment,
                        'texttop' => $this->uploadFormTextTop,
                        'textaftersummary' => $this->uploadFormTextAfterSummary,
                        'destfile' => $this->mDesiredDestName,
@@ -260,7 +264,7 @@ class SpecialUpload extends SpecialPage {
 
                # 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 );
+               $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
                $delNotice = ''; // empty by default
                if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) {
                        LogEventsList::showLogExtract( $delNotice, array( 'delete', 'move' ), 
@@ -365,7 +369,6 @@ class SpecialUpload extends SpecialPage {
                $warningHtml = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n"
                        . '<ul class="warning">';
                foreach( $warnings as $warning => $args ) {
-                       $msg = '';
                        if( $warning == 'exists' ) {
                                $msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n";
                        } elseif( $warning == 'duplicate' ) {
@@ -423,12 +426,13 @@ class SpecialUpload extends SpecialPage {
                        return;
                }
 
-               // Deprecated backwards compatibility hook
                if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) ) {
                        wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
-                       // 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.
+                       // This code path is deprecated. If you want to break upload processing
+                       // do so by hooking into the appropriate hooks in UploadBase::verifyUpload
+                       // and UploadBase::verifyFile.
+                       // If you use this hook to break uploading, the user will be returned
+                       // an empty form with no error message whatsoever.
                        return;
                }
 
@@ -482,21 +486,35 @@ class SpecialUpload extends SpecialPage {
         * Get the initial image page text based on a comment and optional file status information
         */
        public static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
-               global $wgUseCopyrightUpload;
+               global $wgUseCopyrightUpload, $wgForceUIMsgAsContentMsg;
+               $wgForceUIMsgAsContentMsg = (array) $wgForceUIMsgAsContentMsg;
+
+               /* 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 ) {
+                       if ( in_array( $msgName, $wgForceUIMsgAsContentMsg ) ) {
+                               $msg[$msgName] = "{{int:$msgName}}";
+                       } else {
+                               $msg[$msgName] = wfMsgForContent( $msgName );
+                       }
+               }
+
                if ( $wgUseCopyrightUpload ) {
                        $licensetxt = '';
                        if ( $license != '' ) {
-                               $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
+                               $licensetxt = '== ' . $msg[ 'license-header' ] . " ==\n" . '{{' . $license . '}}' . "\n";
                        }
-                       $pageText = '== ' . wfMsgForContent( 'filedesc' ) . " ==\n" . $comment . "\n" .
-                               '== ' . wfMsgForContent( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
+                       $pageText = '== ' . $msg[ 'filedesc' ] . " ==\n" . $comment . "\n" .
+                               '== ' . $msg[ 'filestatus' ] . " ==\n" . $copyStatus . "\n" .
                                "$licensetxt" .
-                               '== ' . wfMsgForContent( 'filesource' ) . " ==\n" . $source;
+                               '== ' . $msg[ 'filesource' ] . " ==\n" . $source;
                } else {
                        if ( $license != '' ) {
-                               $filedesc = $comment == '' ? '' : '== ' . wfMsgForContent( 'filedesc' ) . " ==\n" . $comment . "\n";
+                               $filedesc = $comment == '' ? '' : '== ' . $msg[ 'filedesc' ] . " ==\n" . $comment . "\n";
                                        $pageText = $filedesc .
-                                       '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
+                                       '== ' . $msg[ 'license-header' ] . " ==\n" . '{{' . $license . '}}' . "\n";
                        } else {
                                $pageText = $comment;
                        }
@@ -737,6 +755,7 @@ class UploadForm extends HTMLForm {
        protected $mDestWarningAck;
        protected $mDestFile;
 
+       protected $mComment;
        protected $mTextTop;
        protected $mTextAfterSummary;
 
@@ -751,6 +770,9 @@ class UploadForm extends HTMLForm {
                $this->mDestWarningAck = !empty( $options['destwarningack'] );
                $this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : '';
 
+               $this->mComment = isset( $options['description'] ) ?
+                       $options['description'] : '';
+
                $this->mTextTop = isset( $options['texttop'] )
                        ? $options['texttop'] : '';
 
@@ -774,7 +796,7 @@ class UploadForm extends HTMLForm {
 
                # Build a list of IDs for javascript insertion
                $this->mSourceIds = array();
-               foreach ( $sourceDescriptor as $key => $field ) {
+               foreach ( $sourceDescriptor as $field ) {
                        if ( !empty( $field['id'] ) ) {
                                $this->mSourceIds[] = $field['id'];
                        }
@@ -790,15 +812,14 @@ class UploadForm extends HTMLForm {
         */
        protected function getSourceSection() {
                global $wgLang, $wgUser, $wgRequest;
-               global $wgMaxUploadSize;
 
                if ( $this->mSessionKey ) {
                        return array(
-                               'wpSessionKey' => array(
+                               'SessionKey' => array(
                                        'type' => 'hidden',
                                        'default' => $this->mSessionKey,
                                ),
-                               'wpSourceType' => array(
+                               'SourceType' => array(
                                        'type' => 'hidden',
                                        'default' => 'Stash',
                                ),
@@ -833,7 +854,7 @@ class UploadForm extends HTMLForm {
                                                wfShorthandToInteger( min( 
                                                        wfShorthandToInteger(
                                                                ini_get( 'upload_max_filesize' )
-                                                       ), $wgMaxUploadSize
+                                                       ), UploadBase::getMaxUploadSize( 'file' )
                                                ) )
                                        )
                                ) . ' ' . wfMsgHtml( 'upload_source_file' ),
@@ -849,7 +870,7 @@ class UploadForm extends HTMLForm {
                                'radio' => &$radio,
                                'help' => wfMsgExt( 'upload-maxfilesize',
                                                array( 'parseinline', 'escapenoentities' ),
-                                               $wgLang->formatSize( $wgMaxUploadSize )
+                                               $wgLang->formatSize( UploadBase::getMaxUploadSize( 'url' ) )
                                        ) . ' ' . wfMsgHtml( 'upload_source_url' ),
                                'checked' => $selectedSourceType == 'url',
                        );
@@ -907,12 +928,7 @@ class UploadForm extends HTMLForm {
         * @return Array: descriptor array
         */
        protected function getDescriptionSection() {
-               global $wgUser, $wgOut;
-
-               $cols = intval( $wgUser->getOption( 'cols' ) );
-               if( $wgUser->getOption( 'editwidth' ) ) {
-                       $wgOut->addInlineStyle( '#mw-htmlform-description { width: 100%; }' );
-               }
+               global $wgUser;
 
                $descriptor = array(
                        'DestFile' => array(
@@ -932,7 +948,8 @@ class UploadForm extends HTMLForm {
                                'label-message' => $this->mForReUpload
                                        ? 'filereuploadsummary'
                                        : 'fileuploadsummary',
-                               'cols' => $cols,
+                               'default' => $this->mComment,
+                               'cols' => intval( $wgUser->getOption( 'cols' ) ),
                                'rows' => 8,
                        )
                );
@@ -1012,14 +1029,14 @@ class UploadForm extends HTMLForm {
                        );
                }
 
-               $descriptor['wpDestFileWarningAck'] = array(
+               $descriptor['DestFileWarningAck'] = array(
                        'type' => 'hidden',
                        'id' => 'wpDestFileWarningAck',
                        'default' => $this->mDestWarningAck ? '1' : '',
                );
                
                if ( $this->mForReUpload ) {
-                       $descriptor['wpForReUpload'] = array(
+                       $descriptor['ForReUpload'] = array(
                                'type' => 'hidden',
                                'id' => 'wpForReUpload',
                                'default' => '1',
@@ -1061,9 +1078,12 @@ class UploadForm extends HTMLForm {
 
                $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
 
-               // For <charinsert> support
-               $wgOut->addScriptFile( 'edit.js' );
-               $wgOut->addScriptFile( 'upload.js' );
+               
+               $wgOut->addModules( array(
+                       'mediawiki.legacy.edit', // For <charinsert> support
+                       'mediawiki.legacy.upload', // Old form stuff...
+                       'mediawiki.special.upload', // Newer extras for thumbnail preview.
+               ) );
        }
 
        /**