global $wgAllowCopyUploads;
$this->mDesiredDestName = $request->getText( 'wpDestFile' );
$this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' );
+ $this->mComment = $request->getText( 'wpUploadDescription' );
if( !$request->wasPosted() ) {
- # GET requests just give the main form; no data except wpDestfile.
+ # GET requests just give the main form; no data except destination
+ # filename and description
return;
}
$this->mReUpload = $request->getCheck( 'wpReUpload' );
$this->mUploadClicked = $request->getCheck( 'wpUpload' );
- $this->mComment = $request->getText( 'wpUploadDescription' );
$this->mLicense = $request->getText( 'wpLicense' );
$this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' );
$this->mCopyrightSource = $request->getText( 'wpUploadSource' );
# Chop off any directories in the given filename
if( $this->mDesiredDestName ) {
- $basename = wfBaseName( $this->mDesiredDestName );
+ $basename = $this->mDesiredDestName;
} else {
- $basename = wfBaseName( $this->mSrcName );
+ $basename = $this->mSrcName;
}
+ $filtered = wfBaseName( $basename );
/**
* We'll want to blacklist against *any* 'extension', and use
* only the final one for the whitelist.
*/
- list( $partname, $ext ) = $this->splitExtensions( $basename );
+ list( $partname, $ext ) = $this->splitExtensions( $filtered );
if( count( $ext ) ) {
$finalExt = $ext[count( $ext ) - 1];
* Filter out illegal characters, and try to make a legible name
* out of it. We'll strip some silently that Title would die on.
*/
- $filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $basename );
+ $filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $filtered );
$nt = Title::makeTitleSafe( NS_IMAGE, $filtered );
if( is_null( $nt ) ) {
$this->uploadError( wfMsgWikiHtml( 'illegalfilename', htmlspecialchars( $filtered ) ) );
}
/**
- * Provide an opportunity for extensions to add futher checks
+ * Provide an opportunity for extensions to add further checks
*/
$error = '';
if( !wfRunHooks( 'UploadVerification',
if( $wgCapitalLinks ) {
$filtered = ucfirst( $filtered );
}
- if( $this->mDestName != $filtered ) {
+ if( $basename != $filtered ) {
$warning .= '<li>'.wfMsgHtml( 'badfilename', htmlspecialchars( $this->mDestName ) ).'</li>';
}
$status = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText,
File::DELETE_SOURCE, $this->mFileProps );
- if ( WikiError::isError( $status ) ) {
- $this->showError( $status );
+ if ( !$status->isGood() ) {
+ $this->showError( $status->getWikiText() );
} else {
if ( $this->mWatchthis ) {
global $wgUser;
}
return $s;
}
+
+ /**
+ * Render a preview of a given license for the AJAX preview on upload
+ *
+ * @param string $license
+ * @return string
+ */
+ public static function ajaxGetLicensePreview( $license ) {
+ global $wgParser, $wgUser;
+ $text = '{{' . $license . '}}';
+ $title = Title::makeTitle( NS_IMAGE, 'Sample.jpg' );
+ $options = ParserOptions::newFromUser( $wgUser );
+
+ // Expand subst: first, then live templates...
+ $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
+ $output = $wgParser->parse( $text, $title, $options );
+
+ return $output->getText();
+ }
/**
* Stash a file in a temporary directory for later processing
function saveTempUploadedFile( $saveName, $tempName ) {
global $wgOut;
$repo = RepoGroup::singleton()->getLocalRepo();
- $result = $repo->storeTemp( $saveName, $tempName );
- if ( WikiError::isError( $result ) ) {
- $this->showError( $result );
+ $status = $repo->storeTemp( $saveName, $tempName );
+ if ( !$status->isGood() ) {
+ $this->showError( $status->getWikiText() );
return false;
} else {
- return $result;
+ return $status->value;
}
}
* @access private
*/
function uploadWarning( $warning ) {
- global $wgOut;
+ global $wgOut, $wgContLang;
global $wgUseCopyrightUpload;
$this->mSessionKey = $this->stashSession();
$reup = wfMsgWikiHtml( 'reuploaddesc' );
$titleObj = SpecialPage::getTitleFor( 'Upload' );
$action = $titleObj->escapeLocalURL( 'action=submit' );
+ $align1 = $wgContLang->isRTL() ? 'left' : 'right';
+ $align2 = $wgContLang->isRTL() ? 'right' : 'left';
if ( $wgUseCopyrightUpload )
{
<table border='0'>
<tr>
<tr>
- <td align='right'>
+ <td align='$align1'>
<input tabindex='2' type='submit' name='wpUpload' value=\"$save\" />
</td>
- <td align='left'>$iw</td>
+ <td align='$align2'>$iw</td>
</tr>
<tr>
- <td align='right'>
+ <td align='$align1'>
<input tabindex='2' type='submit' name='wpReUpload' value=\"{$reupload}\" />
</td>
- <td align='left'>$reup</td>
+ <td align='$align2'>$reup</td>
</tr>
</tr>
</table></form>\n" );
* @access private
*/
function mainUploadForm( $msg='' ) {
- global $wgOut, $wgUser;
- global $wgUseCopyrightUpload, $wgAjaxUploadDestCheck, $wgUseAjax;
+ global $wgOut, $wgUser, $wgContLang;
+ global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
global $wgRequest, $wgAllowCopyUploads, $wgEnableAPI;
- global $wgStylePath;
+ global $wgStylePath, $wgStyleVersion;
- $useAjax = $wgAjaxUploadDestCheck && $wgUseAjax;
-
- $wgOut->addScript(
- "<script type='text/javascript'>wgAjaxUploadDestCheck = " .
- ($useAjax ? 'true' : 'false' ) . ";</script>\n" .
- "<script type='text/javascript' src=\"$wgStylePath/common/upload.js?1\"></script>\n"
- );
+ $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
+ $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
+
+ $adc = wfBoolToStr( $useAjaxDestCheck );
+ $alp = wfBoolToStr( $useAjaxLicensePreview );
+
+ $wgOut->addScript( "<script type=\"text/javascript\">
+wgAjaxUploadDestCheck = {$adc};
+wgAjaxLicensePreview = {$alp};
+</script>
+<script type=\"text/javascript\" src=\"{$wgStylePath}/common/upload.js?{$wgStyleVersion}\"></script>
+ " );
if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
{
"size='40' />" .
"<input type='hidden' name='wpSourceType' value='file' />" ;
}
- if ( $useAjax ) {
+ if ( $useAjaxDestCheck ) {
$warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
$destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
} else {
}
$encComment = htmlspecialchars( $this->mComment );
+ $align1 = $wgContLang->isRTL() ? 'left' : 'right';
+ $align2 = $wgContLang->isRTL() ? 'right' : 'left';
$wgOut->addHTML( <<<EOT
<form id='upload' method='post' enctype='multipart/form-data' action="$action">
<table border='0'>
<tr>
{$this->uploadFormTextTop}
- <td align='right' valign='top'><label for='wpUploadFile'>{$sourcefilename}:</label></td>
- <td align='left'>
+ <td align='$align1' valign='top'><label for='wpUploadFile'>{$sourcefilename}:</label></td>
+ <td align='$align2'>
{$filename_form}
</td>
</tr>
<tr>
- <td align='right'><label for='wpDestFile'>{$destfilename}:</label></td>
- <td align='left'>
+ <td align='$align1'><label for='wpDestFile'>{$destfilename}:</label></td>
+ <td align='$align2'>
<input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40'
value="$encDestName" $destOnkeyup />
</td>
</tr>
<tr>
- <td align='right'><label for='wpUploadDescription'>{$summary}</label></td>
- <td align='left'>
+ <td align='$align1'><label for='wpUploadDescription'>{$summary}</label></td>
+ <td align='$align2'>
<textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6'
cols='{$cols}'{$ew}>$encComment</textarea>
{$this->uploadFormTextAfterSummary}
if ( $licenseshtml != '' ) {
global $wgStylePath;
$wgOut->addHTML( "
- <td align='right'><label for='wpLicense'>$license:</label></td>
- <td align='left'>
+ <td align='$align1'><label for='wpLicense'>$license:</label></td>
+ <td align='$align2'>
<select name='wpLicense' id='wpLicense' tabindex='4'
onchange='licenseSelectorCheck()'>
<option value=''>$nolicense</option>
</select>
</td>
</tr>
- <tr>
- ");
+ <tr>" );
+ if( $useAjaxLicensePreview ) {
+ $wgOut->addHtml( "
+ <td></td>
+ <td id=\"mw-license-preview\"></td>
+ </tr>
+ <tr>" );
+ }
}
if ( $wgUseCopyrightUpload ) {
$uploadsource = htmlspecialchars( $this->mCopyrightSource );
$wgOut->addHTML( "
- <td align='right' nowrap='nowrap'><label for='wpUploadCopyStatus'>$filestatus:</label></td>
+ <td align='$align1' nowrap='nowrap'><label for='wpUploadCopyStatus'>$filestatus:</label></td>
<td><input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus'
value=\"$copystatus\" size='40' /></td>
</tr>
<tr>
- <td align='right'><label for='wpUploadCopyStatus'>$filesource:</label></td>
+ <td align='$align1'><label for='wpUploadCopyStatus'>$filesource:</label></td>
<td><input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus'
value=\"$uploadsource\" size='40' /></td>
</tr>
$warningRow
<tr>
<td></td>
- <td align='left'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
+ <td align='$align2'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
</tr>
<tr>
<td></td>
- <td align='left'>
+ <td align='$align2'>
" );
$wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
$wgOut->addHTML( "
global $wgVerifyMimeType;
if ($wgVerifyMimeType) {
+ wfDebug ( "\n\nmime: <$mime> extension: <$extension>\n\n");
#check mime type against file extension
if( !$this->verifyExtension( $mime, $extension ) ) {
return new WikiErrorMsg( 'uploadcorrupt' );
}
/**
- * Display an error from a wikitext-formatted WikiError object
+ * Display an error with a wikitext description
*/
- function showError( WikiError $error ) {
+ function showError( $description ) {
global $wgOut;
$wgOut->setPageTitle( wfMsg( "internalerror" ) );
$wgOut->setRobotpolicy( "noindex,nofollow" );
$wgOut->setArticleRelated( false );
$wgOut->enableClientCache( false );
- $wgOut->addWikiText( $error->getMessage() );
+ $wgOut->addWikiText( $description );
}
/**
}
}
+