00001 <?php
00011 class SpecialUpload extends SpecialPage {
00017 public function __construct( $request = null ) {
00018 global $wgRequest;
00019
00020 parent::__construct( 'Upload', 'upload' );
00021
00022 $this->loadRequest( is_null( $request ) ? $wgRequest : $request );
00023 }
00024
00026 public $mRequest;
00027 public $mSourceType;
00028 public $mUpload;
00029 public $mLocalFile;
00030 public $mUploadClicked;
00031
00033 public $mDesiredDestName;
00034 public $mComment;
00035 public $mLicense;
00036
00038 public $mIgnoreWarning;
00039 public $mWatchThis;
00040 public $mCopyrightStatus;
00041 public $mCopyrightSource;
00042
00044 public $mDestWarningAck;
00045 public $mForReUpload;
00046 public $mCancelUpload;
00047 public $mTokenOk;
00048 public $mUploadSuccessful = false;
00049
00051 public $uploadFormTextTop;
00052 public $uploadFormTextAfterSummary;
00053
00054
00060 protected function loadRequest( $request ) {
00061 global $wgUser;
00062
00063 $this->mRequest = $request;
00064 $this->mSourceType = $request->getVal( 'wpSourceType', 'file' );
00065 $this->mUpload = UploadBase::createFromRequest( $request );
00066 $this->mUploadClicked = $request->wasPosted()
00067 && ( $request->getCheck( 'wpUpload' )
00068 || $request->getCheck( 'wpUploadIgnoreWarning' ) );
00069
00070
00071 $this->mDesiredDestName = $request->getText( 'wpDestFile' );
00072 if( !$this->mDesiredDestName && $request->getFileName( 'wpUploadFile' ) !== null )
00073 $this->mDesiredDestName = $request->getFileName( 'wpUploadFile' );
00074 $this->mComment = $request->getText( 'wpUploadDescription' );
00075 $this->mLicense = $request->getText( 'wpLicense' );
00076
00077
00078 $this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' );
00079 $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' )
00080 || $request->getCheck( 'wpUploadIgnoreWarning' );
00081 $this->mWatchthis = $request->getBool( 'wpWatchthis' ) && $wgUser->isLoggedIn();
00082 $this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' );
00083 $this->mCopyrightSource = $request->getText( 'wpUploadSource' );
00084
00085
00086 $this->mForReUpload = $request->getBool( 'wpForReUpload' );
00087 $this->mCancelUpload = $request->getCheck( 'wpCancelUpload' )
00088 || $request->getCheck( 'wpReUpload' );
00089
00090
00091 $token = $request->getVal( 'wpEditToken' );
00092 if( $this->mSourceType == 'file' && $token == null ) {
00093
00094
00095
00096 $this->mTokenOk = true;
00097 } else {
00098 $this->mTokenOk = $wgUser->matchEditToken( $token );
00099 }
00100
00101 $this->uploadFormTextTop = '';
00102 $this->uploadFormTextAfterSummary = '';
00103 }
00104
00113 public function userCanExecute( $user ) {
00114 return UploadBase::isEnabled() && parent::userCanExecute( $user );
00115 }
00116
00120 public function execute( $par ) {
00121 global $wgUser, $wgOut, $wgRequest;
00122
00123 $this->setHeaders();
00124 $this->outputHeader();
00125
00126 # Check uploading enabled
00127 if( !UploadBase::isEnabled() ) {
00128 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
00129 return;
00130 }
00131
00132 # Check permissions
00133 global $wgGroupPermissions;
00134 if( !$wgUser->isAllowed( 'upload' ) ) {
00135 if( !$wgUser->isLoggedIn() && ( $wgGroupPermissions['user']['upload']
00136 || $wgGroupPermissions['autoconfirmed']['upload'] ) ) {
00137
00138 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
00139 } else {
00140 $wgOut->permissionRequired( 'upload' );
00141 }
00142 return;
00143 }
00144
00145 # Check blocks
00146 if( $wgUser->isBlocked() ) {
00147 $wgOut->blockedPage();
00148 return;
00149 }
00150
00151 # Check whether we actually want to allow changing stuff
00152 if( wfReadOnly() ) {
00153 $wgOut->readOnlyPage();
00154 return;
00155 }
00156
00157 # Unsave the temporary file in case this was a cancelled upload
00158 if ( $this->mCancelUpload ) {
00159 if ( !$this->unsaveUploadedFile() )
00160 # Something went wrong, so unsaveUploadedFile showed a warning
00161 return;
00162 }
00163
00164 # Process upload or show a form
00165 if ( $this->mTokenOk && !$this->mCancelUpload
00166 && ( $this->mUpload && $this->mUploadClicked ) ) {
00167 $this->processUpload();
00168 } else {
00169 # Backwards compatibility hook
00170 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
00171 {
00172 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
00173 return;
00174 }
00175
00176 $this->showUploadForm( $this->getUploadForm() );
00177 }
00178
00179 # Cleanup
00180 if ( $this->mUpload )
00181 $this->mUpload->cleanupTempFile();
00182 }
00183
00189 protected function showUploadForm( $form ) {
00190 # Add links if file was previously deleted
00191 if ( !$this->mDesiredDestName ) {
00192 $this->showViewDeletedLinks();
00193 }
00194
00195 if ( $form instanceof HTMLForm ) {
00196 $form->show();
00197 } else {
00198 global $wgOut;
00199 $wgOut->addHTML( $form );
00200 }
00201
00202 }
00203
00211 protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) {
00212 global $wgOut;
00213
00214 # Initialize form
00215 $form = new UploadForm( array(
00216 'watch' => $this->getWatchCheck(),
00217 'forreupload' => $this->mForReUpload,
00218 'sessionkey' => $sessionKey,
00219 'hideignorewarning' => $hideIgnoreWarning,
00220 'destwarningack' => (bool)$this->mDestWarningAck,
00221
00222 'texttop' => $this->uploadFormTextTop,
00223 'textaftersummary' => $this->uploadFormTextAfterSummary,
00224 'destfile' => $this->mDesiredDestName,
00225 ) );
00226 $form->setTitle( $this->getTitle() );
00227
00228 # Check the token, but only if necessary
00229 if( !$this->mTokenOk && !$this->mCancelUpload
00230 && ( $this->mUpload && $this->mUploadClicked ) ) {
00231 $form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) );
00232 }
00233
00234 # Add text to form
00235 $form->addPreText( '<div id="uploadtext">' .
00236 wfMsgExt( 'uploadtext', 'parse', array( $this->mDesiredDestName ) ) .
00237 '</div>' );
00238 # Add upload error message
00239 $form->addPreText( $message );
00240
00241 # Add footer to form
00242 $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
00243 if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) {
00244 $form->addPostText( '<div id="mw-upload-footer-message">'
00245 . $wgOut->parse( $uploadFooter ) . "</div>\n" );
00246 }
00247
00248 return $form;
00249
00250 }
00251
00255 protected function showViewDeletedLinks() {
00256 global $wgOut, $wgUser;
00257
00258 $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
00259
00260 if( $title instanceof Title ) {
00261 $count = $title->isDeleted();
00262 if ( $count > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
00263 $link = wfMsgExt(
00264 $wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted',
00265 array( 'parse', 'replaceafter' ),
00266 $wgUser->getSkin()->linkKnown(
00267 SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
00268 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
00269 )
00270 );
00271 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
00272 }
00273 }
00274
00275
00276 if( $title instanceof Title && $title->isDeletedQuick() && !$title->exists() ) {
00277 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
00278 }
00279 }
00280
00292 protected function showRecoverableUploadError( $message ) {
00293 $sessionKey = $this->mUpload->stashSession();
00294 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
00295 '<div class="error">' . $message . "</div>\n";
00296
00297 $form = $this->getUploadForm( $message, $sessionKey );
00298 $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
00299 $this->showUploadForm( $form );
00300 }
00309 protected function showUploadWarning( $warnings ) {
00310 global $wgUser;
00311
00312 # If there are no warnings, or warnings we can ignore, return early.
00313 # mDestWarningAck is set when some javascript has shown the warning
00314 # to the user. mForReUpload is set when the user clicks the "upload a
00315 # new version" link.
00316 if ( !$warnings || ( count( $warnings ) == 1 &&
00317 isset( $warnings['exists'] ) &&
00318 ( $this->mDestWarningAck || $this->mForReUpload ) ) )
00319 {
00320 return false;
00321 }
00322
00323 $sessionKey = $this->mUpload->stashSession();
00324
00325 $sk = $wgUser->getSkin();
00326
00327 $warningHtml = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n"
00328 . '<ul class="warning">';
00329 foreach( $warnings as $warning => $args ) {
00330 $msg = '';
00331 if( $warning == 'exists' ) {
00332 $msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n";
00333 } elseif( $warning == 'duplicate' ) {
00334 $msg = self::getDupeWarning( $args );
00335 } elseif( $warning == 'duplicate-archive' ) {
00336 $msg = "\t<li>" . wfMsgExt( 'file-deleted-duplicate', 'parseinline',
00337 array( Title::makeTitle( NS_FILE, $args )->getPrefixedText() ) )
00338 . "</li>\n";
00339 } else {
00340 if ( $args === true )
00341 $args = array();
00342 elseif ( !is_array( $args ) )
00343 $args = array( $args );
00344 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
00345 }
00346 $warningHtml .= $msg;
00347 }
00348 $warningHtml .= "</ul>\n";
00349 $warningHtml .= wfMsgExt( 'uploadwarning-text', 'parse' );
00350
00351 $form = $this->getUploadForm( $warningHtml, $sessionKey, true );
00352 $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
00353 $form->addButton( 'wpUploadIgnoreWarning', wfMsg( 'ignorewarning' ) );
00354 $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
00355
00356 $this->showUploadForm( $form );
00357
00358 # Indicate that we showed a form
00359 return true;
00360 }
00361
00367 protected function showUploadError( $message ) {
00368 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
00369 '<div class="error">' . $message . "</div>\n";
00370 $this->showUploadForm( $this->getUploadForm( $message ) );
00371 }
00372
00377 protected function processUpload() {
00378 global $wgUser, $wgOut;
00379
00380
00381 $permErrors = $this->mUpload->verifyPermissions( $wgUser );
00382 if( $permErrors !== true ) {
00383 $wgOut->showPermissionsErrorPage( $permErrors );
00384 return;
00385 }
00386
00387
00388 $status = $this->mUpload->fetchFile();
00389 if( !$status->isOK() ) {
00390 $this->showUploadForm( $this->getUploadForm( $wgOut->parse( $status->getWikiText() ) ) );
00391 return;
00392 }
00393
00394
00395 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
00396 {
00397 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
00398 return array( 'status' => UploadBase::BEFORE_PROCESSING );
00399 }
00400
00401
00402
00403 $details = $this->mUpload->verifyUpload();
00404 if ( $details['status'] != UploadBase::OK ) {
00405 $this->processVerificationError( $details );
00406 return;
00407 }
00408
00409 $this->mLocalFile = $this->mUpload->getLocalFile();
00410
00411
00412 if( !$this->mIgnoreWarning ) {
00413 $warnings = $this->mUpload->checkWarnings();
00414 if( $this->showUploadWarning( $warnings ) ) {
00415 return;
00416 }
00417 }
00418
00419
00420 if( !$this->mForReUpload ) {
00421 $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
00422 $this->mCopyrightStatus, $this->mCopyrightSource );
00423 } else {
00424 $pageText = false;
00425 }
00426 $status = $this->mUpload->performUpload( $this->mComment, $pageText, $this->mWatchthis, $wgUser );
00427 if ( !$status->isGood() ) {
00428 $this->showUploadError( $wgOut->parse( $status->getWikiText() ) );
00429 return;
00430 }
00431
00432
00433 $this->mUploadSuccessful = true;
00434 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
00435 $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
00436
00437 }
00438
00442 public static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
00443 global $wgUseCopyrightUpload;
00444 if ( $wgUseCopyrightUpload ) {
00445 $licensetxt = '';
00446 if ( $license != '' ) {
00447 $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
00448 }
00449 $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
00450 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
00451 "$licensetxt" .
00452 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
00453 } else {
00454 if ( $license != '' ) {
00455 $filedesc = $comment == '' ? '' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
00456 $pageText = $filedesc .
00457 '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
00458 } else {
00459 $pageText = $comment;
00460 }
00461 }
00462 return $pageText;
00463 }
00464
00476 protected function getWatchCheck() {
00477 global $wgUser;
00478 if( $wgUser->getOption( 'watchdefault' ) ) {
00479
00480 return true;
00481 }
00482
00483 $local = wfLocalFile( $this->mDesiredDestName );
00484 if( $local && $local->exists() ) {
00485
00486
00487 return $local->getTitle()->userIsWatching();
00488 } else {
00489
00490 return $wgUser->getOption( 'watchcreations' );
00491 }
00492 }
00493
00494
00500 protected function processVerificationError( $details ) {
00501 global $wgFileExtensions, $wgLang;
00502
00503 switch( $details['status'] ) {
00504
00506 case UploadBase::MIN_LENGTH_PARTNAME:
00507 $this->showRecoverableUploadError( wfMsgHtml( 'minlength1' ) );
00508 break;
00509 case UploadBase::ILLEGAL_FILENAME:
00510 $this->showRecoverableUploadError( wfMsgExt( 'illegalfilename',
00511 'parseinline', $details['filtered'] ) );
00512 break;
00513 case UploadBase::OVERWRITE_EXISTING_FILE:
00514 $this->showRecoverableUploadError( wfMsgExt( $details['overwrite'],
00515 'parseinline' ) );
00516 break;
00517 case UploadBase::FILETYPE_MISSING:
00518 $this->showRecoverableUploadError( wfMsgExt( 'filetype-missing',
00519 'parseinline' ) );
00520 break;
00521
00523 case UploadBase::EMPTY_FILE:
00524 $this->showUploadForm( $this->getUploadForm( wfMsgHtml( 'emptyfile' ) ) );
00525 break;
00526 case UploadBase::FILETYPE_BADTYPE:
00527 $finalExt = $details['finalExt'];
00528 $this->showUploadError(
00529 wfMsgExt( 'filetype-banned-type',
00530 array( 'parseinline' ),
00531 htmlspecialchars( $finalExt ),
00532 implode(
00533 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
00534 $wgFileExtensions
00535 ),
00536 $wgLang->formatNum( count( $wgFileExtensions ) )
00537 )
00538 );
00539 break;
00540 case UploadBase::VERIFICATION_ERROR:
00541 unset( $details['status'] );
00542 $code = array_shift( $details['details'] );
00543 $this->showUploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
00544 break;
00545 case UploadBase::HOOK_ABORTED:
00546 if ( is_array( $details['error'] ) ) { # allow hooks to return error details in an array
00547 $args = $details['error'];
00548 $error = array_shift( $args );
00549 } else {
00550 $error = $details['error'];
00551 $args = null;
00552 }
00553
00554 $this->showUploadError( wfMsgExt( $error, 'parseinline', $args ) );
00555 break;
00556 default:
00557 throw new MWException( __METHOD__ . ": Unknown value `{$details['status']}`" );
00558 }
00559 }
00560
00566 protected function unsaveUploadedFile() {
00567 global $wgOut;
00568 if ( !( $this->mUpload instanceof UploadFromStash ) )
00569 return true;
00570 $success = $this->mUpload->unsaveUploadedFile();
00571 if ( ! $success ) {
00572 $wgOut->showFileDeleteError( $this->mUpload->getTempPath() );
00573 return false;
00574 } else {
00575 return true;
00576 }
00577 }
00578
00579
00580
00588 public static function getExistsWarning( $exists ) {
00589 global $wgUser, $wgContLang;
00590
00591 if ( !$exists )
00592 return '';
00593
00594 $file = $exists['file'];
00595 $filename = $file->getTitle()->getPrefixedText();
00596 $warning = '';
00597
00598 $sk = $wgUser->getSkin();
00599
00600 if( $exists['warning'] == 'exists' ) {
00601
00602 $warning = wfMsgExt( 'fileexists', 'parseinline', $filename );
00603 } elseif( $exists['warning'] == 'page-exists' ) {
00604
00605 $warning = wfMsgExt( 'filepageexists', 'parseinline', $filename );
00606 } elseif ( $exists['warning'] == 'exists-normalized' ) {
00607 $warning = wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
00608 $exists['normalizedFile']->getTitle()->getPrefixedText() );
00609 } elseif ( $exists['warning'] == 'thumb' ) {
00610
00611 $warning = wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
00612 $exists['thumbFile']->getTitle()->getPrefixedText(), $filename );
00613 } elseif ( $exists['warning'] == 'thumb-name' ) {
00614
00615 $name = $file->getName();
00616 $badPart = substr( $name, 0, strpos( $name, '-' ) + 1 );
00617 $warning = wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart );
00618 } elseif ( $exists['warning'] == 'bad-prefix' ) {
00619 $warning = wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] );
00620 } elseif ( $exists['warning'] == 'was-deleted' ) {
00621 # If the file existed before and was deleted, warn the user of this
00622 $ltitle = SpecialPage::getTitleFor( 'Log' );
00623 $llink = $sk->linkKnown(
00624 $ltitle,
00625 wfMsgHtml( 'deletionlog' ),
00626 array(),
00627 array(
00628 'type' => 'delete',
00629 'page' => $filename
00630 )
00631 );
00632 $warning = wfMsgWikiHtml( 'filewasdeleted', $llink );
00633 }
00634
00635 return $warning;
00636 }
00637
00644 public static function ajaxGetExistsWarning( $filename ) {
00645 $file = wfFindFile( $filename );
00646 if( !$file ) {
00647
00648
00649 $file = wfLocalFile( $filename );
00650 }
00651 $s = ' ';
00652 if ( $file ) {
00653 $exists = UploadBase::getExistsWarning( $file );
00654 $warning = self::getExistsWarning( $exists );
00655 if ( $warning !== '' ) {
00656 $s = "<div>$warning</div>";
00657 }
00658 }
00659 return $s;
00660 }
00661
00665 public static function getDupeWarning( $dupes ) {
00666 if( $dupes ) {
00667 global $wgOut;
00668 $msg = "<gallery>";
00669 foreach( $dupes as $file ) {
00670 $title = $file->getTitle();
00671 $msg .= $title->getPrefixedText() .
00672 "|" . $title->getText() . "\n";
00673 }
00674 $msg .= "</gallery>";
00675 return "<li>" .
00676 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
00677 $wgOut->parse( $msg ) .
00678 "</li>\n";
00679 } else {
00680 return '';
00681 }
00682 }
00683
00684 }
00685
00689 class UploadForm extends HTMLForm {
00690 protected $mWatch;
00691 protected $mForReUpload;
00692 protected $mSessionKey;
00693 protected $mHideIgnoreWarning;
00694 protected $mDestWarningAck;
00695 protected $mDestFile;
00696
00697 protected $mTextTop;
00698 protected $mTextAfterSummary;
00699
00700 protected $mSourceIds;
00701
00702 public function __construct( $options = array() ) {
00703 global $wgLang;
00704
00705 $this->mWatch = !empty( $options['watch'] );
00706 $this->mForReUpload = !empty( $options['forreupload'] );
00707 $this->mSessionKey = isset( $options['sessionkey'] )
00708 ? $options['sessionkey'] : '';
00709 $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
00710 $this->mDestWarningAck = !empty( $options['destwarningack'] );
00711
00712 $this->mTextTop = $options['texttop'];
00713 $this->mTextAfterSummary = $options['textaftersummary'];
00714 $this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : '';
00715
00716 $sourceDescriptor = $this->getSourceSection();
00717 $descriptor = $sourceDescriptor
00718 + $this->getDescriptionSection()
00719 + $this->getOptionsSection();
00720
00721 wfRunHooks( 'UploadFormInitDescriptor', array( &$descriptor ) );
00722 parent::__construct( $descriptor, 'upload' );
00723
00724 # Set some form properties
00725 $this->setSubmitText( wfMsg( 'uploadbtn' ) );
00726 $this->setSubmitName( 'wpUpload' );
00727 $this->setSubmitTooltip( 'upload' );
00728 $this->setId( 'mw-upload-form' );
00729
00730 # Build a list of IDs for javascript insertion
00731 $this->mSourceIds = array();
00732 foreach ( $sourceDescriptor as $key => $field ) {
00733 if ( !empty( $field['id'] ) )
00734 $this->mSourceIds[] = $field['id'];
00735 }
00736
00737 }
00738
00745 protected function getSourceSection() {
00746 global $wgLang, $wgUser, $wgRequest;
00747
00748 if ( $this->mSessionKey ) {
00749 return array(
00750 'wpSessionKey' => array(
00751 'type' => 'hidden',
00752 'default' => $this->mSessionKey,
00753 ),
00754 'wpSourceType' => array(
00755 'type' => 'hidden',
00756 'default' => 'Stash',
00757 ),
00758 );
00759 }
00760
00761 $canUploadByUrl = UploadFromUrl::isEnabled() && $wgUser->isAllowed( 'upload_by_url' );
00762 $radio = $canUploadByUrl;
00763 $selectedSourceType = strtolower( $wgRequest->getText( 'wpSourceType', 'File' ) );
00764
00765 $descriptor = array();
00766 if ( $this->mTextTop ) {
00767 $descriptor['UploadFormTextTop'] = array(
00768 'type' => 'info',
00769 'section' => 'source',
00770 'default' => $this->mTextTop,
00771 'raw' => true,
00772 );
00773 }
00774
00775 $descriptor['UploadFile'] = array(
00776 'class' => 'UploadSourceField',
00777 'section' => 'source',
00778 'type' => 'file',
00779 'id' => 'wpUploadFile',
00780 'label-message' => 'sourcefilename',
00781 'upload-type' => 'File',
00782 'radio' => &$radio,
00783 'help' => wfMsgExt( 'upload-maxfilesize',
00784 array( 'parseinline', 'escapenoentities' ),
00785 $wgLang->formatSize(
00786 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) )
00787 )
00788 ) . ' ' . wfMsgHtml( 'upload_source_file' ),
00789 'checked' => $selectedSourceType == 'file',
00790 );
00791 if ( $canUploadByUrl ) {
00792 global $wgMaxUploadSize;
00793 $descriptor['UploadFileURL'] = array(
00794 'class' => 'UploadSourceField',
00795 'section' => 'source',
00796 'id' => 'wpUploadFileURL',
00797 'label-message' => 'sourceurl',
00798 'upload-type' => 'url',
00799 'radio' => &$radio,
00800 'help' => wfMsgExt( 'upload-maxfilesize',
00801 array( 'parseinline', 'escapenoentities' ),
00802 $wgLang->formatSize( $wgMaxUploadSize )
00803 ) . ' ' . wfMsgHtml( 'upload_source_url' ),
00804 'checked' => $selectedSourceType == 'url',
00805 );
00806 }
00807 wfRunHooks( 'UploadFormSourceDescriptors', array( &$descriptor, &$radio, $selectedSourceType ) );
00808
00809 $descriptor['Extensions'] = array(
00810 'type' => 'info',
00811 'section' => 'source',
00812 'default' => $this->getExtensionsMessage(),
00813 'raw' => true,
00814 );
00815 return $descriptor;
00816 }
00817
00818
00824 protected function getExtensionsMessage() {
00825 # Print a list of allowed file extensions, if so configured. We ignore
00826 # MIME type here, it's incomprehensible to most people and too long.
00827 global $wgLang, $wgCheckFileExtensions, $wgStrictFileExtensions,
00828 $wgFileExtensions, $wgFileBlacklist;
00829
00830 $allowedExtensions = '';
00831 if( $wgCheckFileExtensions ) {
00832 if( $wgStrictFileExtensions ) {
00833 # Everything not permitted is banned
00834 $extensionsList =
00835 '<div id="mw-upload-permitted">' .
00836 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
00837 "</div>\n";
00838 } else {
00839 # We have to list both preferred and prohibited
00840 $extensionsList =
00841 '<div id="mw-upload-preferred">' .
00842 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
00843 "</div>\n" .
00844 '<div id="mw-upload-prohibited">' .
00845 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileBlacklist ) ) .
00846 "</div>\n";
00847 }
00848 } else {
00849 # Everything is permitted.
00850 $extensionsList = '';
00851 }
00852 return $extensionsList;
00853 }
00854
00861 protected function getDescriptionSection() {
00862 global $wgUser, $wgOut;
00863
00864 $cols = intval( $wgUser->getOption( 'cols' ) );
00865 if( $wgUser->getOption( 'editwidth' ) ) {
00866 $wgOut->addInlineStyle( '#mw-htmlform-description { width: 100%; }' );
00867 }
00868
00869 $descriptor = array(
00870 'DestFile' => array(
00871 'type' => 'text',
00872 'section' => 'description',
00873 'id' => 'wpDestFile',
00874 'label-message' => 'destfilename',
00875 'size' => 60,
00876 'default' => $this->mDestFile,
00877 # FIXME: hack to work around poor handling of the 'default' option in HTMLForm
00878 'nodata' => strval( $this->mDestFile ) !== '',
00879 ),
00880 'UploadDescription' => array(
00881 'type' => 'textarea',
00882 'section' => 'description',
00883 'id' => 'wpUploadDescription',
00884 'label-message' => $this->mForReUpload
00885 ? 'filereuploadsummary'
00886 : 'fileuploadsummary',
00887 'cols' => $cols,
00888 'rows' => 8,
00889 )
00890 );
00891 if ( $this->mTextAfterSummary ) {
00892 $descriptor['UploadFormTextAfterSummary'] = array(
00893 'type' => 'info',
00894 'section' => 'description',
00895 'default' => $this->mTextAfterSummary,
00896 'raw' => true,
00897 );
00898 }
00899
00900 $descriptor += array(
00901 'EditTools' => array(
00902 'type' => 'edittools',
00903 'section' => 'description',
00904 ),
00905 'License' => array(
00906 'type' => 'select',
00907 'class' => 'Licenses',
00908 'section' => 'description',
00909 'id' => 'wpLicense',
00910 'label-message' => 'license',
00911 ),
00912 );
00913 if ( $this->mForReUpload )
00914 $descriptor['DestFile']['readonly'] = true;
00915
00916 global $wgUseCopyrightUpload;
00917 if ( $wgUseCopyrightUpload ) {
00918 $descriptor['UploadCopyStatus'] = array(
00919 'type' => 'text',
00920 'section' => 'description',
00921 'id' => 'wpUploadCopyStatus',
00922 'label-message' => 'filestatus',
00923 );
00924 $descriptor['UploadSource'] = array(
00925 'type' => 'text',
00926 'section' => 'description',
00927 'id' => 'wpUploadSource',
00928 'label-message' => 'filesource',
00929 );
00930 }
00931
00932 return $descriptor;
00933 }
00934
00941 protected function getOptionsSection() {
00942 global $wgUser, $wgOut;
00943
00944 if( $wgUser->isLoggedIn() ) {
00945 $descriptor = array(
00946 'Watchthis' => array(
00947 'type' => 'check',
00948 'id' => 'wpWatchthis',
00949 'label-message' => 'watchthisupload',
00950 'section' => 'options',
00951 'default' => $wgUser->getOption( 'watchcreations' ),
00952 )
00953 );
00954 }
00955 if( !$this->mHideIgnoreWarning ) {
00956 $descriptor['IgnoreWarning'] = array(
00957 'type' => 'check',
00958 'id' => 'wpIgnoreWarning',
00959 'label-message' => 'ignorewarnings',
00960 'section' => 'options',
00961 );
00962 }
00963
00964 $descriptor['wpDestFileWarningAck'] = array(
00965 'type' => 'hidden',
00966 'id' => 'wpDestFileWarningAck',
00967 'default' => $this->mDestWarningAck ? '1' : '',
00968 );
00969
00970 if ( $this->mForReUpload ) {
00971 $descriptor['wpForReUpload'] = array(
00972 'type' => 'hidden',
00973 'id' => 'wpForReUpload',
00974 'default' => '1',
00975 );
00976 }
00977
00978 return $descriptor;
00979
00980 }
00981
00985 public function show() {
00986 $this->addUploadJS();
00987 parent::show();
00988 }
00989
00996 protected function addUploadJS( ) {
00997 global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI;
00998 global $wgOut;
00999
01000 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
01001 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI;
01002
01003 $scriptVars = array(
01004 'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
01005 'wgAjaxLicensePreview' => $useAjaxLicensePreview,
01006 'wgUploadAutoFill' => !$this->mForReUpload &&
01007
01008
01009 $this->mDestFile === '',
01010 'wgUploadSourceIds' => $this->mSourceIds,
01011 );
01012
01013 $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
01014
01015
01016 $wgOut->addScriptFile( 'edit.js' );
01017 $wgOut->addScriptFile( 'upload.js' );
01018 }
01019
01025 function trySubmit() {
01026 return false;
01027 }
01028
01029 }
01030
01034 class UploadSourceField extends HTMLTextField {
01035 function getLabelHtml() {
01036 $id = "wpSourceType{$this->mParams['upload-type']}";
01037 $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
01038
01039 if ( !empty( $this->mParams['radio'] ) ) {
01040 $attribs = array(
01041 'name' => 'wpSourceType',
01042 'type' => 'radio',
01043 'id' => $id,
01044 'value' => $this->mParams['upload-type'],
01045 );
01046 if ( !empty( $this->mParams['checked'] ) )
01047 $attribs['checked'] = 'checked';
01048 $label .= Html::element( 'input', $attribs );
01049 }
01050
01051 return Html::rawElement( 'td', array( 'class' => 'mw-label' ), $label );
01052 }
01053 function getSize() {
01054 return isset( $this->mParams['size'] )
01055 ? $this->mParams['size']
01056 : 60;
01057 }
01058 }
01059