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( $this->mUpload
) {
126 $permission = $this->mUpload
->isAllowed( $wgUser );
128 $permission = $wgUser->isAllowed( 'upload' ) ?
true : 'upload';
130 if( $permission !== true ) {
131 if( !$wgUser->isLoggedIn() ) {
132 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
134 $wgOut->permissionRequired( $permission );
140 if( $wgUser->isBlocked() ) {
141 $wgOut->blockedPage();
146 $wgOut->readOnlyPage();
150 if( $this->mReUpload
) {
151 // User did not choose to ignore warnings
152 if( !$this->mUpload
->unsaveUploadedFile() ) {
155 # Because it is probably checked and shouldn't be
156 $this->mIgnoreWarning
= false;
158 $this->mainUploadForm();
159 } elseif( $this->mUpload
&& (
160 'submit' == $this->mAction ||
161 $this->mUploadClicked
163 $this->processUpload();
165 $this->mainUploadForm();
169 $this->mUpload
->cleanupTempFile();
174 * Checks are made in SpecialUpload::execute()
178 function processUpload(){
179 global $wgUser, $wgOut, $wgFileExtensions, $wgLang;
182 $value = $this->internalProcessUpload( $details );
185 case UploadFromBase
::SUCCESS
:
186 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
189 case UploadFromBase
::BEFORE_PROCESSING
:
190 // Do... nothing? Why?
193 case UploadFromBase
::LARGE_FILE_SERVER
:
194 $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
197 case UploadFromBase
::EMPTY_FILE
:
198 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
201 case UploadFromBase
::MIN_LENGHT_PARTNAME
:
202 $this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
205 case UploadFromBase
::ILLEGAL_FILENAME
:
206 $this->uploadError( wfMsgExt( 'illegalfilename',
207 'parseinline', $details['filtered'] ) );
210 case UploadFromBase
::PROTECTED_PAGE
:
211 $wgOut->showPermissionsErrorPage( $details['permissionserrors'] );
214 case UploadFromBase
::OVERWRITE_EXISTING_FILE
:
215 $this->uploadError( wfMsgExt( $details['overwrite'],
219 case UploadFromBase
::FILETYPE_MISSING
:
220 $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
223 case UploadFromBase
::FILETYPE_BADTYPE
:
224 $finalExt = $details['finalExt'];
226 wfMsgExt( 'filetype-banned-type',
227 array( 'parseinline' ),
228 htmlspecialchars( $finalExt ),
230 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
233 $wgLang->formatNum( count( $wgFileExtensions ) )
238 case UploadFromBase
::VERIFICATION_ERROR
:
239 $args = $details['veri'];
240 $code = array_shift( $args );
241 $this->uploadError( wfMsgExt( $code, 'parseinline', $args ) );
244 case UploadFromBase
::UPLOAD_VERIFICATION_ERROR
:
245 $error = $details['error'];
246 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
249 case UploadFromBase
::UPLOAD_WARNING
:
250 $warning = $details['warning'];
251 $this->uploadWarning( $warning );
254 case UploadFromBase
::INTERNAL_ERROR
:
255 $status = $details['internal'];
256 $this->showError( $wgOut->parse( $status->getWikiText() ) );
260 throw new MWException( __METHOD__
. ": Unknown value `{$value}`" );
265 * Really do the upload
266 * Checks are made in SpecialUpload::execute()
268 * @param array $resultDetails contains result-specific dict of additional values
272 function internalProcessUpload( &$resultDetails ) {
275 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
277 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file." );
278 return UploadFromBase
::BEFORE_PROCESSING
;
282 * If the image is protected, non-sysop users won't be able
283 * to modify it by uploading a new revision.
285 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
286 if( $permErrors !== true ) {
287 $resultDetails = array( 'permissionserrors' => $permErrors );
288 return UploadFromBase
::PROTECTED_PAGE
;
291 // Check whether this is a sane upload
292 $result = $this->mUpload
->verifyUpload( $resultDetails );
293 if( $result != UploadFromBase
::OK
)
296 $this->mLocalFile
= $this->mUpload
->getLocalFile();
298 if( !$this->mIgnoreWarning
) {
299 $warnings = $this->mUpload
->checkWarnings();
301 if( count( $warnings ) ) {
302 $resultDetails = array( 'warning' => $warnings );
303 return UploadFromBase
::UPLOAD_WARNING
;
309 * Try actually saving the thing...
310 * It will show an error form on failure. No it will not.
312 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
313 $this->mCopyrightStatus
, $this->mCopyrightSource
);
315 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
317 if ( !$status->isGood() ) {
318 $resultDetails = array( 'internal' => $status );
319 return UploadFromBase
::INTERNAL_ERROR
;
321 // Success, redirect to description page
323 $img = null; // @todo: added to avoid passing a ref to null - should this be defined somewhere?
324 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
325 return UploadFromBase
::SUCCESS
;
330 * Do existence checks on a file and produce a warning
331 * This check is static and can be done pre-upload via AJAX
332 * Returns an HTML fragment consisting of one or more LI elements if there is a warning
333 * Returns an empty string if there is no warning
335 static function getExistsWarning( $exists ) {
336 global $wgUser, $wgContLang;
338 if( $exists === false )
342 $align = $wgContLang->isRtl() ?
'left' : 'right';
344 list( $existsType, $file ) = $exists;
346 $sk = $wgUser->getSkin();
348 if( $existsType == 'exists' ) {
350 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
351 if ( $file->allowInlineDisplay() ) {
352 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
353 $file->getName(), $align, array(), false, true );
354 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
355 $icon = $file->iconThumb();
356 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
357 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
362 $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
364 } elseif( $existsType == 'page-exists' ) {
365 $lnk = $sk->makeKnownLinkObj( $file->getTitle(), '', 'redirect=no' );
366 $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
367 } elseif ( $existsType == 'exists-normalized' ) {
368 # Check if image with lowercase extension exists.
369 # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
370 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
371 if ( $file->allowInlineDisplay() ) {
372 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
373 $file->getTitle()->getText(), $align, array(), false, true );
374 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
375 $icon = $file->iconThumb();
376 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
377 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
383 wfMsgExt( 'fileexists-extension', 'parsemag',
384 $file->getTitle()->getPrefixedText(), $dlink ) .
387 } elseif ( $existsType == 'thumb' ) {
388 # Check if an image without leading '180px-' (or similiar) exists
389 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
390 if ( $file->allowInlineDisplay() ) {
391 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(),
392 wfMsgExt( 'fileexists-thumb', 'parseinline' ),
393 $file->getTitle()->getText(), $align, array(), false, true );
394 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
395 $icon = $file->iconThumb();
396 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
397 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
402 $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
409 * Get a list of warnings
411 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
412 * @return array list of warning messages
414 static function ajaxGetExistsWarning( $filename ) {
415 $file = wfFindFile( $filename );
417 // Force local file so we have an object to do further checks against
418 // if there isn't an exact match...
419 $file = wfLocalFile( $filename );
423 $exists = UploadFromBase
::getExistsWarning( $file );
424 $warning = self
::getExistsWarning( $exists );
425 // FIXME: We probably also want the prefix blacklist and the wasdeleted check here
426 if ( $warning !== '' ) {
427 $s = "<ul>$warning</ul>";
434 * Render a preview of a given license for the AJAX preview on upload
436 * @param string $license
439 public static function ajaxGetLicensePreview( $license ) {
440 global $wgParser, $wgUser;
441 $text = '{{' . $license . '}}';
442 $title = Title
::makeTitle( NS_IMAGE
, 'Sample.jpg' );
443 $options = ParserOptions
::newFromUser( $wgUser );
445 // Expand subst: first, then live templates...
446 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
447 $output = $wgParser->parse( $text, $title, $options );
449 return $output->getText();
453 * Check for duplicate files and throw up a warning before the upload
456 public static function getDupeWarning( $dupes ) {
460 foreach( $dupes as $file ) {
461 $title = $file->getTitle();
462 $msg .= $title->getPrefixedText() .
463 "|" . $title->getText() . "\n";
465 $msg .= "</gallery>";
467 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
468 $wgOut->parse( $msg ) .
476 * Remove a temporarily kept file stashed by saveTempUploadedFile().
480 function unsaveUploadedFile() {
482 $success = $this->mUpload
->unsaveUploadedFile();
484 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
491 /* -------------------------------------------------------------- */
494 * @param string $error as HTML
497 function uploadError( $error ) {
499 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
500 $wgOut->addHTML( '<span class="error">' . $error . '</span>' );
504 * There's something wrong with this file, not enough to reject it
505 * totally but we require manual intervention to save it for real.
506 * Stash it away, then present a form asking to confirm or cancel.
508 * @param string $warning as HTML
511 function uploadWarning( $warnings ) {
512 global $wgOut, $wgUser;
513 global $wgUseCopyrightUpload;
515 $this->mSessionKey
= $this->mUpload
->stashSession();
516 if( !$this->mSessionKey
) {
517 # Couldn't save file; an error has been displayed so let's go.
521 $sk = $wgUser->getSkin();
523 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
524 $wgOut->addHTML( '<ul class="warning">' );
525 foreach( $warnings as $warning => $args ) {
527 if( $warning == 'exists' ) {
528 if ( !$this->mDestWarningAck
)
529 $msg = self
::getExistsWarning( $args );
530 } elseif( $warning == 'duplicate' ) {
531 $msg = $this->getDupeWarning( $args );
532 } elseif( $warning == 'filewasdeleted' ) {
533 $ltitle = SpecialPage
::getTitleFor( 'Log' );
534 $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ),
535 'type=delete&page=' . $args->getPrefixedUrl() );
536 $msg = "\t<li>" . wfMsgWikiHtml( 'filewasdeleted', $llink ) . "</li>\n";
538 if( is_bool( $args ) )
540 elseif( !is_array( $args ) )
541 $args = array( $args );
542 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
545 $wgOut->addHTML( $msg );
548 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
550 if ( $wgUseCopyrightUpload ) {
551 $copyright = Xml
::hidden( 'wpUploadCopyStatus', $this->mCopyrightStatus
) . "\n" .
552 Xml
::hidden( 'wpUploadSource', $this->mCopyrightSource
) . "\n";
558 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
559 'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
560 Xml
::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
561 Xml
::hidden( 'wpSessionKey', $this->mSessionKey
) . "\n" .
562 Xml
::hidden( 'wpUploadDescription', $this->mComment
) . "\n" .
563 Xml
::hidden( 'wpLicense', $this->mLicense
) . "\n" .
564 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
) . "\n" .
565 Xml
::hidden( 'wpWatchthis', $this->mWatchthis
) . "\n" .
566 "{$copyright}<br />" .
567 Xml
::submitButton( wfMsg( 'ignorewarning' ), array ( 'name' => 'wpUpload', 'id' => 'wpUpload', 'checked' => 'checked' ) ) . ' ' .
568 Xml
::submitButton( wfMsg( 'reuploaddesc' ), array ( 'name' => 'wpReUpload', 'id' => 'wpReUpload' ) ) .
569 Xml
::closeElement( 'form' ) . "\n"
574 * Displays the main upload form, optionally with a highlighted
575 * error message up at the top.
577 * @param string $msg as HTML
580 function mainUploadForm( $msg='' ) {
581 global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize;
582 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
584 global $wgStylePath, $wgStyleVersion;
586 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
587 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
589 $adc = wfBoolToStr( $useAjaxDestCheck );
590 $alp = wfBoolToStr( $useAjaxLicensePreview );
591 $autofill = wfBoolToStr( $this->mDesiredDestName
== '' );
593 $wgOut->addScript( "<script type=\"text/javascript\">
594 wgAjaxUploadDestCheck = {$adc};
595 wgAjaxLicensePreview = {$alp};
596 wgUploadAutoFill = {$autofill};
598 $wgOut->addScriptFile( 'upload.js' );
599 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
601 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
603 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
607 if( $this->mDesiredDestName
) {
608 $title = Title
::makeTitleSafe( NS_IMAGE
, $this->mDesiredDestName
);
609 // Show a subtitle link to deleted revisions (to sysops et al only)
610 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
612 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
613 array( 'parse', 'replaceafter' ),
614 $wgUser->getSkin()->makeKnownLinkObj(
615 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
616 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
619 $wgOut->addHtml( "<div id=\"contentSub2\">{$link}</div>" );
622 // Show the relevant lines from deletion log (for still deleted files only)
623 if( $title instanceof Title
&& $title->isDeleted() > 0 && !$title->exists() ) {
624 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
628 $cols = intval($wgUser->getOption( 'cols' ));
630 if( $wgUser->getOption( 'editwidth' ) ) {
631 $width = " style=\"width:100%\"";
637 $sub = wfMsgHtml( 'uploaderror' );
638 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
639 "<span class='error'>{$msg}</span>\n" );
641 $wgOut->addHTML( '<div id="uploadtext">' );
642 $wgOut->addWikiMsg( 'uploadtext', $this->mDesiredDestName
);
643 $wgOut->addHTML( "</div>\n" );
645 # Print a list of allowed file extensions, if so configured. We ignore
646 # MIME type here, it's incomprehensible to most people and too long.
647 global $wgCheckFileExtensions, $wgStrictFileExtensions,
648 $wgFileExtensions, $wgFileBlacklist;
650 $allowedExtensions = '';
651 if( $wgCheckFileExtensions ) {
652 $delim = wfMsgExt( 'comma-separator', array( 'escapenoentities' ) );
653 if( $wgStrictFileExtensions ) {
654 # Everything not permitted is banned
656 '<div id="mw-upload-permitted">' .
657 wfMsgWikiHtml( 'upload-permitted', implode( $wgFileExtensions, $delim ) ) .
660 # We have to list both preferred and prohibited
662 '<div id="mw-upload-preferred">' .
663 wfMsgWikiHtml( 'upload-preferred', implode( $wgFileExtensions, $delim ) ) .
665 '<div id="mw-upload-prohibited">' .
666 wfMsgWikiHtml( 'upload-prohibited', implode( $wgFileBlacklist, $delim ) ) .
670 # Everything is permitted.
671 $extensionsList = '';
674 # Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
675 # See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
676 $val = trim( ini_get( 'upload_max_filesize' ) );
677 $last = strtoupper( ( substr( $val, -1 ) ) );
680 $val2 = substr( $val, 0, -1 ) * 1024 * 1024 * 1024;
683 $val2 = substr( $val, 0, -1 ) * 1024 * 1024;
686 $val2 = substr( $val, 0, -1 ) * 1024;
691 $val2 = UploadFromUrl
::isEnabled() ?
min( $wgMaxUploadSize, $val2 ) : $val2;
692 $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
693 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
694 $wgLang->formatSize( $val2 ) ) .
697 $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
698 $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
700 $summary = wfMsgExt( 'fileuploadsummary', 'parseinline' );
702 $licenses = new Licenses();
703 $license = wfMsgExt( 'license', array( 'parseinline' ) );
704 $nolicense = wfMsgHtml( 'nolicense' );
705 $licenseshtml = $licenses->getHtml();
707 $ulb = wfMsgHtml( 'uploadbtn' );
710 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
712 $encDestName = htmlspecialchars( $this->mDesiredDestName
);
714 $watchChecked = $this->watchCheck()
715 ?
'checked="checked"'
717 $warningChecked = $this->mIgnoreWarning ?
'checked' : '';
719 // Prepare form for upload or upload/copy
720 if( UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
722 "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " .
723 "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
724 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
726 "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
727 "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
728 "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
729 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
730 "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='web' " .
731 "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" .
732 "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
734 "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
735 "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
736 "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' disabled='disabled' />" .
737 wfMsgHtml( 'upload_source_url' ) ;
740 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
741 ($this->mDesiredDestName?
"":"onchange='fillDestFilename(\"wpUploadFile\")' ") .
743 "<input type='hidden' name='wpSourceType' value='file' />" ;
745 if ( $useAjaxDestCheck ) {
746 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
747 $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
753 $encComment = htmlspecialchars( $this->mComment
);
756 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL(),
757 'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
758 Xml
::openElement( 'fieldset' ) .
759 Xml
::element( 'legend', null, wfMsg( 'upload' ) ) .
760 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
762 {$this->uploadFormTextTop}
763 <td class='mw-label'>
764 <label for='wpUploadFile'>{$sourcefilename}</label>
766 <td class='mw-input'>
778 <td class='mw-label'>
779 <label for='wpDestFile'>{$destfilename}</label>
781 <td class='mw-input'>
782 <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
783 value=\"{$encDestName}\" onchange='toggleFilenameFiller()' $destOnkeyup />
787 <td class='mw-label'>
788 <label for='wpUploadDescription'>{$summary}</label>
790 <td class='mw-input'>
791 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6'
792 cols='{$cols}'{$width}>$encComment</textarea>
793 {$this->uploadFormTextAfterSummary}
799 if ( $licenseshtml != '' ) {
802 <td class='mw-label'>
803 <label for='wpLicense'>$license</label>
805 <td class='mw-input'>
806 <select name='wpLicense' id='wpLicense' tabindex='4'
807 onchange='licenseSelectorCheck()'>
808 <option value=''>$nolicense</option>
815 if( $useAjaxLicensePreview ) {
818 <td id=\"mw-license-preview\"></td>
825 if ( $wgUseCopyrightUpload ) {
826 $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
827 $copystatus = htmlspecialchars( $this->mCopyrightStatus
);
828 $filesource = wfMsgExt( 'filesource', 'escapenoentities' );
829 $uploadsource = htmlspecialchars( $this->mCopyrightSource
);
832 <td class='mw-label' style='white-space: nowrap;'>
833 <label for='wpUploadCopyStatus'>$filestatus</label></td>
834 <td class='mw-input'>
835 <input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus'
836 value=\"$copystatus\" size='60' />
840 <td class='mw-label'>
841 <label for='wpUploadCopyStatus'>$filesource</label>
843 <td class='mw-input'>
844 <input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus'
845 value=\"$uploadsource\" size='60' />
855 <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
856 <label for='wpWatchthis'>" . wfMsgHtml( 'watchthisupload' ) . "</label>
857 <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked/>
858 <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
864 <td class='mw-input'>
865 <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" . $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
870 <td class='mw-input'>"
872 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
876 Xml
::closeElement( 'table' ) .
877 Xml
::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
878 Xml
::closeElement( 'fieldset' ) .
879 Xml
::closeElement( 'form' )
881 $uploadfooter = wfMsgNoTrans( 'uploadfooter' );
882 if( $uploadfooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadfooter ) ){
883 $wgOut->addWikiText( '<div id="mw-upload-footer-message">' . $uploadfooter . '</div>' );
887 /* -------------------------------------------------------------- */
890 * See if we should check the 'watch this page' checkbox on the form
891 * based on the user's preferences and whether we're being asked
892 * to create a new file or update an existing one.
894 * In the case where 'watch edits' is off but 'watch creations' is on,
895 * we'll leave the box unchecked.
897 * Note that the page target can be changed *on the form*, so our check
898 * state can get out of sync.
900 function watchCheck() {
902 if( $wgUser->getOption( 'watchdefault' ) ) {
907 $local = wfLocalFile( $this->mDesiredDestName
);
908 if( $local && $local->exists() ) {
909 // We're uploading a new version of an existing file.
910 // No creation, so don't watch it if we're not already.
911 return $local->getTitle()->userIsWatching();
913 // New page should get watched if that's our option.
914 return $wgUser->getOption( 'watchcreations' );
919 * Check if a user is the last uploader
922 * @param string $img, image name
924 * @deprecated Use UploadFromBase::userCanReUpload
926 public static function userCanReUpload( User
$user, $img ) {
927 wfDeprecated( __METHOD__
);
929 if( $user->isAllowed( 'reupload' ) )
930 return true; // non-conditional
931 if( !$user->isAllowed( 'reupload-own' ) )
934 $dbr = wfGetDB( DB_SLAVE
);
935 $row = $dbr->selectRow('image',
936 /* SELECT */ 'img_user',
937 /* WHERE */ array( 'img_name' => $img )
942 return $user->getId() == $row->img_user
;
946 * Display an error with a wikitext description
948 function showError( $description ) {
950 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
951 $wgOut->setRobotPolicy( "noindex,nofollow" );
952 $wgOut->setArticleRelated( false );
953 $wgOut->enableClientCache( false );
954 $wgOut->addWikiText( $description );
958 * Get the initial image page text based on a comment and optional file status information
960 static function getInitialPageText( $comment, $license, $copyStatus, $source ) {
961 global $wgUseCopyrightUpload;
962 if ( $wgUseCopyrightUpload ) {
963 if ( $license != '' ) {
964 $licensetxt = '== ' . wfMsgForContent( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
966 $pageText = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n" .
967 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
969 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
971 if ( $license != '' ) {
972 $filedesc = $comment == '' ?
'' : '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n";
973 $pageText = $filedesc .
974 '== ' . wfMsgForContent ( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
976 $pageText = $comment;
983 * If there are rows in the deletion log for this file, show them,
984 * along with a nice little note for the user
986 * @param OutputPage $out
987 * @param string filename
989 private function showDeletionLog( $out, $filename ) {
991 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
992 $pager = new LogPager( $loglist, 'delete', false, $filename );
993 if( $pager->getNumRows() > 0 ) {
994 $out->addHtml( '<div id="mw-upload-deleted-warn">' );
995 $out->addWikiMsg( 'upload-wasdeleted' );
997 $loglist->beginLogEventsList() .
999 $loglist->endLogEventsList()
1001 $out->addHtml( '</div>' );