summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialUpload.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
committerPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
commitca32f08966f1b51fcb19460f0996bb0c4048e6fe (patch)
treeec04cc15b867bc21eedca904cea9af0254531a11 /includes/specials/SpecialUpload.php
parenta22fbfc60f36f5f7ee10d5ae6fe347340c2ee67c (diff)
Update to MediaWiki 1.18.0
* also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing
Diffstat (limited to 'includes/specials/SpecialUpload.php')
-rw-r--r--includes/specials/SpecialUpload.php150
1 files changed, 98 insertions, 52 deletions
diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php
index 893e4be2..8eeca5d5 100644
--- a/includes/specials/SpecialUpload.php
+++ b/includes/specials/SpecialUpload.php
@@ -45,7 +45,15 @@ class SpecialUpload extends SpecialPage {
/** Misc variables **/
public $mRequest; // The WebRequest or FauxRequest this form is supposed to handle
public $mSourceType;
+
+ /**
+ * @var UploadBase
+ */
public $mUpload;
+
+ /**
+ * @var LocalFile
+ */
public $mLocalFile;
public $mUploadClicked;
@@ -71,6 +79,8 @@ class SpecialUpload extends SpecialPage {
public $uploadFormTextTop;
public $uploadFormTextAfterSummary;
+ public $mWatchthis;
+
/**
* Initialize instance variables from request and create an Upload handler
*
@@ -105,7 +115,7 @@ class SpecialUpload extends SpecialPage {
$this->mForReUpload = $request->getBool( 'wpForReUpload' ); // updating a file
$this->mCancelUpload = $request->getCheck( 'wpCancelUpload' )
- || $request->getCheck( 'wpReUpload' ); // b/w compat
+ || $request->getCheck( 'wpReUpload' ); // b/w compat
// If it was posted check for the token (no remote POST'ing with user credentials)
$token = $request->getVal( 'wpEditToken' );
@@ -130,7 +140,7 @@ class SpecialUpload extends SpecialPage {
* @param $user User object
* @return Boolean
*/
- public function userCanExecute( $user ) {
+ public function userCanExecute( User $user ) {
return UploadBase::isEnabled() && parent::userCanExecute( $user );
}
@@ -196,7 +206,7 @@ class SpecialUpload extends SpecialPage {
wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
return;
}
-
+
$this->showUploadForm( $this->getUploadForm() );
}
@@ -214,7 +224,7 @@ class SpecialUpload extends SpecialPage {
*/
protected function showUploadForm( $form ) {
# Add links if file was previously deleted
- if ( !$this->mDesiredDestName ) {
+ if ( $this->mDesiredDestName ) {
$this->showViewDeletedLinks();
}
@@ -267,7 +277,7 @@ class SpecialUpload extends SpecialPage {
$desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
$delNotice = ''; // empty by default
if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) {
- LogEventsList::showLogExtract( $delNotice, array( 'delete', 'move' ),
+ LogEventsList::showLogExtract( $delNotice, array( 'delete', 'move' ),
$desiredTitleObj->getPrefixedText(),
'', array( 'lim' => 10,
'conds' => array( "log_action != 'revision'" ),
@@ -278,17 +288,17 @@ class SpecialUpload extends SpecialPage {
$form->addPreText( $delNotice );
# Add text to form
- $form->addPreText( '<div id="uploadtext">' .
- wfMsgExt( 'uploadtext', 'parse', array( $this->mDesiredDestName ) ) .
+ $form->addPreText( '<div id="uploadtext">' .
+ wfMsgExt( 'uploadtext', 'parse', array( $this->mDesiredDestName ) ) .
'</div>' );
# Add upload error message
$form->addPreText( $message );
# Add footer to form
- $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
- if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) {
+ $uploadFooter = wfMessage( 'uploadfooter' );
+ if ( !$uploadFooter->isDisabled() ) {
$form->addPostText( '<div id="mw-upload-footer-message">'
- . $wgOut->parse( $uploadFooter ) . "</div>\n" );
+ . $wgOut->parse( $uploadFooter->plain() ) . "</div>\n" );
}
return $form;
@@ -309,7 +319,7 @@ class SpecialUpload extends SpecialPage {
$link = wfMsgExt(
$wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted',
array( 'parse', 'replaceafter' ),
- $wgUser->getSkin()->linkKnown(
+ $this->getSkin()->linkKnown(
SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
)
@@ -317,11 +327,6 @@ class SpecialUpload extends SpecialPage {
$wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
}
}
-
- // Show the relevant lines from deletion log (for still deleted files only)
- if( $title instanceof Title && $title->isDeletedQuick() && !$title->exists() ) {
- $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
- }
}
/**
@@ -337,7 +342,7 @@ class SpecialUpload extends SpecialPage {
*/
protected function showRecoverableUploadError( $message ) {
$sessionKey = $this->mUpload->stashSession();
- $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
+ $message = '<h2>' . wfMsgHtml( 'uploaderror' ) . "</h2>\n" .
'<div class="error">' . $message . "</div>\n";
$form = $this->getUploadForm( $message, $sessionKey );
@@ -357,8 +362,8 @@ class SpecialUpload extends SpecialPage {
# mDestWarningAck is set when some javascript has shown the warning
# to the user. mForReUpload is set when the user clicks the "upload a
# new version" link.
- if ( !$warnings || ( count( $warnings ) == 1 &&
- isset( $warnings['exists'] ) &&
+ if ( !$warnings || ( count( $warnings ) == 1 &&
+ isset( $warnings['exists'] ) &&
( $this->mDestWarningAck || $this->mForReUpload ) ) )
{
return false;
@@ -436,16 +441,15 @@ class SpecialUpload extends SpecialPage {
return;
}
-
// Upload verification
$details = $this->mUpload->verifyUpload();
if ( $details['status'] != UploadBase::OK ) {
$this->processVerificationError( $details );
return;
}
-
+
// Verify permissions for this title
- $permErrors = $this->mUpload->verifyPermissions( $wgUser );
+ $permErrors = $this->mUpload->verifyTitlePermissions( $wgUser );
if( $permErrors !== true ) {
$code = array_shift( $permErrors[0] );
$this->showRecoverableUploadError( wfMsgExt( $code,
@@ -574,6 +578,10 @@ class SpecialUpload extends SpecialPage {
$this->showRecoverableUploadError( wfMsgExt( 'filetype-missing',
'parseinline' ) );
break;
+ case UploadBase::WINDOWS_NONASCII_FILENAME:
+ $this->showRecoverableUploadError( wfMsgExt( 'windows-nonascii-filename',
+ 'parseinline' ) );
+ break;
/** Statuses that require reuploading **/
case UploadBase::EMPTY_FILE:
@@ -583,18 +591,25 @@ class SpecialUpload extends SpecialPage {
$this->showUploadError( wfMsgHtml( 'largefileserver' ) );
break;
case UploadBase::FILETYPE_BADTYPE:
- $finalExt = $details['finalExt'];
- $this->showUploadError(
- wfMsgExt( 'filetype-banned-type',
- array( 'parseinline' ),
- htmlspecialchars( $finalExt ),
- implode(
- wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
- $wgFileExtensions
- ),
- $wgLang->formatNum( count( $wgFileExtensions ) )
- )
- );
+ $msg = wfMessage( 'filetype-banned-type' );
+ if ( isset( $details['blacklistedExt'] ) ) {
+ $msg->params( $wgLang->commaList( $details['blacklistedExt'] ) );
+ } else {
+ $msg->params( $details['finalExt'] );
+ }
+ $msg->params( $wgLang->commaList( $wgFileExtensions ),
+ count( $wgFileExtensions ) );
+
+ // Add PLURAL support for the first parameter. This results
+ // in a bit unlogical parameter sequence, but does not break
+ // old translations
+ if ( isset( $details['blacklistedExt'] ) ) {
+ $msg->params( count( $details['blacklistedExt'] ) );
+ } else {
+ $msg->params( 1 );
+ }
+
+ $this->showUploadError( $msg->parse() );
break;
case UploadBase::VERIFICATION_ERROR:
unset( $details['status'] );
@@ -690,7 +705,7 @@ class SpecialUpload extends SpecialPage {
'page' => $filename
)
);
- $warning = wfMsgWikiHtml( 'filewasdeleted', $llink );
+ $warning = wfMsgExt( 'filewasdeleted', array( 'parse', 'replaceafter' ), $llink );
}
return $warning;
@@ -761,6 +776,8 @@ class UploadForm extends HTMLForm {
protected $mSourceIds;
+ protected $mMaxFileSize = array();
+
public function __construct( $options = array() ) {
$this->mWatch = !empty( $options['watch'] );
$this->mForReUpload = !empty( $options['forreupload'] );
@@ -777,7 +794,7 @@ class UploadForm extends HTMLForm {
? $options['texttop'] : '';
$this->mTextAfterSummary = isset( $options['textaftersummary'] )
- ? $options['textaftersummary'] : '';
+ ? $options['textaftersummary'] : '';
$sourceDescriptor = $this->getSourceSection();
$descriptor = $sourceDescriptor
@@ -812,7 +829,6 @@ class UploadForm extends HTMLForm {
*/
protected function getSourceSection() {
global $wgLang, $wgUser, $wgRequest;
- global $wgMaxUploadSize;
if ( $this->mSessionKey ) {
return array(
@@ -841,6 +857,14 @@ class UploadForm extends HTMLForm {
);
}
+ $this->mMaxUploadSize['file'] = UploadBase::getMaxUploadSize( 'file' );
+ # Limit to upload_max_filesize unless we are running under HipHop and
+ # that setting doesn't exist
+ if ( !wfIsHipHop() ) {
+ $this->mMaxUploadSize['file'] = min( $this->mMaxUploadSize['file'],
+ wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ) );
+ }
+
$descriptor['UploadFile'] = array(
'class' => 'UploadSourceField',
'section' => 'source',
@@ -851,17 +875,12 @@ class UploadForm extends HTMLForm {
'radio' => &$radio,
'help' => wfMsgExt( 'upload-maxfilesize',
array( 'parseinline', 'escapenoentities' ),
- $wgLang->formatSize(
- wfShorthandToInteger( min(
- wfShorthandToInteger(
- ini_get( 'upload_max_filesize' )
- ), $wgMaxUploadSize
- ) )
- )
+ $wgLang->formatSize( $this->mMaxUploadSize['file'] )
) . ' ' . wfMsgHtml( 'upload_source_file' ),
'checked' => $selectedSourceType == 'file',
);
if ( $canUploadByUrl ) {
+ $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize( 'url' );
$descriptor['UploadFileURL'] = array(
'class' => 'UploadSourceField',
'section' => 'source',
@@ -871,7 +890,7 @@ class UploadForm extends HTMLForm {
'radio' => &$radio,
'help' => wfMsgExt( 'upload-maxfilesize',
array( 'parseinline', 'escapenoentities' ),
- $wgLang->formatSize( $wgMaxUploadSize )
+ $wgLang->formatSize( $this->mMaxUploadSize['url'] )
) . ' ' . wfMsgHtml( 'upload_source_url' ),
'checked' => $selectedSourceType == 'url',
);
@@ -903,16 +922,16 @@ class UploadForm extends HTMLForm {
# Everything not permitted is banned
$extensionsList =
'<div id="mw-upload-permitted">' .
- wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
+ wfMsgExt( 'upload-permitted', 'parse', $wgLang->commaList( $wgFileExtensions ) ) .
"</div>\n";
} else {
# We have to list both preferred and prohibited
$extensionsList =
'<div id="mw-upload-preferred">' .
- wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
+ wfMsgExt( 'upload-preferred', 'parse', $wgLang->commaList( $wgFileExtensions ) ) .
"</div>\n" .
'<div id="mw-upload-prohibited">' .
- wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileBlacklist ) ) .
+ wfMsgExt( 'upload-prohibited', 'parse', $wgLang->commaList( $wgFileBlacklist ) ) .
"</div>\n";
}
} else {
@@ -931,6 +950,26 @@ class UploadForm extends HTMLForm {
protected function getDescriptionSection() {
global $wgUser;
+ if ( $this->mSessionKey ) {
+ $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
+ try {
+ $file = $stash->getFile( $this->mSessionKey );
+ } catch ( MWException $e ) {
+ $file = null;
+ }
+ if ( $file ) {
+ global $wgContLang;
+
+ $mto = $file->transform( array( 'width' => 120 ) );
+ $this->addHeaderText(
+ '<div class="thumb t' . $wgContLang->alignEnd() . '">' .
+ Html::element( 'img', array(
+ 'src' => $mto->getUrl(),
+ 'class' => 'thumbimage',
+ ) ) . '</div>', 'description' );
+ }
+ }
+
$descriptor = array(
'DestFile' => array(
'type' => 'text',
@@ -939,7 +978,7 @@ class UploadForm extends HTMLForm {
'label-message' => 'destfilename',
'size' => 60,
'default' => $this->mDestFile,
- # FIXME: hack to work around poor handling of the 'default' option in HTMLForm
+ # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
'nodata' => strval( $this->mDestFile ) !== '',
),
'UploadDescription' => array(
@@ -967,6 +1006,7 @@ class UploadForm extends HTMLForm {
'EditTools' => array(
'type' => 'edittools',
'section' => 'description',
+ 'message' => 'edittools-upload',
)
);
@@ -1035,7 +1075,7 @@ class UploadForm extends HTMLForm {
'id' => 'wpDestFileWarningAck',
'default' => $this->mDestWarningAck ? '1' : '',
);
-
+
if ( $this->mForReUpload ) {
$descriptor['ForReUpload'] = array(
'type' => 'hidden',
@@ -1064,6 +1104,7 @@ class UploadForm extends HTMLForm {
$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
$useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI;
+ $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
$scriptVars = array(
'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
@@ -1075,12 +1116,17 @@ class UploadForm extends HTMLForm {
'wgUploadSourceIds' => $this->mSourceIds,
'wgStrictFileExtensions' => $wgStrictFileExtensions,
'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
+ 'wgMaxUploadSize' => $this->mMaxUploadSize,
);
$wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
- // For <charinsert> support
- $wgOut->addModules( array( 'mediawiki.legacy.edit', 'mediawiki.legacy.upload' ) );
+
+ $wgOut->addModules( array(
+ 'mediawiki.action.edit', // For <charinsert> support
+ 'mediawiki.legacy.upload', // Old form stuff...
+ 'mediawiki.special.upload', // Newer extras for thumbnail preview.
+ ) );
}
/**