mWatch = !empty( $options['watch'] );
$this->mForReUpload = !empty( $options['forreupload'] );
$this->mSessionKey = isset( $options['sessionkey'] )
? $options['sessionkey'] : '';
$this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
$this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : '';
$this->mTextTop = isset( $options['texttop'] ) ? $options['texttop'] : '';
$this->mTextAfterSummary = isset( $options['textaftersummary'] ) ? $options['textaftersummary'] : '';
$sourceDescriptor = $this->getSourceSection();
$descriptor = $sourceDescriptor
+ $this->getDescriptionSection()
+ $this->getOptionsSection();
Hooks::run( 'UploadFormInitDescriptor', array( &$descriptor ) );
parent::__construct( $descriptor, 'upload' );
# Set some form properties
$this->setSubmitText( wfMessage( 'uploadbtn' )->text() );
$this->setSubmitName( 'wpUpload' );
$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'] ) ) {
$this->mSourceIds[] = $field['id'];
}
}
// added for Page Forms
$this->addHiddenField( 'pfInputID', $options['pfInputID'] );
$this->addHiddenField( 'pfDelimiter', $options['pfDelimiter'] );
}
/**
* Get the descriptor of the fieldset that contains the file source
* selection. The section is 'source'
*
* @return array Descriptor array
*/
protected function getSourceSection() {
if ( $this->mSessionKey ) {
return array(
'SessionKey' => array(
'id' => 'wpSessionKey',
'type' => 'hidden',
'default' => $this->mSessionKey,
),
'SourceType' => array(
'id' => 'wpSourceType',
'type' => 'hidden',
'default' => 'Stash',
),
);
}
$canUploadByUrl = UploadFromUrl::isEnabled() && $this->getUser()->isAllowed( 'upload_by_url' );
$radio = $canUploadByUrl;
$selectedSourceType = strtolower( $this->getRequest()->getText( 'wpSourceType', 'File' ) );
$descriptor = array();
if ( $this->mTextTop ) {
$descriptor['UploadFormTextTop'] = array(
'type' => 'info',
'section' => 'source',
'default' => $this->mTextTop,
'raw' => true,
);
}
$maxUploadSizeFile = wfShorthandToInteger(ini_get( 'upload_max_filesize' ));
$maxUploadSizeURL = wfShorthandToInteger(ini_get( 'upload_max_filesize' ));
global $wgMaxUploadSize;
if ( isset( $wgMaxUploadSize ) ) {
if ( gettype( $wgMaxUploadSize ) == "array" ) {
$maxUploadSizeFile = min($wgMaxUploadSize['*'], $maxUploadSizeFile);
$maxUploadSizeURL = min($wgMaxUploadSize['url'], $maxUploadSizeURL);
} else {
$maxUploadSizeFile = min($wgMaxUploadSize, $maxUploadSizeFile);
$maxUploadSizeURL = min($wgMaxUploadSize, $maxUploadSizeURL);
}
}
$descriptor['UploadFile'] = array(
'class' => 'PFUploadSourceField',
'section' => 'source',
'type' => 'file',
'id' => 'wpUploadFile',
'label-message' => 'sourcefilename',
'upload-type' => 'File',
'radio' => &$radio,
'help' => wfMessage( 'upload-maxfilesize',
$this->getLanguage()->formatSize($maxUploadSizeFile)
)->parse() . ' ' . wfMessage( 'upload_source_file' )->escaped(),
'checked' => $selectedSourceType == 'file',
);
if ( $canUploadByUrl ) {
$descriptor['UploadFileURL'] = array(
'class' => 'UploadSourceField',
'section' => 'source',
'id' => 'wpUploadFileURL',
'label-message' => 'sourceurl',
'upload-type' => 'Url',
'radio' => &$radio,
'help' => wfMessage( 'upload-maxfilesize',
$this->getLanguage()->formatSize( $maxUploadSizeURL )
)->parse() . ' ' . wfMessage( 'upload_source_url' )->escaped(),
'checked' => $selectedSourceType == 'url',
);
}
Hooks::run( 'UploadFormSourceDescriptors', array( &$descriptor, &$radio, $selectedSourceType ) );
$descriptor['Extensions'] = array(
'type' => 'info',
'section' => 'source',
'default' => $this->getExtensionsMessage(),
'raw' => true,
);
return $descriptor;
}
/**
* Get the messages indicating which extensions are preferred and prohibitted.
*
* @return string HTML string containing the message
*/
protected function getExtensionsMessage() {
# 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;
if ( $wgCheckFileExtensions ) {
if ( $wgStrictFileExtensions ) {
# Everything not permitted is banned
$extensionsList =
'
' .
wfMessage( 'upload-permitted', $this->getLanguage()->commaList( $wgFileExtensions ) )->parse() .
"
\n";
} else {
# We have to list both preferred and prohibited
$extensionsList =
'' .
wfMessage( 'upload-preferred', $this->getLanguage()->commaList( $wgFileExtensions ) )->parse() .
"
\n" .
'' .
wfMessage( 'upload-prohibited', $this->getLanguage()->commaList( $wgFileBlacklist ) )->parse() .
"
\n";
}
} else {
# Everything is permitted.
$extensionsList = '';
}
return $extensionsList;
}
/**
* Get the descriptor of the fieldset that contains the file description
* input. The section is 'description'
*
* @return array Descriptor array
*/
protected function getDescriptionSection() {
$descriptor = array(
'DestFile' => array(
'type' => 'text',
'section' => 'description',
'id' => 'wpDestFile',
'label-message' => 'destfilename',
'size' => 60,
),
'UploadDescription' => array(
'type' => 'textarea',
'section' => 'description',
'id' => 'wpUploadDescription',
'label-message' => $this->mForReUpload
? 'filereuploadsummary'
: 'fileuploadsummary',
'cols' => 80,
'rows' => 4,
),
/*
'EditTools' => array(
'type' => 'edittools',
'section' => 'description',
),
*/
'License' => array(
'type' => 'select',
'class' => 'Licenses',
'section' => 'description',
'id' => 'wpLicense',
'label-message' => 'license',
),
);
if ( $this->mTextAfterSummary ) {
$descriptor['UploadFormTextAfterSummary'] = array(
'type' => 'info',
'section' => 'description',
'default' => $this->mTextAfterSummary,
'raw' => true,
);
}
if ( $this->mForReUpload ) {
$descriptor['DestFile']['readonly'] = true;
}
global $wgUseCopyrightUpload;
if ( $wgUseCopyrightUpload ) {
$descriptor['UploadCopyStatus'] = array(
'type' => 'text',
'section' => 'description',
'id' => 'wpUploadCopyStatus',
'label-message' => 'filestatus',
);
$descriptor['UploadSource'] = array(
'type' => 'text',
'section' => 'description',
'id' => 'wpUploadSource',
'label-message' => 'filesource',
);
}
return $descriptor;
}
/**
* Get the descriptor of the fieldset that contains the upload options,
* such as "watch this file". The section is 'options'
*
* @return array Descriptor array
*/
protected function getOptionsSection() {
$descriptor = array(
'Watchthis' => array(
'type' => 'check',
'id' => 'wpWatchthis',
'label-message' => 'watchthisupload',
'section' => 'options',
)
);
if ( !$this->mHideIgnoreWarning ) {
$descriptor['IgnoreWarning'] = array(
'type' => 'check',
'id' => 'wpIgnoreWarning',
'label-message' => 'ignorewarnings',
'section' => 'options',
);
}
$descriptor['DestFileWarningAck'] = array(
'type' => 'hidden',
'id' => 'wpDestFileWarningAck',
'default' => $this->mDestWarningAck ? '1' : '',
);
return $descriptor;
}
/**
* Add the upload JS and show the form.
*/
public function show() {
$this->addUploadJS();
parent::show();
// disable output - we'll print out the page manually,
// taking the body created by the form, plus the necessary
// Javascript files, and turning them into an HTML page
global $wgTitle, $wgLanguageCode,
$wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgContLang;
$out = $this->getOutput();
$out->disable();
$wgTitle = SpecialPage::getTitleFor( 'Upload' );
$out->addModules( array(
'mediawiki.action.edit', // For support
'mediawiki.special.upload', // Extras for thumbnail and license preview.
'mediawiki.legacy.upload', // For backward compatibility (this was removed 2014-09-10)
) );
$text = <<
$ns ) {
$text .= "xmlns:{$tag}=\"{$ns}\" ";
}
$dir = $wgContLang->isRTL() ? "rtl" : "ltr";
$text .= "xml:lang=\"{$wgLanguageCode}\" lang=\"{$wgLanguageCode}\" dir=\"{$dir}\">";
$text .= <<
{$out->getHTML()}
{$out->getBottomScripts()}
END;
print $text;
}
/**
* Add upload JS to the OutputPage
*/
protected function addUploadJS() {
$config = $this->getConfig();
$useAjaxDestCheck = $config->get( 'UseAjax' ) && $config->get( 'AjaxUploadDestCheck' );
$useAjaxLicensePreview = $config->get( 'UseAjax' ) &&
$config->get( 'AjaxLicensePreview' ) && $config->get( 'EnableAPI' );
$this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
$scriptVars = array(
'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
'wgAjaxLicensePreview' => $useAjaxLicensePreview,
'wgUploadAutoFill' => !$this->mForReUpload &&
// If we received mDestFile from the request, don't autofill
// the wpDestFile textbox
$this->mDestFile === '',
'wgUploadSourceIds' => $this->mSourceIds,
'wgCheckFileExtensions' => $config->get( 'CheckFileExtensions' ),
'wgStrictFileExtensions' => $config->get( 'StrictFileExtensions' ),
'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
'wgMaxUploadSize' => $this->mMaxUploadSize,
);
$out = $this->getOutput();
$out->addJsConfigVars( $scriptVars );
}
/**
* Empty function; submission is handled elsewhere.
*
* @return bool false
*/
function trySubmit() {
return false;
}
}