<?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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * 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
- *
- * Form for handling uploads and special page.
*/
+/**
+ * Form for handling uploads and special page.
+ *
+ * @ingroup SpecialPage
+ * @ingroup Upload
+ */
class SpecialUpload extends SpecialPage {
/**
* Constructor : initialise object
}
/** 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;
* Special page entry point
*/
public function execute( $par ) {
- global $wgUser, $wgOut, $wgRequest;
+ global $wgUser, $wgOut;
$this->setHeaders();
$this->outputHeader();
wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
return;
}
+
$this->showUploadForm( $this->getUploadForm() );
}
'hideignorewarning' => $hideIgnoreWarning,
'destwarningack' => (bool)$this->mDestWarningAck,
+ 'description' => $this->mComment,
'texttop' => $this->uploadFormTextTop,
'textaftersummary' => $this->uploadFormTextAfterSummary,
'destfile' => $this->mDesiredDestName,
# 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' ),
$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' ) {
protected function processUpload() {
global $wgUser, $wgOut;
- // Verify permissions
- $permErrors = $this->mUpload->verifyPermissions( $wgUser );
- if( $permErrors !== true ) {
- $wgOut->showPermissionsErrorPage( $permErrors );
- return;
- }
-
- if( $this->mUpload instanceOf UploadFromUrl ) {
- return $this->showUploadError( wfMsg( 'uploadfromurl-queued' ) );
- }
-
// Fetch the file if required
$status = $this->mUpload->fetchFile();
if( !$status->isOK() ) {
return;
}
- // Deprecated backwards compatibility hook
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;
}
$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();
* 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;
}
$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' ) );
* @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 ) {
return '';
// if there isn't an exact match...
$file = wfLocalFile( $filename );
}
- $s = ' ';
+ $s = ' ';
if ( $file ) {
$exists = UploadBase::getExistsWarning( $file );
$warning = self::getExistsWarning( $exists );
protected $mDestWarningAck;
protected $mDestFile;
+ protected $mComment;
protected $mTextTop;
protected $mTextAfterSummary;
$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'] : '';
# 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'];
}
*/
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',
),
wfShorthandToInteger( min(
wfShorthandToInteger(
ini_get( 'upload_max_filesize' )
- ), $wgMaxUploadSize
+ ), UploadBase::getMaxUploadSize( 'file' )
) )
)
) . ' ' . wfMsgHtml( 'upload_source_file' ),
'radio' => &$radio,
'help' => wfMsgExt( 'upload-maxfilesize',
array( 'parseinline', 'escapenoentities' ),
- $wgLang->formatSize( $wgMaxUploadSize )
+ $wgLang->formatSize( UploadBase::getMaxUploadSize( 'url' ) )
) . ' ' . wfMsgHtml( 'upload_source_url' ),
'checked' => $selectedSourceType == 'url',
);
global $wgLang, $wgCheckFileExtensions, $wgStrictFileExtensions,
$wgFileExtensions, $wgFileBlacklist;
- $allowedExtensions = '';
if( $wgCheckFileExtensions ) {
if( $wgStrictFileExtensions ) {
# Everything not permitted is banned
* @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(
'label-message' => $this->mForReUpload
? 'filereuploadsummary'
: 'fileuploadsummary',
- 'cols' => $cols,
+ 'default' => $this->mComment,
+ 'cols' => intval( $wgUser->getOption( 'cols' ) ),
'rows' => 8,
)
);
);
}
- $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',
* Add upload JS to $wgOut
*/
protected function addUploadJS() {
- global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI;
+ global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI, $wgStrictFileExtensions;
global $wgOut;
$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
$scriptVars = array(
'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
'wgAjaxLicensePreview' => $useAjaxLicensePreview,
- 'wgUploadAutoFill' => !$this->mForReUpload,
+ 'wgUploadAutoFill' => !$this->mForReUpload &&
+ // If we received mDestFile from the request, don't autofill
+ // the wpDestFile textbox
+ $this->mDestFile === '',
'wgUploadSourceIds' => $this->mSourceIds,
+ 'wgStrictFileExtensions' => $wgStrictFileExtensions,
+ 'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
);
$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.
+ ) );
}
/**
* 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::element( 'input', $attribs );
}
- return Html::rawElement( 'td', array( 'class' => 'mw-label' ), $label );
+ return Html::rawElement( 'td', array( 'class' => 'mw-label' ) + $cellAttributes, $label );
}
function getSize() {