}
/** Misc variables **/
- public $mRequest; // The WebRequest or FauxRequest this form is supposed to handle
+
+ /** @var WebRequest|FauxRequest The request this form is supposed to handle */
+ public $mRequest;
public $mSourceType;
- /**
- * @var UploadBase
- */
+ /** @var UploadBase */
public $mUpload;
- /**
- * @var LocalFile
- */
+ /** @var LocalFile */
public $mLocalFile;
public $mUploadClicked;
/** User input variables from the "description" section **/
- public $mDesiredDestName; // The requested target file name
+
+ /** @var string The requested target file name */
+ public $mDesiredDestName;
public $mComment;
public $mLicense;
/** User input variables from the root section **/
+
public $mIgnoreWarning;
public $mWatchthis;
public $mCopyrightStatus;
public $mCopyrightSource;
/** Hidden variables **/
+
public $mDestWarningAck;
- public $mForReUpload; // The user followed an "overwrite this file" link
- public $mCancelUpload; // The user clicked "Cancel and return to upload form" button
+
+ /** @var bool The user followed an "overwrite this file" link */
+ public $mForReUpload;
+
+ /** @var bool The user clicked "Cancel and return to upload form" button */
+ public $mCancelUpload;
public $mTokenOk;
- public $mUploadSuccessful = false; // Subclasses can use this to determine whether a file was uploaded
+
+ /** @var bool Subclasses can use this to determine whether a file was uploaded */
+ public $mUploadSuccessful = false;
/** Text injection points for hooks not using HTMLForm **/
public $uploadFormTextTop;
} else {
# Backwards compatibility hook
if ( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) ) {
- wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
+ wfDebug( "Hook 'UploadForm:initial' broke output of the upload form\n" );
+
return;
}
$this->showUploadForm( $this->getUploadForm() );
} else {
$this->getOutput()->addHTML( $form );
}
-
}
/**
$form->setSubmitText( $this->msg( 'upload-tryagain' )->escaped() );
$this->showUploadForm( $form );
}
+
/**
* Stashes the upload, shows the main form, but adds a "continue anyway button".
* Also checks whether there are actually warnings to display.
$status = $this->mUpload->fetchFile();
if ( !$status->isOK() ) {
$this->showUploadError( $this->getOutput()->parse( $status->getWikiText() ) );
+
return;
}
$details = $this->mUpload->verifyUpload();
if ( $details['status'] != UploadBase::OK ) {
$this->processVerificationError( $details );
+
return;
}
if ( $permErrors !== true ) {
$code = array_shift( $permErrors[0] );
$this->showRecoverableUploadError( $this->msg( $code, $permErrors[0] )->parse() );
+
return;
}
} else {
$pageText = false;
}
- $status = $this->mUpload->performUpload( $this->mComment, $pageText, $this->mWatchthis, $this->getUser() );
+
+ $status = $this->mUpload->performUpload(
+ $this->mComment,
+ $pageText,
+ $this->mWatchthis,
+ $this->getUser()
+ );
+
if ( !$status->isGood() ) {
$this->showUploadError( $this->getOutput()->parse( $status->getWikiText() ) );
+
return;
}
/**
* 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
+ * @param string $comment
+ * @param string $license
+ * @param string $copyStatus
+ * @param string $source
* @return string
*/
- public static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
+ public static function getInitialPageText( $comment = '', $license = '',
+ $copyStatus = '', $source = ''
+ ) {
global $wgUseCopyrightUpload, $wgForceUIMsgAsContentMsg;
$msg = array();
$pageText = $comment;
}
}
+
return $pageText;
}
$success = $this->mUpload->unsaveUploadedFile();
if ( !$success ) {
$this->getOutput()->showFileDeleteError( $this->mUpload->getTempPath() );
+
return false;
} else {
return true;
foreach ( $dupes as $file ) {
$gallery->add( $file->getTitle() );
}
+
return '<li>' .
wfMessage( 'file-exists-duplicate' )->numParams( count( $dupes ) )->parse() .
$gallery->toHtml() . "</li>\n";
public function __construct( array $options = array(), IContextSource $context = null ) {
$this->mWatch = !empty( $options['watch'] );
$this->mForReUpload = !empty( $options['forreupload'] );
- $this->mSessionKey = isset( $options['sessionkey'] )
- ? $options['sessionkey'] : '';
+ $this->mSessionKey = isset( $options['sessionkey'] ) ? $options['sessionkey'] : '';
$this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
$this->mDestWarningAck = !empty( $options['destwarningack'] );
$this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : '';
$this->mSourceIds[] = $field['id'];
}
}
-
}
/**
'section' => 'source',
'type' => 'file',
'id' => 'wpUploadFile',
+ 'radio-id' => 'wpSourceTypeFile',
'label-message' => 'sourcefilename',
'upload-type' => 'File',
'radio' => &$radio,
'help' => $this->msg( 'upload-maxfilesize',
- $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['file'] ) )
- ->parse() .
+ $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['file'] )
+ )->parse() .
$this->msg( 'word-separator' )->escaped() .
$this->msg( 'upload_source_file' )->escaped(),
'checked' => $selectedSourceType == 'file',
'class' => 'UploadSourceField',
'section' => 'source',
'id' => 'wpUploadFileURL',
+ 'radio-id' => 'wpSourceTypeurl',
'label-message' => 'sourceurl',
'upload-type' => 'url',
'radio' => &$radio,
'help' => $this->msg( 'upload-maxfilesize',
- $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['url'] ) )
- ->parse() .
+ $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['url'] )
+ )->parse() .
$this->msg( 'word-separator' )->escaped() .
$this->msg( 'upload_source_url' )->escaped(),
'checked' => $selectedSourceType == 'url',
'default' => $this->getExtensionsMessage(),
'raw' => true,
);
+
return $descriptor;
}
# Print a list of allowed file extensions, if so configured. We ignore
# MIME type here, it's incomprehensible to most people and too long.
global $wgCheckFileExtensions, $wgStrictFileExtensions,
- $wgFileExtensions, $wgFileBlacklist;
+ $wgFileExtensions, $wgFileBlacklist;
if ( $wgCheckFileExtensions ) {
if ( $wgStrictFileExtensions ) {
# Everything not permitted is banned
$extensionsList =
'<div id="mw-upload-permitted">' .
- $this->msg( 'upload-permitted', $this->getContext()->getLanguage()->commaList( array_unique( $wgFileExtensions ) ) )->parseAsBlock() .
+ $this->msg(
+ 'upload-permitted',
+ $this->getContext()->getLanguage()->commaList( array_unique( $wgFileExtensions ) )
+ )->parseAsBlock() .
"</div>\n";
} else {
# We have to list both preferred and prohibited
$extensionsList =
'<div id="mw-upload-preferred">' .
- $this->msg( 'upload-preferred', $this->getContext()->getLanguage()->commaList( array_unique( $wgFileExtensions ) ) )->parseAsBlock() .
+ $this->msg(
+ 'upload-preferred',
+ $this->getContext()->getLanguage()->commaList( array_unique( $wgFileExtensions ) )
+ )->parseAsBlock() .
"</div>\n" .
'<div id="mw-upload-prohibited">' .
- $this->msg( 'upload-prohibited', $this->getContext()->getLanguage()->commaList( array_unique( $wgFileBlacklist ) ) )->parseAsBlock() .
+ $this->msg(
+ 'upload-prohibited',
+ $this->getContext()->getLanguage()->commaList( array_unique( $wgFileBlacklist ) )
+ )->parseAsBlock() .
"</div>\n";
}
} else {
# Everything is permitted.
$extensionsList = '';
}
+
return $extensionsList;
}
* Add upload JS to the OutputPage
*/
protected function addUploadJS() {
- global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI, $wgStrictFileExtensions;
+ global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview,
+ $wgEnableAPI, $wgStrictFileExtensions;
$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
$useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI;
function trySubmit() {
return false;
}
-
}
/**
* @return string
*/
function getLabelHtml( $cellAttributes = array() ) {
+ $id = $this->mParams['id'];
+ $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
+
if ( !empty( $this->mParams['radio'] ) ) {
- $id = "wpSourceType{$this->mParams['upload-type']}";
+ if ( isset( $this->mParams['radio-id'] ) ) {
+ $radioId = $this->mParams['radio-id'];
+ } else {
+ // Old way. For the benefit of extensions that do not define
+ // the 'radio-id' key.
+ $radioId = 'wpSourceType' . $this->mParams['upload-type'];
+ }
+
$attribs = array(
'name' => 'wpSourceType',
'type' => 'radio',
- 'id' => $id,
+ 'id' => $radioId,
'value' => $this->mParams['upload-type'],
);
+
if ( !empty( $this->mParams['checked'] ) ) {
$attribs['checked'] = 'checked';
}
- $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
+
$label .= Html::element( 'input', $attribs );
- } else {
- $id = $this->mParams['id'];
- $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
}
+
return Html::rawElement( 'td', array( 'class' => 'mw-label' ) + $cellAttributes, $label );
}