X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/96940cda03e7d46e1ce0b13d087122e157391a04..8c41e2cbfa5bfcd79f0aec6e34220379ccc842fd:/includes/specials/SpecialUpload.php diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 68ee8efc..893e4be2 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -1,18 +1,38 @@ mRequest = $request; $this->mSourceType = $request->getVal( 'wpSourceType', 'file' ); $this->mUpload = UploadBase::createFromRequest( $request ); - $this->mUploadClicked = $request->wasPosted() - && ( $request->getCheck( 'wpUpload' ) + $this->mUploadClicked = $request->wasPosted() + && ( $request->getCheck( 'wpUpload' ) || $request->getCheck( 'wpUploadIgnoreWarning' ) ); // Guess the desired name from the filename if not provided $this->mDesiredDestName = $request->getText( 'wpDestFile' ); - if( !$this->mDesiredDestName && $request->getFileName( 'wpUploadFile' ) !== null ) + if( !$this->mDesiredDestName && $request->getFileName( 'wpUploadFile' ) !== null ) { $this->mDesiredDestName = $request->getFileName( 'wpUploadFile' ); + } $this->mComment = $request->getText( 'wpUploadDescription' ); $this->mLicense = $request->getText( 'wpLicense' ); @@ -97,7 +117,7 @@ class SpecialUpload extends SpecialPage { } else { $this->mTokenOk = $wgUser->matchEditToken( $token ); } - + $this->uploadFormTextTop = ''; $this->uploadFormTextAfterSummary = ''; } @@ -107,8 +127,8 @@ class SpecialUpload extends SpecialPage { * Handle permission checking elsewhere in order to be able to show * custom error messages. * - * @param User $user - * @return bool + * @param $user User object + * @return Boolean */ public function userCanExecute( $user ) { return UploadBase::isEnabled() && parent::userCanExecute( $user ); @@ -118,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(); @@ -131,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; } @@ -156,69 +177,76 @@ class SpecialUpload extends SpecialPage { # Unsave the temporary file in case this was a cancelled upload if ( $this->mCancelUpload ) { - if ( !$this->unsaveUploadedFile() ) + if ( !$this->unsaveUploadedFile() ) { # Something went wrong, so unsaveUploadedFile showed a warning return; + } } # Process upload or show a form - if ( $this->mTokenOk && !$this->mCancelUpload - && ( $this->mUpload && $this->mUploadClicked ) ) { + if ( + $this->mTokenOk && !$this->mCancelUpload && + ( $this->mUpload && $this->mUploadClicked ) + ) + { $this->processUpload(); } else { # Backwards compatibility hook - if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) ) - { + if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) ) { wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" ); return; } + $this->showUploadForm( $this->getUploadForm() ); } # Cleanup - if ( $this->mUpload ) + if ( $this->mUpload ) { $this->mUpload->cleanupTempFile(); + } } /** - * Show the main upload form + * Show the main upload form * - * @param mixed $form An HTMLForm instance or HTML string to show + * @param $form Mixed: an HTMLForm instance or HTML string to show */ protected function showUploadForm( $form ) { # Add links if file was previously deleted if ( !$this->mDesiredDestName ) { $this->showViewDeletedLinks(); } - + if ( $form instanceof HTMLForm ) { $form->show(); } else { global $wgOut; $wgOut->addHTML( $form ); } - + } /** * Get an UploadForm instance with title and text properly set. * - * @param string $message HTML string to add to the form - * @param string $sessionKey Session key in case this is a stashed upload + * @param $message String: HTML string to add to the form + * @param $sessionKey String: session key in case this is a stashed upload + * @param $hideIgnoreWarning Boolean: whether to hide "ignore warning" check box * @return UploadForm */ protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) { global $wgOut; - + # Initialize form $form = new UploadForm( array( - 'watch' => $this->getWatchCheck(), - 'forreupload' => $this->mForReUpload, + 'watch' => $this->getWatchCheck(), + 'forreupload' => $this->mForReUpload, 'sessionkey' => $sessionKey, 'hideignorewarning' => $hideIgnoreWarning, 'destwarningack' => (bool)$this->mDestWarningAck, - + + 'description' => $this->mComment, 'texttop' => $this->uploadFormTextTop, 'textaftersummary' => $this->uploadFormTextAfterSummary, 'destfile' => $this->mDesiredDestName, @@ -226,26 +254,44 @@ class SpecialUpload extends SpecialPage { $form->setTitle( $this->getTitle() ); # Check the token, but only if necessary - if( !$this->mTokenOk && !$this->mCancelUpload - && ( $this->mUpload && $this->mUploadClicked ) ) { + if( + !$this->mTokenOk && !$this->mCancelUpload && + ( $this->mUpload && $this->mUploadClicked ) + ) + { $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::makeTitleSafe( NS_FILE, $this->mDesiredDestName ); + $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 ) ) . '
' ); # Add upload error message $form->addPreText( $message ); - + # Add footer to form $uploadFooter = wfMsgNoTrans( 'uploadfooter' ); if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) { $form->addPostText( '\n" ); } - - return $form; + + return $form; } @@ -287,13 +333,13 @@ class SpecialUpload extends SpecialPage { * essentially means that UploadBase::VERIFICATION_ERROR and * UploadBase::EMPTY_FILE should not be passed here. * - * @param string $message HTML message to be passed to mainUploadForm + * @param $message String: HTML message to be passed to mainUploadForm */ protected function showRecoverableUploadError( $message ) { $sessionKey = $this->mUpload->stashSession(); $message = '

' . wfMsgHtml( 'uploadwarning' ) . "

\n" . '
' . $message . "
\n"; - + $form = $this->getUploadForm( $message, $sessionKey ); $form->setSubmitText( wfMsg( 'upload-tryagain' ) ); $this->showUploadForm( $form ); @@ -302,13 +348,11 @@ class SpecialUpload extends SpecialPage { * Stashes the upload, shows the main form, but adds an "continue anyway button". * Also checks whether there are actually warnings to display. * - * @param array $warnings - * @return boolean true if warnings were displayed, false if there are no + * @param $warnings Array + * @return boolean true if warnings were displayed, false if there are no * warnings and the should continue processing like there was no warning */ protected function showUploadWarning( $warnings ) { - global $wgUser; - # If there are no warnings, or warnings we can ignore, return early. # mDestWarningAck is set when some javascript has shown the warning # to the user. mForReUpload is set when the user clicks the "upload a @@ -322,28 +366,26 @@ class SpecialUpload extends SpecialPage { $sessionKey = $this->mUpload->stashSession(); - $sk = $wgUser->getSkin(); - $warningHtml = '

' . wfMsgHtml( 'uploadwarning' ) . "

\n" . '\n"; $warningHtml .= wfMsgExt( 'uploadwarning-text', 'parse' ); @@ -354,7 +396,7 @@ class SpecialUpload extends SpecialPage { $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) ); $this->showUploadForm( $form ); - + # Indicate that we showed a form return true; } @@ -362,7 +404,7 @@ class SpecialUpload extends SpecialPage { /** * Show the upload form with error message, but do not stash the file. * - * @param string $message + * @param $message HTML string */ protected function showUploadError( $message ) { $message = '

' . wfMsgHtml( 'uploadwarning' ) . "

\n" . @@ -377,25 +419,21 @@ 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 ) ) ) - { + if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) ) { wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" ); - return array( 'status' => UploadBase::BEFORE_PROCESSING ); + // 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; } @@ -405,6 +443,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(); @@ -433,28 +480,41 @@ class SpecialUpload extends SpecialPage { $this->mUploadSuccessful = true; wfRunHooks( 'SpecialUploadComplete', array( &$this ) ); $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() ); - } /** * 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" . - "$licensetxt" . - '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ; + $pageText = '== ' . $msg[ 'filedesc' ] . " ==\n" . $comment . "\n" . + '== ' . $msg[ 'filestatus' ] . " ==\n" . $copyStatus . "\n" . + "$licensetxt" . + '== ' . $msg[ 'filesource' ] . " ==\n" . $source; } else { if ( $license != '' ) { - $filedesc = $comment == '' ? '' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n"; - $pageText = $filedesc . - '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n"; + $filedesc = $comment == '' ? '' : '== ' . $msg[ 'filedesc' ] . " ==\n" . $comment . "\n"; + $pageText = $filedesc . + '== ' . $msg[ 'license-header' ] . " ==\n" . '{{' . $license . '}}' . "\n"; } else { $pageText = $comment; } @@ -495,7 +555,7 @@ class SpecialUpload extends SpecialPage { /** * Provides output to the user for a result of UploadBase::verifyUpload * - * @param array $details Result of UploadBase::verifyUpload + * @param $details Array: result of UploadBase::verifyUpload */ protected function processVerificationError( $details ) { global $wgFileExtensions, $wgLang; @@ -510,10 +570,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' ) ); @@ -521,7 +577,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']; @@ -560,15 +619,16 @@ class SpecialUpload extends SpecialPage { /** * Remove a temporarily kept file stashed by saveTempUploadedFile(). - * @access private - * @return success + * + * @return Boolean: success */ protected function unsaveUploadedFile() { global $wgOut; - if ( !( $this->mUpload instanceof UploadFromStash ) ) + if ( !( $this->mUpload instanceof UploadFromStash ) ) { return true; + } $success = $this->mUpload->unsaveUploadedFile(); - if ( ! $success ) { + if ( !$success ) { $wgOut->showFileDeleteError( $this->mUpload->getTempPath() ); return false; } else { @@ -582,14 +642,15 @@ class SpecialUpload extends SpecialPage { * Formats a result of UploadBase::getExistsWarning as HTML * This check is static and can be done pre-upload via AJAX * - * @param array $exists The result of UploadBase::getExistsWarning - * @return string Empty string if there is no warning or an HTML fragment + * @param $exists Array: the result of UploadBase::getExistsWarning + * @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 ) + if ( !$exists ) { return ''; + } $file = $exists['file']; $filename = $file->getTitle()->getPrefixedText(); @@ -638,8 +699,8 @@ class SpecialUpload extends SpecialPage { /** * Get a list of warnings * - * @param string local filename, e.g. 'file exists', 'non-descriptive filename' - * @return array list of warning messages + * @param $filename String: local filename, e.g. 'file exists', 'non-descriptive filename' + * @return Array: list of warning messages */ public static function ajaxGetExistsWarning( $filename ) { $file = wfFindFile( $filename ); @@ -648,7 +709,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 ); @@ -665,15 +726,15 @@ class SpecialUpload extends SpecialPage { public static function getDupeWarning( $dupes ) { if( $dupes ) { global $wgOut; - $msg = ""; + $msg = ''; foreach( $dupes as $file ) { $title = $file->getTitle(); $msg .= $title->getPrefixedText() . - "|" . $title->getText() . "\n"; + '|' . $title->getText() . "\n"; } - $msg .= ""; - return "
  • " . - wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) . + $msg .= ''; + return '
  • ' . + wfMsgExt( 'file-exists-duplicate', array( 'parse' ), count( $dupes ) ) . $wgOut->parse( $msg ) . "
  • \n"; } else { @@ -694,25 +755,30 @@ class UploadForm extends HTMLForm { protected $mDestWarningAck; protected $mDestFile; + protected $mComment; protected $mTextTop; protected $mTextAfterSummary; - + protected $mSourceIds; public function __construct( $options = array() ) { - global $wgLang; - $this->mWatch = !empty( $options['watch'] ); $this->mForReUpload = !empty( $options['forreupload'] ); - $this->mSessionKey = isset( $options['sessionkey'] ) + $this->mSessionKey = isset( $options['sessionkey'] ) ? $options['sessionkey'] : ''; $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] ); $this->mDestWarningAck = !empty( $options['destwarningack'] ); - - $this->mTextTop = $options['texttop']; - $this->mTextAfterSummary = $options['textaftersummary']; $this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : ''; + $this->mComment = isset( $options['description'] ) ? + $options['description'] : ''; + + $this->mTextTop = isset( $options['texttop'] ) + ? $options['texttop'] : ''; + + $this->mTextAfterSummary = isset( $options['textaftersummary'] ) + ? $options['textaftersummary'] : ''; + $sourceDescriptor = $this->getSourceSection(); $descriptor = $sourceDescriptor + $this->getDescriptionSection() @@ -724,34 +790,37 @@ 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' ); # Build a list of IDs for javascript insertion $this->mSourceIds = array(); - foreach ( $sourceDescriptor as $key => $field ) { - if ( !empty( $field['id'] ) ) + foreach ( $sourceDescriptor as $field ) { + if ( !empty( $field['id'] ) ) { $this->mSourceIds[] = $field['id']; + } } } /** - * Get the descriptor of the fieldset that contains the file source + * Get the descriptor of the fieldset that contains the file source * selection. The section is 'source' - * - * @return array Descriptor array + * + * @return Array: descriptor array */ 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', ), @@ -771,25 +840,28 @@ class UploadForm extends HTMLForm { 'raw' => true, ); } - + $descriptor['UploadFile'] = array( - 'class' => 'UploadSourceField', - 'section' => 'source', - 'type' => 'file', - 'id' => 'wpUploadFile', - 'label-message' => 'sourcefilename', - 'upload-type' => 'File', - 'radio' => &$radio, - 'help' => wfMsgExt( 'upload-maxfilesize', - array( 'parseinline', 'escapenoentities' ), - $wgLang->formatSize( - wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ) - ) - ) . ' ' . wfMsgHtml( 'upload_source_file' ), - 'checked' => $selectedSourceType == 'file', + 'class' => 'UploadSourceField', + 'section' => 'source', + 'type' => 'file', + 'id' => 'wpUploadFile', + 'label-message' => 'sourcefilename', + 'upload-type' => 'File', + 'radio' => &$radio, + 'help' => wfMsgExt( 'upload-maxfilesize', + array( 'parseinline', 'escapenoentities' ), + $wgLang->formatSize( + 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', @@ -815,11 +887,10 @@ class UploadForm extends HTMLForm { return $descriptor; } - /** * Get the messages indicating which extensions are preferred and prohibitted. - * - * @return string HTML string containing the message + * + * @return String: HTML string containing the message */ protected function getExtensionsMessage() { # Print a list of allowed file extensions, if so configured. We ignore @@ -827,7 +898,6 @@ class UploadForm extends HTMLForm { global $wgLang, $wgCheckFileExtensions, $wgStrictFileExtensions, $wgFileExtensions, $wgFileBlacklist; - $allowedExtensions = ''; if( $wgCheckFileExtensions ) { if( $wgStrictFileExtensions ) { # Everything not permitted is banned @@ -855,16 +925,11 @@ class UploadForm extends HTMLForm { /** * Get the descriptor of the fieldset that contains the file description * input. The section is 'description' - * - * @return array Descriptor array + * + * @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( @@ -884,7 +949,8 @@ class UploadForm extends HTMLForm { 'label-message' => $this->mForReUpload ? 'filereuploadsummary' : 'fileuploadsummary', - 'cols' => $cols, + 'default' => $this->mComment, + 'cols' => intval( $wgUser->getOption( 'cols' ) ), 'rows' => 8, ) ); @@ -896,22 +962,25 @@ class UploadForm extends HTMLForm { 'raw' => true, ); } - + $descriptor += array( '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; if ( $wgUseCopyrightUpload ) { @@ -933,15 +1002,15 @@ class UploadForm extends HTMLForm { } /** - * Get the descriptor of the fieldset that contains the upload options, + * Get the descriptor of the fieldset that contains the upload options, * such as "watch this file". The section is 'options' - * - * @return array Descriptor array + * + * @return Array: descriptor array */ protected function getOptionsSection() { - global $wgUser, $wgOut; + global $wgUser; - if( $wgUser->isLoggedIn() ) { + if ( $wgUser->isLoggedIn() ) { $descriptor = array( 'Watchthis' => array( 'type' => 'check', @@ -952,7 +1021,7 @@ class UploadForm extends HTMLForm { ) ); } - if( !$this->mHideIgnoreWarning ) { + if ( !$this->mHideIgnoreWarning ) { $descriptor['IgnoreWarning'] = array( 'type' => 'check', 'id' => 'wpIgnoreWarning', @@ -961,14 +1030,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', @@ -976,7 +1045,6 @@ class UploadForm extends HTMLForm { } return $descriptor; - } /** @@ -989,12 +1057,9 @@ class UploadForm extends HTMLForm { /** * Add upload JS to $wgOut - * - * @param bool $autofill Whether or not to autofill the destination - * filename text box */ - protected function addUploadJS( ) { - global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI; + protected function addUploadJS() { + global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI, $wgStrictFileExtensions; global $wgOut; $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck; @@ -1008,18 +1073,19 @@ class UploadForm extends HTMLForm { // 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' ) ); } /** * Empty function; submission is handled elsewhere. - * + * * @return bool false */ function trySubmit() { @@ -1032,9 +1098,9 @@ 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 ); + $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel ); if ( !empty( $this->mParams['radio'] ) ) { $attribs = array( @@ -1043,13 +1109,15 @@ class UploadSourceField extends HTMLTextField { 'id' => $id, 'value' => $this->mParams['upload-type'], ); - if ( !empty( $this->mParams['checked'] ) ) + if ( !empty( $this->mParams['checked'] ) ) { $attribs['checked'] = 'checked'; + } $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() { return isset( $this->mParams['size'] ) ? $this->mParams['size']