* @ingroup SpecialPage
*/
-
-/**
- * Entry point
- */
-function wfSpecialUpload() {
- global $wgRequest;
- $form = new UploadForm( $wgRequest );
- $form->execute();
-}
-
/**
* implements Special:Upload
* @ingroup SpecialPage
*/
-class UploadForm {
+class UploadForm extends SpecialPage {
/**#@+
* @access private
*/
var $mCopyrightStatus, $mCopyrightSource, $mReUpload, $mAction, $mUploadClicked;
var $mDestWarningAck;
var $mLocalFile;
-
- var $mUpload; // Instance of UploadFromBase or derivative
+
+ var $mUpload; // Instance of UploadBase or derivative
# Placeholders for text injection by hooks (must be HTML)
# extensions should take care to _append_ to the present value
var $uploadFormTextTop;
var $uploadFormTextAfterSummary;
-
+ var $mTokenOk = false;
+ var $mForReUpload = false;
/**#@-*/
/**
* Get data POSTed through the form and assign them to the object
* @param $request Data posted.
*/
- function __construct( &$request ) {
- global $wgAllowCopyUploads;
+ function __construct( $request = null ) {
+ parent::__construct( 'Upload', 'upload' );
+ $this->mRequest = $request;
+ }
+
+ protected function initForm() {
+ global $wgRequest, $wgUser;
+
+ if ( is_null( $this->mRequest ) ) {
+ $request = $wgRequest;
+ } else {
+ $request = $this->mRequest;
+ }
+ // Guess the desired name from the filename if not provided
$this->mDesiredDestName = $request->getText( 'wpDestFile' );
+ if( !$this->mDesiredDestName )
+ $this->mDesiredDestName = $request->getText( 'wpUploadFile' );
+
$this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' );
$this->mComment = $request->getText( 'wpUploadDescription' );
# filename and description
return;
}
+ //if it was posted check for the token (no remote POST'ing with user credentials)
+ $token = $request->getVal( 'wpEditToken' );
+ $this->mTokenOk = $wgUser->matchEditToken( $token );
# Placeholders for text injection by hooks (empty per default)
$this->uploadFormTextTop = "";
$this->uploadFormTextAfterSummary = "";
- $this->mReUpload = $request->getCheck( 'wpReUpload' );
$this->mUploadClicked = $request->getCheck( 'wpUpload' );
$this->mLicense = $request->getText( 'wpLicense' );
$this->mSourceType = $request->getText( 'wpSourceType' );
$this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' );
- $this->mAction = $request->getVal( 'action' );
+ $this->mForReUpload = $request->getBool( 'wpForReUpload' );
- $desiredDestName = $request->getText( 'wpDestFile' );
- if( !$desiredDestName )
- $desiredDestName = $request->getText( 'wpUploadFile' );
-
- $this->mSessionKey = $request->getInt( 'wpSessionKey' );
- if( !empty( $this->mSessionKey ) &&
- isset( $_SESSION['wsUploadData'][$this->mSessionKey]['version'] ) &&
- $_SESSION['wsUploadData'][$this->mSessionKey]['version'] ==
- UploadFromBase::SESSION_VERSION ) {
- /**
- * Confirming a temporarily stashed upload.
- * We don't want path names to be forged, so we keep
- * them in the session on the server and just give
- * an opaque key to the user agent.
- */
-
- $this->mUpload = new UploadFromStash( $desiredDestName );
- $data = $_SESSION['wsUploadData'][$this->mSessionKey];
- $this->mUpload->initialize( $data );
-
- } else {
- /**
- *Check for a newly uploaded file.
- */
- if( $wgAllowCopyUploads && $this->mSourceType == 'web' ) {
- $this->mUpload = new UploadFromUrl( $desiredDestName );
- $this->mUpload->initialize( $request->getText( 'wpUploadFileURL' ) );
- } else {
- $this->mUpload = new UploadFromUpload( $desiredDestName );
- $this->mUpload->initialize(
- $request->getFileTempName( 'wpUploadFile' ),
- $request->getFileSize( 'wpUploadFile' ),
- $request->getFileName( 'wpUploadFile' )
- );
- }
- }
- }
+ $this->mReUpload = $request->getCheck( 'wpReUpload' );
+ $this->mAction = $request->getVal( 'action' );
+ $this->mUpload = UploadBase::createFromRequest( $request );
+ }
+ public function userCanExecute( $user ) {
+ return UploadBase::isEnabled() && parent::userCanExecute( $user );
+ }
/**
* Start doing stuff
* @access public
*/
- function execute() {
- global $wgUser, $wgOut;
- global $wgEnableUploads;
+ function execute( $par ) {
+ global $wgUser, $wgOut, $wgRequest;
+
+ $this->setHeaders();
+ $this->outputHeader();
+
+ $this->initForm();
# Check uploading enabled
- if( !$wgEnableUploads ) {
- $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext', array( $this->mDesiredDestName ) );
+ if( !UploadBase::isEnabled() ) {
+ $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
return;
}
# Check permissions
+ global $wgGroupPermissions;
if( !$wgUser->isAllowed( 'upload' ) ) {
- if( !$wgUser->isLoggedIn() ) {
+ 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->readOnlyPage();
return;
}
+ //check token if uploading or reUploading
+ if( !$this->mTokenOk && !$this->mReUpload && ($this->mUpload && (
+ 'submit' == $this->mAction || $this->mUploadClicked ) )
+ ){
+ $this->mainUploadForm ( wfMsg( 'session_fail_preview' ) );
+ return ;
+ }
+
- if( $this->mReUpload ) {
- // User did not choose to ignore warnings
+ if( $this->mReUpload && $this->mUpload) {
+ // User choose to cancel upload
if( !$this->mUpload->unsaveUploadedFile() ) {
return;
}
# Because it is probably checked and shouldn't be
$this->mIgnoreWarning = false;
-
$this->mainUploadForm();
- } elseif( $this->mUpload && (
- 'submit' == $this->mAction ||
- $this->mUploadClicked
+ } elseif( $this->mUpload && (
+ 'submit' == $this->mAction ||
+ $this->mUploadClicked
) ) {
$this->processUpload();
} else {
$this->mainUploadForm();
}
-
+
if( $this->mUpload )
$this->mUpload->cleanupTempFile();
}
* Do the upload
* Checks are made in SpecialUpload::execute()
*
+ * FIXME this should really use the standard Status class (instead of associative array)
+ * FIXME would be nice if we refactored this into the upload api.
+ * (the special upload page is not the only response point that needs clean localized error msgs)
+ *
* @access private
*/
function processUpload(){
- global $wgUser, $wgOut, $wgFileExtensions, $wgLang;
- $details = null;
- $value = null;
- $value = $this->internalProcessUpload( $details );
-
- switch($value) {
- case UploadFromBase::SUCCESS:
+ global $wgOut, $wgFileExtensions, $wgLang;
+ $details = $this->internalProcessUpload();
+ switch( $details['status'] ) {
+ case UploadBase::SUCCESS:
$wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
break;
- case UploadFromBase::BEFORE_PROCESSING:
- // Do... nothing? Why?
+ case UploadBase::BEFORE_PROCESSING:
+ $this->uploadError( $details['error'] );
break;
-
- case UploadFromBase::LARGE_FILE_SERVER:
+ case UploadBase::LARGE_FILE_SERVER:
$this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
break;
- case UploadFromBase::EMPTY_FILE:
+ case UploadBase::EMPTY_FILE:
$this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
break;
- case UploadFromBase::MIN_LENGHT_PARTNAME:
+ case UploadBase::MIN_LENGTH_PARTNAME:
$this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
break;
- case UploadFromBase::ILLEGAL_FILENAME:
+ case UploadBase::ILLEGAL_FILENAME:
$this->uploadError( wfMsgExt( 'illegalfilename',
'parseinline', $details['filtered'] ) );
break;
- case UploadFromBase::PROTECTED_PAGE:
+ case UploadBase::PROTECTED_PAGE:
$wgOut->showPermissionsErrorPage( $details['permissionserrors'] );
break;
- case UploadFromBase::OVERWRITE_EXISTING_FILE:
+ case UploadBase::OVERWRITE_EXISTING_FILE:
$this->uploadError( wfMsgExt( $details['overwrite'],
'parseinline' ) );
break;
- case UploadFromBase::FILETYPE_MISSING:
+ case UploadBase::FILETYPE_MISSING:
$this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
break;
- case UploadFromBase::FILETYPE_BADTYPE:
+ case UploadBase::FILETYPE_BADTYPE:
$finalExt = $details['finalExt'];
$this->uploadError(
wfMsgExt( 'filetype-banned-type',
);
break;
- case UploadFromBase::VERIFICATION_ERROR:
- $args = $details['veri'];
- $code = array_shift( $args );
- $this->uploadError( wfMsgExt( $code, 'parseinline', $args ) );
+ case UploadBase::VERIFICATION_ERROR:
+ unset( $details['status'] );
+ $code = array_shift( $details );
+ $this->uploadError( wfMsgExt( $code, 'parseinline', $details ) );
break;
- case UploadFromBase::UPLOAD_VERIFICATION_ERROR:
+ case UploadBase::UPLOAD_VERIFICATION_ERROR:
$error = $details['error'];
$this->uploadError( wfMsgExt( $error, 'parseinline' ) );
break;
- case UploadFromBase::UPLOAD_WARNING:
- $warning = $details['warning'];
- $this->uploadWarning( $warning );
+ case UploadBase::UPLOAD_WARNING:
+ unset( $details['status'] );
+ $this->uploadWarning( $details );
break;
- case UploadFromBase::INTERNAL_ERROR:
+ case UploadBase::INTERNAL_ERROR:
$status = $details['internal'];
$this->showError( $wgOut->parse( $status->getWikiText() ) );
break;
default:
- throw new MWException( __METHOD__ . ": Unknown value `{$value}`" );
- }
+ throw new MWException( __METHOD__ . ": Unknown value `{$details['status']}`" );
+ }
}
/**
*
* @access private
*/
- function internalProcessUpload( &$resultDetails ) {
+ function internalProcessUpload() {
global $wgUser;
if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
{
- wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file." );
- return UploadFromBase::BEFORE_PROCESSING;
- }
-
- $nt = $this->mUpload->getTitle();
- // Hold back returning errors for a bit so that verifyUpload can fill in the details
- if ( $nt instanceof Title ) {
- /**
- * If the image is protected, non-sysop users won't be able
- * to modify it by uploading a new revision.
- */
- $permErrors = $this->mUpload->verifyPermissions( $wgUser );
- if( $permErrors !== true ) {
- $resultDetails = array( 'permissionserrors' => $permErrors );
- return UploadFromBase::PROTECTED_PAGE;
- }
+ wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
+ return array( 'status' => UploadBase::BEFORE_PROCESSING );
+ }
+
+ /**
+ * If the image is protected, non-sysop users won't be able
+ * to modify it by uploading a new revision.
+ */
+ $permErrors = $this->mUpload->verifyPermissions( $wgUser );
+ if( $permErrors !== true ) {
+ return array( 'status' => UploadBase::PROTECTED_PAGE, 'permissionserrors' => $permErrors );
+ }
+
+ // Fetch the file if required
+ $status = $this->mUpload->fetchFile();
+ if( !$status->isOK() ){
+ return array( 'status' =>UploadBase::BEFORE_PROCESSING, 'error'=>$status->getWikiText() );
}
// Check whether this is a sane upload
- $result = $this->mUpload->verifyUpload( $resultDetails );
- if( $result != UploadFromBase::OK )
+ $result = $this->mUpload->verifyUpload();
+ if( $result != UploadBase::OK )
return $result;
$this->mLocalFile = $this->mUpload->getLocalFile();
if( !$this->mIgnoreWarning ) {
$warnings = $this->mUpload->checkWarnings();
-
+
if( count( $warnings ) ) {
- $resultDetails = array( 'warning' => $warnings );
- return UploadFromBase::UPLOAD_WARNING;
+ $warnings['status'] = UploadBase::UPLOAD_WARNING;
+ return $warnings;
}
}
* Try actually saving the thing...
* It will show an error form on failure. No it will not.
*/
- $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
- $this->mCopyrightStatus, $this->mCopyrightSource );
-
+ if( !$this->mForReUpload ) {
+ $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
+ $this->mCopyrightStatus, $this->mCopyrightSource );
+ } else {
+ $pageText = false;
+ }
$status = $this->mUpload->performUpload( $this->mComment, $pageText, $this->mWatchthis, $wgUser );
if ( !$status->isGood() ) {
- $resultDetails = array( 'internal' => $status );
- return UploadFromBase::INTERNAL_ERROR;
+ return array( 'status' => UploadBase::INTERNAL_ERROR, 'internal' => $status );
} else {
// Success, redirect to description page
- // WTF WTF WTF?
- $img = null; // @todo: added to avoid passing a ref to null - should this be defined somewhere?
wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
- return UploadFromBase::SUCCESS;
+ return UploadBase::SUCCESS;
}
}
*/
static function getExistsWarning( $exists ) {
global $wgUser, $wgContLang;
-
+ // Check for uppercase extension. We allow these filenames but check if an image
+ // with lowercase extension exists already
+ $warning = '';
+ $align = $wgContLang->isRtl() ? 'left' : 'right';
+
if( $exists === false )
return '';
-
+
$warning = '';
$align = $wgContLang->isRtl() ? 'left' : 'right';
if( $existsType == 'exists' ) {
// Exact match
- $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
+ $dlink = $sk->linkKnown( $file->getTitle() );
if ( $file->allowInlineDisplay() ) {
$dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
$file->getName(), $align, array(), false, true );
$warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
} elseif( $existsType == 'page-exists' ) {
- $lnk = $sk->makeKnownLinkObj( $file->getTitle(), '', 'redirect=no' );
+ $lnk = $sk->linkKnown( $file->getTitle(), '', '',array('redirect'=>'no') );
$warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
} elseif ( $existsType == 'exists-normalized' ) {
# Check if image with lowercase extension exists.
# It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
- $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
- if ( $file->allowInlineDisplay() ) {
- $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
- $file->getTitle()->getText(), $align, array(), false, true );
- } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
- $icon = $file->iconThumb();
+ $dlink = $sk->linkKnown( $nt_lc );
+ if ( $file_lc->allowInlineDisplay() ) {
+ // FIXME: replace deprecated makeImageLinkObj by link()
+ $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline' ),
+ $nt_lc->getText(), $align, array(), false, true );
+ } elseif ( !$file_lc->allowInlineDisplay() && $file_lc->isSafeFile() ) {
+ $icon = $file_lc->iconThumb();
$dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
$icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
} else {
$file->getTitle()->getPrefixedText(), $dlink ) .
'</li>' . $dlink2;
- } elseif ( $existsType == 'thumb' ) {
- # Check if an image without leading '180px-' (or similiar) exists
- $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
- if ( $file->allowInlineDisplay() ) {
- $dlink2 = $sk->makeImageLinkObj( $file->getTitle(),
- wfMsgExt( 'fileexists-thumb', 'parseinline' ),
- $file->getTitle()->getText(), $align, array(), false, true );
- } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
- $icon = $file->iconThumb();
- $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
- $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
- $dlink . '</div>';
+ } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' )
+ && preg_match( "/[0-9]{2}/" , substr( $partname , 0, 2 ) ) )
+ {
+ # Check for filenames like 50px- or 180px-, these are mostly thumbnails
+ $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $rawExtension );
+ $file_thb = wfLocalFile( $nt_thb );
+ if ($file_thb->exists() ) {
+ # Check if an image without leading '180px-' (or similiar) exists
+ $dlink = $sk->linkKnown( $nt_thb );
+ if ( $file_thb->allowInlineDisplay() ) {
+ // FIXME: replace deprecated makeImageLinkObj by link()
+ $dlink2 = $sk->makeImageLinkObj( $nt_thb,
+ wfMsgExt( 'fileexists-thumb', 'parseinline' ),
+ $nt_thb->getText(), $align, array(), false, true );
+ } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) {
+ $icon = $file_thb->iconThumb();
+ $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
+ $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
+ $dlink . '</div>';
+ } else {
+ $dlink2 = '';
+ }
+
+ $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
+ '</li>' . $dlink2;
} else {
- $dlink2 = '';
+ # Image w/o '180px-' does not exists, but we do not like these filenames
+ $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' ,
+ substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>';
}
- $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
- '</li>' . $dlink2;
+ }
+
+ $filenamePrefixBlacklist = UploadBase::getFilenamePrefixBlacklist();
+ # Do the match
+ if(!isset($partname))
+ $partname = '';
+ foreach( $filenamePrefixBlacklist as $prefix ) {
+ if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
+ $warning .= '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $prefix ) . '</li>';
+ break;
+ }
+ }
+
+ if ( $file->wasDeleted() && !$file->exists() ) {
+ # If the file existed before and was deleted, warn the user of this
+ # Don't bother doing so if the file exists now, however
+ $ltitle = SpecialPage::getTitleFor( 'Log' );
+ $llink = $sk->linkKnown(
+ $ltitle,
+ wfMsgHtml( 'deletionlog' ),
+ array(),
+ array(
+ 'type' => 'delete',
+ 'page' => $file->getTitle()->getPrefixedText()
+ )
+ );
+ $warning .= '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
}
return $warning;
}
-
+
/**
* Get a list of warnings
*
}
$s = ' ';
if ( $file ) {
- $exists = UploadFromBase::getExistsWarning( $file );
+ $exists = UploadBase::getExistsWarning( $file );
$warning = self::getExistsWarning( $exists );
// FIXME: We probably also want the prefix blacklist and the wasdeleted check here
if ( $warning !== '' ) {
public static function ajaxGetLicensePreview( $license ) {
global $wgParser, $wgUser;
$text = '{{' . $license . '}}';
- $title = Title::makeTitle( NS_IMAGE, 'Sample.jpg' );
+ $title = Title::makeTitle( NS_FILE, 'Sample.jpg' );
$options = ParserOptions::newFromUser( $wgUser );
// Expand subst: first, then live templates...
return $output->getText();
}
-
+
/**
- * Check for duplicate files and throw up a warning before the upload
- * completes.
+ * Construct the human readable warning message from an array of duplicate files
*/
public static function getDupeWarning( $dupes ) {
if( $dupes ) {
}
}
+
/**
* Remove a temporarily kept file stashed by saveTempUploadedFile().
* @access private
}
}
- /* -------------------------------------------------------------- */
+ /* Interface code starts below this line *
+ * -------------------------------------------------------------- */
+
/**
* @param string $error as HTML
* @access private
*/
function uploadWarning( $warnings ) {
- global $wgOut;
+ global $wgOut, $wgUser;
global $wgUseCopyrightUpload;
$this->mSessionKey = $this->mUpload->stashSession();
- if( !$this->mSessionKey ) {
+
+ if( $this->mSessionKey === false ) {
# Couldn't save file; an error has been displayed so let's go.
return;
}
+ $sk = $wgUser->getSkin();
+
$wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
$wgOut->addHTML( '<ul class="warning">' );
foreach( $warnings as $warning => $args ) {
$msg = null;
if( $warning == 'exists' ) {
- if ( !$this->mDestWarningAck )
+
+ //we should not have produced this warning if the user already acknowledged the destination warning
+ //at any rate I don't see why we should hid this warning if mDestWarningAck has been checked
+ //(it produces an empty warning page when no other warnings are fired)
+ //if ( !$this->mDestWarningAck )
$msg = self::getExistsWarning( $args );
+
} elseif( $warning == 'duplicate' ) {
$msg = $this->getDupeWarning( $args );
+ } elseif( $warning == 'duplicate-archive' ) {
+ $titleText = Title::makeTitle( NS_FILE, $args )->getPrefixedText();
+ $msg = Xml::tags( 'li', null, wfMsgExt( 'file-deleted-duplicate', array( 'parseinline' ), array( $titleText ) ) );
} elseif( $warning == 'filewasdeleted' ) {
$ltitle = SpecialPage::getTitleFor( 'Log' );
$llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ),
- 'type=delete&page=' . $file->getTitle()->getPrefixedUrl() );
+ 'type=delete&page=' . $args->getPrefixedUrl() );
$msg = "\t<li>" . wfMsgWikiHtml( 'filewasdeleted', $llink ) . "</li>\n";
} else {
if( is_bool( $args ) )
$args = array();
- elseif( !is_array( $args ) )
+ elseif( !is_array( $args ) )
$args = array( $args );
$msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
}
if( $msg )
$wgOut->addHTML( $msg );
}
-
+
$titleObj = SpecialPage::getTitleFor( 'Upload' );
if ( $wgUseCopyrightUpload ) {
} else {
$copyright = '';
}
-
$wgOut->addHTML(
Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
+ Xml::hidden('wpEditToken', $wgUser->editToken()) .
Xml::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
+ Xml::hidden( 'wpSourceType', 'stash' ) . "\n" .
Xml::hidden( 'wpSessionKey', $this->mSessionKey ) . "\n" .
Xml::hidden( 'wpUploadDescription', $this->mComment ) . "\n" .
Xml::hidden( 'wpLicense', $this->mLicense ) . "\n" .
* @access private
*/
function mainUploadForm( $msg='' ) {
- global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize;
+ global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize, $wgEnableFirefogg;
global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
- global $wgRequest, $wgAllowCopyUploads;
+ global $wgRequest;
global $wgStylePath, $wgStyleVersion;
+ global $wgEnableJS2system;
$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
$useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
$adc = wfBoolToStr( $useAjaxDestCheck );
$alp = wfBoolToStr( $useAjaxLicensePreview );
+ $uef = wfBoolToStr( $wgEnableFirefogg );
$autofill = wfBoolToStr( $this->mDesiredDestName == '' );
+
$wgOut->addScript( "<script type=\"text/javascript\">
wgAjaxUploadDestCheck = {$adc};
wgAjaxLicensePreview = {$alp};
+wgEnableFirefogg = {$uef};
wgUploadAutoFill = {$autofill};
</script>" );
- $wgOut->addScriptFile( 'upload.js' );
- $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
+
+ if( $wgEnableJS2system ){
+ //js2version of upload page:
+ $wgOut->addScriptClass( 'uploadPage' );
+ }else{
+ //legacy upload code:
+ $wgOut->addScriptFile( 'upload.js' );
+ $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
+ }
if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
{
return false;
}
- if( $this->mDesiredDestName ) {
- $title = Title::makeTitleSafe( NS_IMAGE, $this->mDesiredDestName );
+ if( $this->mDesiredDestName != '' ) {
+ $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()->makeKnownLinkObj(
+ $wgUser->getSkin()->linkKnown(
SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
)
);
- $wgOut->addHtml( "<div id=\"contentSub2\">{$link}</div>" );
+ $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
}
// Show the relevant lines from deletion log (for still deleted files only)
- if( $title instanceof Title && $title->isDeleted() > 0 && !$title->exists() ) {
+ if( $title instanceof Title && $title->isDeletedQuick() && !$title->exists() ) {
$this->showDeletionLog( $wgOut, $title->getPrefixedText() );
}
}
$wgOut->addHTML( "<h2>{$sub}</h2>\n" .
"<span class='error'>{$msg}</span>\n" );
}
+
$wgOut->addHTML( '<div id="uploadtext">' );
$wgOut->addWikiMsg( 'uploadtext', $this->mDesiredDestName );
$wgOut->addHTML( "</div>\n" );
$allowedExtensions = '';
if( $wgCheckFileExtensions ) {
- $delim = wfMsgExt( 'comma-separator', array( 'escapenoentities' ) );
if( $wgStrictFileExtensions ) {
# Everything not permitted is banned
$extensionsList =
'<div id="mw-upload-permitted">' .
- wfMsgWikiHtml( 'upload-permitted', implode( $wgFileExtensions, $delim ) ) .
+ wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
"</div>\n";
} else {
# We have to list both preferred and prohibited
$extensionsList =
'<div id="mw-upload-preferred">' .
- wfMsgWikiHtml( 'upload-preferred', implode( $wgFileExtensions, $delim ) ) .
+ wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
"</div>\n" .
'<div id="mw-upload-prohibited">' .
- wfMsgWikiHtml( 'upload-prohibited', implode( $wgFileBlacklist, $delim ) ) .
+ wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileExtensions ) ) .
"</div>\n";
}
} else {
default:
$val2 = $val;
}
- $val2 = $wgAllowCopyUploads ? min( $wgMaxUploadSize, $val2 ) : $val2;
- $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
- wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
+ $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
+ wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
$wgLang->formatSize( $val2 ) ) .
"</div>\n";
+ //add a hidden filed for upload by url (uses the $wgMaxUploadSize var)
+ if( UploadFromUrl::isEnabled() ){
+ $maxUploadSize.='<div id="mw-upload-maxfilesize-url" style="display:none">' .
+ wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
+ $wgLang->formatSize( $wgMaxUploadSize ) ) .
+ "</div>\n";
+ }
$sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
- $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
-
- $summary = wfMsgExt( 'fileuploadsummary', 'parseinline' );
+ $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
+
+ $msg = ( $this->mForReUpload ) ? 'filereuploadsummary' : 'fileuploadsummary';
+ $summary = wfMsgExt( $msg, 'parseinline' );
$licenses = new Licenses();
$license = wfMsgExt( 'license', array( 'parseinline' ) );
$encDestName = htmlspecialchars( $this->mDesiredDestName );
- $watchChecked = $this->watchCheck()
- ? 'checked="checked"'
- : '';
- $warningChecked = $this->mIgnoreWarning ? 'checked' : '';
+ $watchChecked = $this->watchCheck() ? 'checked="checked"' : '';
+ # Re-uploads should not need "file exist already" warnings
+ $warningChecked = ($this->mIgnoreWarning || $this->mForReUpload) ? 'checked="checked"' : '';
// Prepare form for upload or upload/copy
- if( $wgAllowCopyUploads && $wgUser->isAllowed( 'upload_by_url' ) ) {
- $filename_form =
+ //javascript moved from inline calls to setup:
+ if( UploadFromUrl::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
+ if($wgEnableJS2system){
+ $filename_form =
+ Xml::input( 'wpSourceType', false, 'file', array( 'id'=>'wpSourceTypeFile', 'type' => 'radio', 'checked' => 'checked' ) ) .
+ Xml::input( 'wpUploadFile', 60, false, array( 'id'=>'wpUploadFile', 'type'=>'file', 'tabindex' => '1' ) ) .
+ wfMsgHTML( 'upload_source_file' ) . "<br/>" .
+ Xml::input( 'wpSourceType', false, 'Url', array( 'id'=>'wpSourceTypeURL', 'type' => 'radio' )) .
+ Xml::input( 'wpUploadFileURL', 60, false, array( 'id'=>'wpUploadFileURL', 'type' => 'text', 'tabindex' => '1')) .
+ wfMsgHtml( 'upload_source_url' ) ;
+ }else{
+ //@@todo depreciate (not needed once $wgEnableJS2system is turned on)
+ $filename_form =
"<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " .
"onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
"<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
- "onfocus='" .
+ " onfocus='" .
"toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
"toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
"onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
"toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
"onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' disabled='disabled' />" .
wfMsgHtml( 'upload_source_url' ) ;
+
+ }
} else {
- $filename_form =
- "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
- ($this->mDesiredDestName?"":"onchange='fillDestFilename(\"wpUploadFile\")' ") .
- "size='60' />" .
+ if($wgEnableJS2system){
+ $filename_form =
+ Xml::input( 'wpUploadFile', 60, false, array( 'id'=>'wpUploadFile', 'type'=>'file', 'tabindex' => '1' ) ) .
+ Xml::hidden( 'wpSourceType', 'file');
+ }else{
+ $filename_form =
+ "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' ".
+ "onchange='fillDestFilename(\"wpUploadFile\")' />" .
"<input type='hidden' name='wpSourceType' value='file' />" ;
+ }
}
- if ( $useAjaxDestCheck ) {
+ $warningRow = '';
+ $destOnkeyup = '';
+ if($wgEnableJS2system){
$warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
- $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
- } else {
- $warningRow = '';
- $destOnkeyup = '';
+ }else{
+ if ( $useAjaxDestCheck ) {
+ $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
+ $destOnkeyup = 'onchange=\'wgUploadWarningObj.checkNow(this.value);\'';
+ }
}
+ # Uploading a new version? If so, the name is fixed.
+ $on = $this->mForReUpload ? "readonly='readonly'" : "";
$encComment = htmlspecialchars( $this->mComment );
+ //add the wpEditToken
$wgOut->addHTML(
- Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL(),
+ Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
+ Xml::hidden('wpEditToken', $wgUser->editToken()) .
Xml::openElement( 'fieldset' ) .
Xml::element( 'legend', null, wfMsg( 'upload' ) ) .
Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
"<tr>
- {$this->uploadFormTextTop}
+ {$this->uploadFormTextTop}
<td class='mw-label'>
<label for='wpUploadFile'>{$sourcefilename}</label>
</td>
<td class='mw-label'>
<label for='wpDestFile'>{$destfilename}</label>
</td>
- <td class='mw-input'>
- <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
- value=\"{$encDestName}\" onchange='toggleFilenameFiller()' $destOnkeyup />
- </td>
+ <td class='mw-input'>"
+ );
+ if( $this->mForReUpload ) {
+ $wgOut->addHTML(
+ Xml::hidden( 'wpDestFile', $this->mDesiredDestName, array('id'=>'wpDestFile','tabindex'=>2) ) .
+ "<tt>" .
+ $encDestName .
+ "</tt>"
+ );
+ }
+ else {
+ $wgOut->addHTML(
+ "<input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
+ value=\"{$encDestName}\" $destOnkeyup />"
+ );
+ }
+
+
+ $wgOut->addHTML(
+ "</td>
</tr>
<tr>
<td class='mw-label'>
<tr>"
);
- if ( $licenseshtml != '' ) {
+ # Re-uploads should not need license info
+ if ( !$this->mForReUpload && $licenseshtml != '' ) {
global $wgStylePath;
$wgOut->addHTML( "
<td class='mw-label'>
<tr>"
);
if( $useAjaxLicensePreview ) {
- $wgOut->addHtml( "
+ $wgOut->addHTML( "
<td></td>
<td id=\"mw-license-preview\"></td>
</tr>
}
}
- if ( $wgUseCopyrightUpload ) {
+ if ( !$this->mForReUpload && $wgUseCopyrightUpload ) {
$filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
$copystatus = htmlspecialchars( $this->mCopyrightStatus );
$filesource = wfMsgExt( 'filesource', 'escapenoentities' );
);
}
- $wgOut->addHtml( "
+ $wgOut->addHTML( "
<td></td>
<td>
<input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
<label for='wpWatchthis'>" . wfMsgHtml( 'watchthisupload' ) . "</label>
- <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked/>
+ <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked />
<label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
</td>
</tr>
<tr>
<td></td>
<td class='mw-input'>
- <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" . $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
+ <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" .
+ $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
</td>
</tr>
<tr>
<td></td>
<td class='mw-input'>"
);
- $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
+ $wgOut->addHTML( '<div class="mw-editTools">' );
+ $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
+ $wgOut->addHTML( '</div>' );
$wgOut->addHTML( "
</td>
</tr>" .
Xml::closeElement( 'table' ) .
Xml::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
+ Xml::hidden( 'wpForReUpload', $this->mForReUpload, array( 'id' => 'wpForReUpload' ) ) .
Xml::closeElement( 'fieldset' ) .
Xml::closeElement( 'form' )
);
}
/* -------------------------------------------------------------- */
-
+
/**
* See if we should check the 'watch this page' checkbox on the form
* based on the user's preferences and whether we're being asked
// Watch all edits!
return true;
}
-
+
$local = wfLocalFile( $this->mDesiredDestName );
if( $local && $local->exists() ) {
// We're uploading a new version of an existing file.
* @param User $user
* @param string $img, image name
* @return bool
- * @deprecated Use UploadFromBase::userCanReUpload
+ * @deprecated Use UploadBase::userCanReUpload
*/
public static function userCanReUpload( User $user, $img ) {
wfDeprecated( __METHOD__ );
-
+
if( $user->isAllowed( 'reupload' ) )
return true; // non-conditional
if( !$user->isAllowed( 'reupload-own' ) )
/**
* Get the initial image page text based on a comment and optional file status information
*/
- static function getInitialPageText( $comment, $license, $copyStatus, $source ) {
+ static function getInitialPageText( $comment='', $license='', $copyStatus='', $source='' ) {
global $wgUseCopyrightUpload;
if ( $wgUseCopyrightUpload ) {
+ $licensetxt = '';
if ( $license != '' ) {
$licensetxt = '== ' . wfMsgForContent( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
}
- $pageText = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n" .
+ $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
'== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
"$licensetxt" .
'== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
} else {
if ( $license != '' ) {
- $filedesc = $comment == '' ? '' : '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n";
+ $filedesc = $comment == '' ? '' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
$pageText = $filedesc .
'== ' . wfMsgForContent ( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
} else {
$loglist = new LogEventsList( $wgUser->getSkin(), $out );
$pager = new LogPager( $loglist, 'delete', false, $filename );
if( $pager->getNumRows() > 0 ) {
- $out->addHtml( '<div id="mw-upload-deleted-warn">' );
+ $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
$out->addWikiMsg( 'upload-wasdeleted' );
$out->addHTML(
$loglist->beginLogEventsList() .
$pager->getBody() .
$loglist->endLogEventsList()
);
- $out->addHtml( '</div>' );
+ $out->addHTML( '</div>' );
}
}
}