11 function wfSpecialUpload() {
13 $form = new UploadForm( $wgRequest );
18 * implements Special:Upload
19 * @ingroup SpecialPage
25 var $mComment, $mLicense, $mIgnoreWarning;
26 var $mCopyrightStatus, $mCopyrightSource, $mReUpload, $mAction, $mUploadClicked;
30 var $mUpload; // Instance of UploadFromBase or derivative
32 # Placeholders for text injection by hooks (must be HTML)
33 # extensions should take care to _append_ to the present value
34 var $uploadFormTextTop;
35 var $uploadFormTextAfterSummary;
40 * Constructor : initialise object
41 * Get data POSTed through the form and assign them to the object
42 * @param $request Data posted.
44 function __construct( &$request ) {
45 $this->mDesiredDestName
= $request->getText( 'wpDestFile' );
46 $this->mIgnoreWarning
= $request->getCheck( 'wpIgnoreWarning' );
47 $this->mComment
= $request->getText( 'wpUploadDescription' );
49 if( !$request->wasPosted() ) {
50 # GET requests just give the main form; no data except destination
51 # filename and description
55 # Placeholders for text injection by hooks (empty per default)
56 $this->uploadFormTextTop
= "";
57 $this->uploadFormTextAfterSummary
= "";
59 $this->mReUpload
= $request->getCheck( 'wpReUpload' );
60 $this->mUploadClicked
= $request->getCheck( 'wpUpload' );
62 $this->mLicense
= $request->getText( 'wpLicense' );
63 $this->mCopyrightStatus
= $request->getText( 'wpUploadCopyStatus' );
64 $this->mCopyrightSource
= $request->getText( 'wpUploadSource' );
65 $this->mWatchthis
= $request->getBool( 'wpWatchthis' );
66 $this->mSourceType
= $request->getText( 'wpSourceType' );
67 $this->mDestWarningAck
= $request->getText( 'wpDestFileWarningAck' );
69 $this->mAction
= $request->getVal( 'action' );
71 $desiredDestName = $request->getText( 'wpDestFile' );
72 if( !$desiredDestName )
73 $desiredDestName = $request->getText( 'wpUploadFile' );
75 $this->mSessionKey
= $request->getInt( 'wpSessionKey' );
76 if( !empty( $this->mSessionKey
) &&
77 isset( $_SESSION['wsUploadData'][$this->mSessionKey
]['version'] ) &&
78 $_SESSION['wsUploadData'][$this->mSessionKey
]['version'] ==
79 UploadFromBase
::SESSION_VERSION
) {
81 * Confirming a temporarily stashed upload.
82 * We don't want path names to be forged, so we keep
83 * them in the session on the server and just give
84 * an opaque key to the user agent.
87 $this->mUpload
= new UploadFromStash( $desiredDestName );
88 $data = $_SESSION['wsUploadData'][$this->mSessionKey
];
89 $this->mUpload
->initialize( $data );
93 *Check for a newly uploaded file.
95 if( UploadFromUrl
::isEnabled() && $this->mSourceType
== 'web' ) {
96 $this->mUpload
= new UploadFromUrl( $desiredDestName );
97 $this->mUpload
->initialize( $request->getText( 'wpUploadFileURL' ) );
99 $this->mUpload
= new UploadFromUpload( $desiredDestName );
100 $this->mUpload
->initialize(
101 $request->getFileTempName( 'wpUploadFile' ),
102 $request->getFileSize( 'wpUploadFile' ),
103 $request->getFileName( 'wpUploadFile' )
116 global $wgUser, $wgOut;
118 # Check uploading enabled
119 if( !UploadFromBase
::isEnabled() ) {
120 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext', array( $this->mDesiredDestName
) );
125 if( !$wgUser->isAllowed( 'upload' ) ) {
126 if( !$wgUser->isLoggedIn() ) {
127 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
129 $wgOut->permissionRequired( 'upload' );
135 if( $wgUser->isBlocked() ) {
136 $wgOut->blockedPage();
141 $wgOut->readOnlyPage();
145 if( $this->mReUpload
) {
146 // User did not choose to ignore warnings
147 if( !$this->mUpload
->unsaveUploadedFile() ) {
150 # Because it is probably checked and shouldn't be
151 $this->mIgnoreWarning
= false;
153 $this->mainUploadForm();
154 } elseif( $this->mUpload
&& (
155 'submit' == $this->mAction ||
156 $this->mUploadClicked
158 $this->processUpload();
160 $this->mainUploadForm();
164 $this->mUpload
->cleanupTempFile();
169 * Checks are made in SpecialUpload::execute()
173 function processUpload(){
174 global $wgUser, $wgOut, $wgFileExtensions, $wgLang;
177 $value = $this->internalProcessUpload( $details );
180 case UploadFromBase
::SUCCESS
:
181 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
184 case UploadFromBase
::BEFORE_PROCESSING
:
185 // Do... nothing? Why?
188 case UploadFromBase
::LARGE_FILE_SERVER
:
189 $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
192 case UploadFromBase
::EMPTY_FILE
:
193 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
196 case UploadFromBase
::MIN_LENGHT_PARTNAME
:
197 $this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
200 case UploadFromBase
::ILLEGAL_FILENAME
:
201 $this->uploadError( wfMsgExt( 'illegalfilename',
202 'parseinline', $details['filtered'] ) );
205 case UploadFromBase
::PROTECTED_PAGE
:
206 $wgOut->showPermissionsErrorPage( $details['permissionserrors'] );
209 case UploadFromBase
::OVERWRITE_EXISTING_FILE
:
210 $this->uploadError( wfMsgExt( $details['overwrite'],
214 case UploadFromBase
::FILETYPE_MISSING
:
215 $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
218 case UploadFromBase
::FILETYPE_BADTYPE
:
219 $finalExt = $details['finalExt'];
221 wfMsgExt( 'filetype-banned-type',
222 array( 'parseinline' ),
223 htmlspecialchars( $finalExt ),
225 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
228 $wgLang->formatNum( count( $wgFileExtensions ) )
233 case UploadFromBase
::VERIFICATION_ERROR
:
234 $args = $details['veri'];
235 $code = array_shift( $args );
236 $this->uploadError( wfMsgExt( $code, 'parseinline', $args ) );
239 case UploadFromBase
::UPLOAD_VERIFICATION_ERROR
:
240 $error = $details['error'];
241 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
244 case UploadFromBase
::UPLOAD_WARNING
:
245 $warning = $details['warning'];
246 $this->uploadWarning( $warning );
249 case UploadFromBase
::INTERNAL_ERROR
:
250 $status = $details['internal'];
251 $this->showError( $wgOut->parse( $status->getWikiText() ) );
255 throw new MWException( __METHOD__
. ": Unknown value `{$value}`" );
260 * Really do the upload
261 * Checks are made in SpecialUpload::execute()
263 * @param array $resultDetails contains result-specific dict of additional values
267 function internalProcessUpload( &$resultDetails ) {
270 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
272 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file." );
273 return UploadFromBase
::BEFORE_PROCESSING
;
276 $nt = $this->mUpload
->getTitle();
277 // Hold back returning errors for a bit so that verifyUpload can fill in the details
278 if ( $nt instanceof Title
) {
280 * If the image is protected, non-sysop users won't be able
281 * to modify it by uploading a new revision.
283 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
284 if( $permErrors !== true ) {
285 $resultDetails = array( 'permissionserrors' => $permErrors );
286 return UploadFromBase
::PROTECTED_PAGE
;
290 // Check whether this is a sane upload
291 $result = $this->mUpload
->verifyUpload( $resultDetails );
292 if( $result != UploadFromBase
::OK
)
295 $this->mLocalFile
= $this->mUpload
->getLocalFile();
297 if( !$this->mIgnoreWarning
) {
298 $warnings = $this->mUpload
->checkWarnings();
300 if( count( $warnings ) ) {
301 $resultDetails = array( 'warning' => $warnings );
302 return UploadFromBase
::UPLOAD_WARNING
;
308 * Try actually saving the thing...
309 * It will show an error form on failure. No it will not.
311 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
312 $this->mCopyrightStatus
, $this->mCopyrightSource
);
314 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
316 if ( !$status->isGood() ) {
317 $resultDetails = array( 'internal' => $status );
318 return UploadFromBase
::INTERNAL_ERROR
;
320 // Success, redirect to description page
322 $img = null; // @todo: added to avoid passing a ref to null - should this be defined somewhere?
323 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
324 return UploadFromBase
::SUCCESS
;
329 * Do existence checks on a file and produce a warning
330 * This check is static and can be done pre-upload via AJAX
331 * Returns an HTML fragment consisting of one or more LI elements if there is a warning
332 * Returns an empty string if there is no warning
334 static function getExistsWarning( $exists ) {
335 global $wgUser, $wgContLang;
337 if( $exists === false )
341 $align = $wgContLang->isRtl() ?
'left' : 'right';
343 list( $existsType, $file ) = $exists;
345 $sk = $wgUser->getSkin();
347 if( $existsType == 'exists' ) {
349 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
350 if ( $file->allowInlineDisplay() ) {
351 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
352 $file->getName(), $align, array(), false, true );
353 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
354 $icon = $file->iconThumb();
355 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
356 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
361 $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
363 } elseif( $existsType == 'page-exists' ) {
364 $lnk = $sk->makeKnownLinkObj( $file->getTitle(), '', 'redirect=no' );
365 $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
366 } elseif ( $existsType == 'exists-normalized' ) {
367 # Check if image with lowercase extension exists.
368 # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
369 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
370 if ( $file->allowInlineDisplay() ) {
371 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
372 $file->getTitle()->getText(), $align, array(), false, true );
373 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
374 $icon = $file->iconThumb();
375 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
376 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
382 wfMsgExt( 'fileexists-extension', 'parsemag',
383 $file->getTitle()->getPrefixedText(), $dlink ) .
386 } elseif ( $existsType == 'thumb' ) {
387 # Check if an image without leading '180px-' (or similiar) exists
388 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
389 if ( $file->allowInlineDisplay() ) {
390 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(),
391 wfMsgExt( 'fileexists-thumb', 'parseinline' ),
392 $file->getTitle()->getText(), $align, array(), false, true );
393 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
394 $icon = $file->iconThumb();
395 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
396 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
401 $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
408 * Get a list of warnings
410 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
411 * @return array list of warning messages
413 static function ajaxGetExistsWarning( $filename ) {
414 $file = wfFindFile( $filename );
416 // Force local file so we have an object to do further checks against
417 // if there isn't an exact match...
418 $file = wfLocalFile( $filename );
422 $exists = UploadFromBase
::getExistsWarning( $file );
423 $warning = self
::getExistsWarning( $exists );
424 // FIXME: We probably also want the prefix blacklist and the wasdeleted check here
425 if ( $warning !== '' ) {
426 $s = "<ul>$warning</ul>";
433 * Render a preview of a given license for the AJAX preview on upload
435 * @param string $license
438 public static function ajaxGetLicensePreview( $license ) {
439 global $wgParser, $wgUser;
440 $text = '{{' . $license . '}}';
441 $title = Title
::makeTitle( NS_IMAGE
, 'Sample.jpg' );
442 $options = ParserOptions
::newFromUser( $wgUser );
444 // Expand subst: first, then live templates...
445 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
446 $output = $wgParser->parse( $text, $title, $options );
448 return $output->getText();
452 * Check for duplicate files and throw up a warning before the upload
455 public static function getDupeWarning( $dupes ) {
459 foreach( $dupes as $file ) {
460 $title = $file->getTitle();
461 $msg .= $title->getPrefixedText() .
462 "|" . $title->getText() . "\n";
464 $msg .= "</gallery>";
466 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
467 $wgOut->parse( $msg ) .
475 * Remove a temporarily kept file stashed by saveTempUploadedFile().
479 function unsaveUploadedFile() {
481 $success = $this->mUpload
->unsaveUploadedFile();
483 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
490 /* -------------------------------------------------------------- */
493 * @param string $error as HTML
496 function uploadError( $error ) {
498 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
499 $wgOut->addHTML( '<span class="error">' . $error . '</span>' );
503 * There's something wrong with this file, not enough to reject it
504 * totally but we require manual intervention to save it for real.
505 * Stash it away, then present a form asking to confirm or cancel.
507 * @param string $warning as HTML
510 function uploadWarning( $warnings ) {
512 global $wgUseCopyrightUpload;
514 $this->mSessionKey
= $this->mUpload
->stashSession();
515 if( !$this->mSessionKey
) {
516 # Couldn't save file; an error has been displayed so let's go.
520 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
521 $wgOut->addHTML( '<ul class="warning">' );
522 foreach( $warnings as $warning => $args ) {
524 if( $warning == 'exists' ) {
525 if ( !$this->mDestWarningAck
)
526 $msg = self
::getExistsWarning( $args );
527 } elseif( $warning == 'duplicate' ) {
528 $msg = $this->getDupeWarning( $args );
529 } elseif( $warning == 'filewasdeleted' ) {
530 $ltitle = SpecialPage
::getTitleFor( 'Log' );
531 $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ),
532 'type=delete&page=' . $file->getTitle()->getPrefixedUrl() );
533 $msg = "\t<li>" . wfMsgWikiHtml( 'filewasdeleted', $llink ) . "</li>\n";
535 if( is_bool( $args ) )
537 elseif( !is_array( $args ) )
538 $args = array( $args );
539 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
542 $wgOut->addHTML( $msg );
545 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
547 if ( $wgUseCopyrightUpload ) {
548 $copyright = Xml
::hidden( 'wpUploadCopyStatus', $this->mCopyrightStatus
) . "\n" .
549 Xml
::hidden( 'wpUploadSource', $this->mCopyrightSource
) . "\n";
555 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
556 'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
557 Xml
::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
558 Xml
::hidden( 'wpSessionKey', $this->mSessionKey
) . "\n" .
559 Xml
::hidden( 'wpUploadDescription', $this->mComment
) . "\n" .
560 Xml
::hidden( 'wpLicense', $this->mLicense
) . "\n" .
561 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
) . "\n" .
562 Xml
::hidden( 'wpWatchthis', $this->mWatchthis
) . "\n" .
563 "{$copyright}<br />" .
564 Xml
::submitButton( wfMsg( 'ignorewarning' ), array ( 'name' => 'wpUpload', 'id' => 'wpUpload', 'checked' => 'checked' ) ) . ' ' .
565 Xml
::submitButton( wfMsg( 'reuploaddesc' ), array ( 'name' => 'wpReUpload', 'id' => 'wpReUpload' ) ) .
566 Xml
::closeElement( 'form' ) . "\n"
571 * Displays the main upload form, optionally with a highlighted
572 * error message up at the top.
574 * @param string $msg as HTML
577 function mainUploadForm( $msg='' ) {
578 global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize;
579 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
581 global $wgStylePath, $wgStyleVersion;
583 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
584 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
586 $adc = wfBoolToStr( $useAjaxDestCheck );
587 $alp = wfBoolToStr( $useAjaxLicensePreview );
588 $autofill = wfBoolToStr( $this->mDesiredDestName
== '' );
590 $wgOut->addScript( "<script type=\"text/javascript\">
591 wgAjaxUploadDestCheck = {$adc};
592 wgAjaxLicensePreview = {$alp};
593 wgUploadAutoFill = {$autofill};
595 $wgOut->addScriptFile( 'upload.js' );
596 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
598 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
600 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
604 if( $this->mDesiredDestName
) {
605 $title = Title
::makeTitleSafe( NS_IMAGE
, $this->mDesiredDestName
);
606 // Show a subtitle link to deleted revisions (to sysops et al only)
607 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
609 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
610 array( 'parse', 'replaceafter' ),
611 $wgUser->getSkin()->makeKnownLinkObj(
612 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
613 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
616 $wgOut->addHtml( "<div id=\"contentSub2\">{$link}</div>" );
619 // Show the relevant lines from deletion log (for still deleted files only)
620 if( $title instanceof Title
&& $title->isDeleted() > 0 && !$title->exists() ) {
621 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
625 $cols = intval($wgUser->getOption( 'cols' ));
627 if( $wgUser->getOption( 'editwidth' ) ) {
628 $width = " style=\"width:100%\"";
634 $sub = wfMsgHtml( 'uploaderror' );
635 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
636 "<span class='error'>{$msg}</span>\n" );
638 $wgOut->addHTML( '<div id="uploadtext">' );
639 $wgOut->addWikiMsg( 'uploadtext', $this->mDesiredDestName
);
640 $wgOut->addHTML( "</div>\n" );
642 # Print a list of allowed file extensions, if so configured. We ignore
643 # MIME type here, it's incomprehensible to most people and too long.
644 global $wgCheckFileExtensions, $wgStrictFileExtensions,
645 $wgFileExtensions, $wgFileBlacklist;
647 $allowedExtensions = '';
648 if( $wgCheckFileExtensions ) {
649 $delim = wfMsgExt( 'comma-separator', array( 'escapenoentities' ) );
650 if( $wgStrictFileExtensions ) {
651 # Everything not permitted is banned
653 '<div id="mw-upload-permitted">' .
654 wfMsgWikiHtml( 'upload-permitted', implode( $wgFileExtensions, $delim ) ) .
657 # We have to list both preferred and prohibited
659 '<div id="mw-upload-preferred">' .
660 wfMsgWikiHtml( 'upload-preferred', implode( $wgFileExtensions, $delim ) ) .
662 '<div id="mw-upload-prohibited">' .
663 wfMsgWikiHtml( 'upload-prohibited', implode( $wgFileBlacklist, $delim ) ) .
667 # Everything is permitted.
668 $extensionsList = '';
671 # Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
672 # See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
673 $val = trim( ini_get( 'upload_max_filesize' ) );
674 $last = strtoupper( ( substr( $val, -1 ) ) );
677 $val2 = substr( $val, 0, -1 ) * 1024 * 1024 * 1024;
680 $val2 = substr( $val, 0, -1 ) * 1024 * 1024;
683 $val2 = substr( $val, 0, -1 ) * 1024;
688 $val2 = UploadFromUrl
::isEnabled() ?
min( $wgMaxUploadSize, $val2 ) : $val2;
689 $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
690 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
691 $wgLang->formatSize( $val2 ) ) .
694 $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
695 $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
697 $summary = wfMsgExt( 'fileuploadsummary', 'parseinline' );
699 $licenses = new Licenses();
700 $license = wfMsgExt( 'license', array( 'parseinline' ) );
701 $nolicense = wfMsgHtml( 'nolicense' );
702 $licenseshtml = $licenses->getHtml();
704 $ulb = wfMsgHtml( 'uploadbtn' );
707 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
709 $encDestName = htmlspecialchars( $this->mDesiredDestName
);
711 $watchChecked = $this->watchCheck()
712 ?
'checked="checked"'
714 $warningChecked = $this->mIgnoreWarning ?
'checked' : '';
716 // Prepare form for upload or upload/copy
717 if( UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
719 "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " .
720 "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
721 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
723 "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
724 "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
725 "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
726 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
727 "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='web' " .
728 "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" .
729 "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
731 "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
732 "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
733 "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' disabled='disabled' />" .
734 wfMsgHtml( 'upload_source_url' ) ;
737 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
738 ($this->mDesiredDestName?
"":"onchange='fillDestFilename(\"wpUploadFile\")' ") .
740 "<input type='hidden' name='wpSourceType' value='file' />" ;
742 if ( $useAjaxDestCheck ) {
743 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
744 $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
750 $encComment = htmlspecialchars( $this->mComment
);
753 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL(),
754 'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
755 Xml
::openElement( 'fieldset' ) .
756 Xml
::element( 'legend', null, wfMsg( 'upload' ) ) .
757 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
759 {$this->uploadFormTextTop}
760 <td class='mw-label'>
761 <label for='wpUploadFile'>{$sourcefilename}</label>
763 <td class='mw-input'>
775 <td class='mw-label'>
776 <label for='wpDestFile'>{$destfilename}</label>
778 <td class='mw-input'>
779 <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
780 value=\"{$encDestName}\" onchange='toggleFilenameFiller()' $destOnkeyup />
784 <td class='mw-label'>
785 <label for='wpUploadDescription'>{$summary}</label>
787 <td class='mw-input'>
788 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6'
789 cols='{$cols}'{$width}>$encComment</textarea>
790 {$this->uploadFormTextAfterSummary}
796 if ( $licenseshtml != '' ) {
799 <td class='mw-label'>
800 <label for='wpLicense'>$license</label>
802 <td class='mw-input'>
803 <select name='wpLicense' id='wpLicense' tabindex='4'
804 onchange='licenseSelectorCheck()'>
805 <option value=''>$nolicense</option>
812 if( $useAjaxLicensePreview ) {
815 <td id=\"mw-license-preview\"></td>
822 if ( $wgUseCopyrightUpload ) {
823 $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
824 $copystatus = htmlspecialchars( $this->mCopyrightStatus
);
825 $filesource = wfMsgExt( 'filesource', 'escapenoentities' );
826 $uploadsource = htmlspecialchars( $this->mCopyrightSource
);
829 <td class='mw-label' style='white-space: nowrap;'>
830 <label for='wpUploadCopyStatus'>$filestatus</label></td>
831 <td class='mw-input'>
832 <input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus'
833 value=\"$copystatus\" size='60' />
837 <td class='mw-label'>
838 <label for='wpUploadCopyStatus'>$filesource</label>
840 <td class='mw-input'>
841 <input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus'
842 value=\"$uploadsource\" size='60' />
852 <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
853 <label for='wpWatchthis'>" . wfMsgHtml( 'watchthisupload' ) . "</label>
854 <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked/>
855 <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
861 <td class='mw-input'>
862 <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" . $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
867 <td class='mw-input'>"
869 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
873 Xml
::closeElement( 'table' ) .
874 Xml
::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
875 Xml
::closeElement( 'fieldset' ) .
876 Xml
::closeElement( 'form' )
878 $uploadfooter = wfMsgNoTrans( 'uploadfooter' );
879 if( $uploadfooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadfooter ) ){
880 $wgOut->addWikiText( '<div id="mw-upload-footer-message">' . $uploadfooter . '</div>' );
884 /* -------------------------------------------------------------- */
887 * See if we should check the 'watch this page' checkbox on the form
888 * based on the user's preferences and whether we're being asked
889 * to create a new file or update an existing one.
891 * In the case where 'watch edits' is off but 'watch creations' is on,
892 * we'll leave the box unchecked.
894 * Note that the page target can be changed *on the form*, so our check
895 * state can get out of sync.
897 function watchCheck() {
899 if( $wgUser->getOption( 'watchdefault' ) ) {
904 $local = wfLocalFile( $this->mDesiredDestName
);
905 if( $local && $local->exists() ) {
906 // We're uploading a new version of an existing file.
907 // No creation, so don't watch it if we're not already.
908 return $local->getTitle()->userIsWatching();
910 // New page should get watched if that's our option.
911 return $wgUser->getOption( 'watchcreations' );
916 * Check if a user is the last uploader
919 * @param string $img, image name
921 * @deprecated Use UploadFromBase::userCanReUpload
923 public static function userCanReUpload( User
$user, $img ) {
924 wfDeprecated( __METHOD__
);
926 if( $user->isAllowed( 'reupload' ) )
927 return true; // non-conditional
928 if( !$user->isAllowed( 'reupload-own' ) )
931 $dbr = wfGetDB( DB_SLAVE
);
932 $row = $dbr->selectRow('image',
933 /* SELECT */ 'img_user',
934 /* WHERE */ array( 'img_name' => $img )
939 return $user->getId() == $row->img_user
;
943 * Display an error with a wikitext description
945 function showError( $description ) {
947 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
948 $wgOut->setRobotPolicy( "noindex,nofollow" );
949 $wgOut->setArticleRelated( false );
950 $wgOut->enableClientCache( false );
951 $wgOut->addWikiText( $description );
955 * Get the initial image page text based on a comment and optional file status information
957 static function getInitialPageText( $comment, $license, $copyStatus, $source ) {
958 global $wgUseCopyrightUpload;
959 if ( $wgUseCopyrightUpload ) {
960 if ( $license != '' ) {
961 $licensetxt = '== ' . wfMsgForContent( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
963 $pageText = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n" .
964 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
966 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
968 if ( $license != '' ) {
969 $filedesc = $comment == '' ?
'' : '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n";
970 $pageText = $filedesc .
971 '== ' . wfMsgForContent ( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
973 $pageText = $comment;
980 * If there are rows in the deletion log for this file, show them,
981 * along with a nice little note for the user
983 * @param OutputPage $out
984 * @param string filename
986 private function showDeletionLog( $out, $filename ) {
988 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
989 $pager = new LogPager( $loglist, 'delete', false, $filename );
990 if( $pager->getNumRows() > 0 ) {
991 $out->addHtml( '<div id="mw-upload-deleted-warn">' );
992 $out->addWikiMsg( 'upload-wasdeleted' );
994 $loglist->beginLogEventsList() .
996 $loglist->endLogEventsList()
998 $out->addHtml( '</div>' );