$this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' )
|| $request->getCheck( 'wpUploadIgnoreWarning' );
- $this->mWatchthis = $request->getBool( 'wpWatchthis' );
+ $this->mWatchthis = $request->getBool( 'wpWatchthis' ) && $wgUser->isLoggedIn();
$this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' );
$this->mCopyrightSource = $request->getText( 'wpUploadSource' );
# Initialize form
$form = new UploadForm( array(
- 'watch' => $this->watchCheck(),
+ 'watch' => $this->getWatchCheck(),
'forreupload' => $this->mForReUpload,
'sessionkey' => $sessionKey,
'hideignorewarning' => $hideIgnoreWarning,
# Check the token, but only if necessary
if( !$this->mTokenOk && !$this->mCancelUpload
- && ( $this->mUpload && $this->mUploadClicked ) )
+ && ( $this->mUpload && $this->mUploadClicked ) ) {
$form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) );
+ }
# Add text to form
$form->addPreText( '<div id="uploadtext">' . wfMsgExt( 'uploadtext', 'parse' ) . '</div>');
$title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
// Show a subtitle link to deleted revisions (to sysops et al only)
- if( $title instanceof Title && ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
- $link = wfMsgExt(
- $wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted',
- array( 'parse', 'replaceafter' ),
- $wgUser->getSkin()->linkKnown(
- SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
- wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
- )
- );
- $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
+ if( $title instanceof Title ) {
+ $count = $title->isDeleted();
+ if ( $count > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
+ $link = wfMsgExt(
+ $wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted',
+ array( 'parse', 'replaceafter' ),
+ $wgUser->getSkin()->linkKnown(
+ SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
+ wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
+ )
+ );
+ $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
+ }
}
// Show the relevant lines from deletion log (for still deleted files only)
*
* @param string $message HTML message to be passed to mainUploadForm
*/
- protected function recoverableUploadError( $message ) {
+ protected function showRecoverableUploadError( $message ) {
$sessionKey = $this->mUpload->stashSession();
$message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
'<div class="error">' . $message . "</div>\n";
*
* @param array $warnings
*/
- protected function uploadWarning( $warnings ) {
+ protected function showUploadWarning( $warnings ) {
global $wgUser;
$sessionKey = $this->mUpload->stashSession();
*
* @param string $message
*/
- protected function uploadError( $message ) {
+ protected function showUploadError( $message ) {
$message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
'<div class="error">' . $message . "</div>\n";
$this->showUploadForm( $this->getUploadForm( $message ) );
// Verify permissions
$permErrors = $this->mUpload->verifyPermissions( $wgUser );
- if( $permErrors !== true )
- return $wgOut->showPermissionsErrorPage( $permErrors );
+ if( $permErrors !== true ) {
+ $wgOut->showPermissionsErrorPage( $permErrors );
+ return;
+ }
// Fetch the file if required
$status = $this->mUpload->fetchFile();
- if( !$status->isOK() )
- return $this->mainUploadForm( $wgOut->parse( $status->getWikiText() ) );
+ if( !$status->isOK() ) {
+ $this->showUploadForm( $this->getUploadForm( $wgOut->parse( $status->getWikiText() ) ) );
+ return;
+ }
// Upload verification
$details = $this->mUpload->verifyUpload();
- if ( $details['status'] != UploadBase::OK )
- return $this->processVerificationError( $details );
+ if ( $details['status'] != UploadBase::OK ) {
+ $this->processVerificationError( $details );
+ return;
+ }
$this->mLocalFile = $this->mUpload->getLocalFile();
// Check warnings if necessary
if( !$this->mIgnoreWarning ) {
$warnings = $this->mUpload->checkWarnings();
- if( count( $warnings ) )
- return $this->uploadWarning( $warnings );
+ if( count( $warnings ) ) {
+ $this->showUploadWarning( $warnings );
+ return;
+ }
}
// Get the page text if this is not a reupload
$pageText = false;
}
$status = $this->mUpload->performUpload( $this->mComment, $pageText, $this->mWatchthis, $wgUser );
- if ( !$status->isGood() )
- return $this->uploadError( $wgOut->parse( $status->getWikiText() ) );
+ if ( !$status->isGood() ) {
+ $this->showUploadError( $wgOut->parse( $status->getWikiText() ) );
+ return;
+ }
// Success, redirect to description page
wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
* Note that the page target can be changed *on the form*, so our check
* state can get out of sync.
*/
- protected function watchCheck() {
+ protected function getWatchCheck() {
global $wgUser;
if( $wgUser->getOption( 'watchdefault' ) ) {
// Watch all edits!
/** Statuses that only require name changing **/
case UploadBase::MIN_LENGTH_PARTNAME:
- $this->recoverableUploadError( wfMsgHtml( 'minlength1' ) );
+ $this->showRecoverableUploadError( wfMsgHtml( 'minlength1' ) );
break;
case UploadBase::ILLEGAL_FILENAME:
- $this->recoverableUploadError( wfMsgExt( 'illegalfilename',
+ $this->showRecoverableUploadError( wfMsgExt( 'illegalfilename',
'parseinline', $details['filtered'] ) );
break;
case UploadBase::OVERWRITE_EXISTING_FILE:
- $this->recoverableUploadError( wfMsgExt( $details['overwrite'],
+ $this->showRecoverableUploadError( wfMsgExt( $details['overwrite'],
'parseinline' ) );
break;
case UploadBase::FILETYPE_MISSING:
- $this->recoverableUploadError( wfMsgExt( 'filetype-missing',
+ $this->showRecoverableUploadError( wfMsgExt( 'filetype-missing',
'parseinline' ) );
break;
/** Statuses that require reuploading **/
case UploadBase::EMPTY_FILE:
- $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
+ $this->showUploadForm( $this->getUploadForm( wfMsgHtml( 'emptyfile' ) ) );
break;
case UploadBase::FILETYPE_BADTYPE:
$finalExt = $details['finalExt'];
- $this->uploadError(
+ $this->showUploadError(
wfMsgExt( 'filetype-banned-type',
array( 'parseinline' ),
htmlspecialchars( $finalExt ),
case UploadBase::VERIFICATION_ERROR:
unset( $details['status'] );
$code = array_shift( $details['details'] );
- $this->uploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
+ $this->showUploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
break;
case UploadBase::HOOK_ABORTED:
- $error = $details['error'];
- $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
+ if ( is_array( $details['error'] ) ) { # allow hooks to return error details in an array
+ $args = $details['error'];
+ $error = array_shift( $args );
+ } else {
+ $error = $details['error'];
+ $args = null;
+ }
+
+ $this->showUploadError( wfMsgExt( $error, 'parseinline', $args ) );
break;
default:
throw new MWException( __METHOD__ . ": Unknown value `{$details['status']}`" );
'section' => 'source',
'id' => 'wpUploadFileURL',
'label-message' => 'sourceurl',
- 'upload-type' => 'Url',
+ 'upload-type' => 'url',
'radio' => &$radio,
'help' => wfMsgExt( 'upload-maxfilesize',
array( 'parseinline', 'escapenoentities' ),
'checked' => $selectedSourceType == 'url',
);
}
- wfRunHooks( 'UploadFormSourceDescriptors', array( $descriptor, &$radio, $selectedSourceType ) );
+ wfRunHooks( 'UploadFormSourceDescriptors', array( &$descriptor, &$radio, $selectedSourceType ) );
$descriptor['Extensions'] = array(
'type' => 'info',
* @return array Descriptor array
*/
protected function getOptionsSection() {
- global $wgOut;
+ global $wgUser, $wgOut;
- $descriptor = array(
- 'Watchthis' => array(
- 'type' => 'check',
- 'id' => 'wpWatchthis',
- 'label-message' => 'watchthisupload',
- 'section' => 'options',
- )
- );
- if ( !$this->mHideIgnoreWarning ) {
+ if( $wgUser->isLoggedIn() ) {
+ $descriptor = array(
+ 'Watchthis' => array(
+ 'type' => 'check',
+ 'id' => 'wpWatchthis',
+ 'label-message' => 'watchthisupload',
+ 'section' => 'options',
+ )
+ );
+ }
+ if( !$this->mHideIgnoreWarning ) {
$descriptor['IgnoreWarning'] = array(
'type' => 'check',
'id' => 'wpIgnoreWarning',
* @param bool $autofill Whether or not to autofill the destination
* filename text box
*/
- protected function addUploadJS( $autofill = true ) {
+ protected function addUploadJS( ) {
global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
- global $wgEnableFirefogg, $wgEnableJS2system;
global $wgOut;
$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
$scriptVars = array(
'wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck,
'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview,
- 'wgEnableFirefogg' => (bool)$wgEnableFirefogg,
- 'wgUploadAutoFill' => (bool)$autofill,
+ 'wgUploadAutoFill' => !$this->mForReUpload,
'wgUploadSourceIds' => $this->mSourceIds,
);
$wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
-
- if ( $wgEnableJS2system ) {
- //js2version of upload page:
- $wgOut->addScriptClass( 'uploadPage' );
- } else {
- //legacy upload code:
- $wgOut->addScriptFile( 'upload.js' );
- $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
- }
+
+ // For <charinsert> support
+ $wgOut->addScriptFile( 'edit.js' );
+ $wgOut->addScriptFile( 'upload.js' );
}
/**