* @ingroup SpecialPage
*/
-
-/**
- * Entry point
- */
-function wfSpecialUpload() {
- global $wgRequest;
- $form = new UploadForm( $wgRequest );
- $form->execute();
-}
-
/**
* implements Special:Upload
* @ingroup SpecialPage
var $mDestWarningAck;
var $mLocalFile;
- var $mUpload; // Instance of UploadBase 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 $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 $wgUser;
+ 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->mForReUpload = $request->getBool( 'wpForReUpload' ); // updating a file
$this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' );
$this->mComment = $request->getText( 'wpUploadDescription' );
$this->mSourceType = $request->getText( 'wpSourceType' );
$this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' );
- $this->mForReUpload = $request->getBool( 'wpForReUpload' );
- $this->mReUpload = $request->getCheck( 'wpReUpload' );
+ $this->mReUpload = $request->getCheck( 'wpReUpload' ); // retrying upload
$this->mAction = $request->getVal( 'action' );
- $this->mUpload = UploadBase::createFromRequest( $request );
+ $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;
+ function execute( $par ) {
+ global $wgUser, $wgOut, $wgRequest;
+
+ $this->setHeaders();
+ $this->outputHeader();
+
+ $this->initForm();
+
# Check uploading enabled
if( !UploadBase::isEnabled() ) {
$wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
return;
}
+
# Check permissions
- if( $this->mUpload ) {
- $permission = $this->mUpload->isAllowed( $wgUser );
- } else {
- $permission = $wgUser->isAllowed( 'upload' ) ? true : 'upload';
- }
- if( $permission !== true ) {
- if( !$wgUser->isLoggedIn() ) {
+ global $wgGroupPermissions;
+ if( !$wgUser->isAllowed( 'upload' ) ) {
+ 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( $permission );
+ $wgOut->permissionRequired( 'upload' );
}
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 ;
+ 'submit' == $this->mAction || $this->mUploadClicked ) ) )
+ {
+ $this->mainUploadForm ( wfMsg( 'session_fail_preview' ) );
+ return ;
}
- if( $this->mReUpload ) {
+ if( $this->mReUpload && $this->mUpload) {
// User choose to cancel upload
if( !$this->mUpload->unsaveUploadedFile() ) {
return;
*
* 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)
+ * (the special upload page is not the only response point that needs clean localized error msgs)
*
* @access private
*/
- function processUpload(){
+ function processUpload() {
global $wgOut, $wgFileExtensions, $wgLang;
- $details = $this->internalProcessUpload();
- switch( $details['status'] ) {
+ $details = $this->internalProcessUpload();
+ switch( $details['status'] ) {
case UploadBase::SUCCESS:
$wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
break;
case UploadBase::VERIFICATION_ERROR:
unset( $details['status'] );
- $code = array_shift( $details );
- $this->uploadError( wfMsgExt( $code, 'parseinline', $details ) );
+ $code = array_shift( $details['details'] );
+ $this->uploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
break;
case UploadBase::UPLOAD_VERIFICATION_ERROR:
default:
throw new MWException( __METHOD__ . ": Unknown value `{$details['status']}`" );
- }
+ }
}
/**
// Fetch the file if required
$status = $this->mUpload->fetchFile();
- if( !$status->isOK() ){
- return array( 'status' =>UploadBase::BEFORE_PROCESSING, 'error'=>$status->getWikiText() );
+ if( !$status->isOK() ) {
+ return array( 'status' => UploadBase::BEFORE_PROCESSING, 'error'=> $status->getWikiText() );
}
// Check whether this is a sane upload
$result = $this->mUpload->verifyUpload();
- if( $result != UploadBase::OK )
+ if( $result['status'] != UploadBase::OK )
return $result;
$this->mLocalFile = $this->mUpload->getLocalFile();
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 );
*/
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
if( $exists === false )
return '';
$warning = '';
- $align = $wgContLang->isRtl() ? 'left' : 'right';
+ $align = $wgContLang->alignEnd();
list( $existsType, $file ) = $exists;
+ if( strpos( $file->getName(), '.' ) == false ) {
+ $partname = $file->getName();
+ $rawExtension = '';
+ } else {
+ $n = strrpos( $file->getName(), '.' );
+ $rawExtension = substr( $file->getName(), $n + 1 );
+ $partname = substr( $file->getName(), 0, $n );
+ }
+
$sk = $wgUser->getSkin();
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.
$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>';
$this->mSessionKey = $this->mUpload->stashSession();
- if( $sessionData === false ) {
+ if( $this->mSessionKey === false ) {
# Couldn't save file; an error has been displayed so let's go.
return;
}
} else {
$copyright = '';
}
- //add the wpEditToken
- $token = htmlspecialchars( $wgUser->editToken() );
- $tokenInput = "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n";
-
$wgOut->addHTML(
Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
- $tokenInput .
+ Xml::hidden('wpEditToken', $wgUser->editToken(), array("id" => 'wpEditToken')) .
Xml::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
Xml::hidden( 'wpSourceType', 'stash' ) . "\n" .
Xml::hidden( 'wpSessionKey', $this->mSessionKey ) . "\n" .
wgUploadAutoFill = {$autofill};
</script>" );
- if( $wgEnableJS2system ){
+ if( $wgEnableJS2system ) {
//js2version of upload page:
- $wgOut->addScriptClass( 'uploadPage' );
+ $wgOut->addScriptClass( 'uploadPage' );
}else{
//legacy upload code:
$wgOut->addScriptFile( 'upload.js' );
return false;
}
- if( $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 )
)
$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 {
# Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
# See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
- $val = trim( ini_get( 'upload_max_filesize' ) );
- $last = strtoupper( ( substr( $val, -1 ) ) );
- switch( $last ) {
- case 'G':
- $val2 = substr( $val, 0, -1 ) * 1024 * 1024 * 1024;
- break;
- case 'M':
- $val2 = substr( $val, 0, -1 ) * 1024 * 1024;
- break;
- case 'K':
- $val2 = substr( $val, 0, -1 ) * 1024;
- break;
- default:
- $val2 = $val;
- }
+ $val = wfShorthandToInteger( ini_get( 'upload_max_filesize' ) );
$maxUploadSize = '<div id="mw-upload-maxfilesize">' .
wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
- $wgLang->formatSize( $val2 ) ) .
+ $wgLang->formatSize( $val ) ) .
"</div>\n";
//add a hidden filed for upload by url (uses the $wgMaxUploadSize var)
- if( UploadFromUrl::isEnabled() ){
+ if( UploadFromUrl::isEnabled() ) {
$maxUploadSize.='<div id="mw-upload-maxfilesize-url" style="display:none">' .
wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
$wgLang->formatSize( $wgMaxUploadSize ) ) .
}
$sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
- $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
+ $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
- $msg = $this->mForReUpload ? 'filereuploadsummary' : 'fileuploadsummary';
+ $msg = ( $this->mForReUpload ) ? 'filereuploadsummary' : 'fileuploadsummary';
$summary = wfMsgExt( $msg, 'parseinline' );
$licenses = new Licenses();
// Prepare form for upload or upload/copy
//javascript moved from inline calls to setup:
if( UploadFromUrl::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
- if($wgEnableJS2system){
- $filename_form =
- "<input type='radio' id=\"wpSourceTypeFile\" name='wpSourceType' value='file' checked='checked' />" .
- "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' />" .
- wfMsgHTML( 'upload_source_file' ) . "<br/>" .
- "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='url' />" .
- "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' size='60' />" .
+ 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 (only support JS2system)
- $filename_form =
+ } else {
+ //@@todo deprecate (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' />" .
"onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' disabled='disabled' />" .
wfMsgHtml( 'upload_source_url' ) ;
- }
+ }
} else {
- $filename_form =
- "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' />" .
- "<input type='hidden' name='wpSourceType' value='upload' />" ;
+ 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 = '';
} else {
- $warningRow = '';
- $destOnkeyup = '';
+ 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
- $token = htmlspecialchars( $wgUser->editToken() );
- $tokenInput = "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n";
-
+ //add the wpEditToken
$wgOut->addHTML(
- Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
+ Xml::openElement( 'form',
+ array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
- $tokenInput .
- Xml::openElement( 'fieldset' ) .
- Xml::element( 'legend', null, wfMsg( 'upload' ) ) .
- Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
- "<tr>
- {$this->uploadFormTextTop}
+ Xml::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) .
+ Xml::openElement( 'fieldset' ) .
+ Xml::element( 'legend', null, wfMsg( 'upload' ) ) .
+ Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
+ "<tr>
+ {$this->uploadFormTextTop}
<td class='mw-label'>
<label for='wpUploadFile'>{$sourcefilename}</label>
</td>
}
}
- /**
+ /**
* Check if a user is the last uploader
*
* @param User $user
/**
* 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";
+ $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\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";
+ '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
} else {
$pageText = $comment;
}