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 $permission = $this->mUpload
->isAllowed( $wgUser );
126 if( $permission !== true ) {
127 if( !$wgUser->isLoggedIn() ) {
128 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
130 $wgOut->permissionRequired( $permission );
136 if( $wgUser->isBlocked() ) {
137 $wgOut->blockedPage();
142 $wgOut->readOnlyPage();
146 if( $this->mReUpload
) {
147 // User did not choose to ignore warnings
148 if( !$this->mUpload
->unsaveUploadedFile() ) {
151 # Because it is probably checked and shouldn't be
152 $this->mIgnoreWarning
= false;
154 $this->mainUploadForm();
155 } elseif( $this->mUpload
&& (
156 'submit' == $this->mAction ||
157 $this->mUploadClicked
159 $this->processUpload();
161 $this->mainUploadForm();
165 $this->mUpload
->cleanupTempFile();
170 * Checks are made in SpecialUpload::execute()
174 function processUpload(){
175 global $wgUser, $wgOut, $wgFileExtensions, $wgLang;
178 $value = $this->internalProcessUpload( $details );
181 case UploadFromBase
::SUCCESS
:
182 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
185 case UploadFromBase
::BEFORE_PROCESSING
:
186 // Do... nothing? Why?
189 case UploadFromBase
::LARGE_FILE_SERVER
:
190 $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
193 case UploadFromBase
::EMPTY_FILE
:
194 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
197 case UploadFromBase
::MIN_LENGHT_PARTNAME
:
198 $this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
201 case UploadFromBase
::ILLEGAL_FILENAME
:
202 $this->uploadError( wfMsgExt( 'illegalfilename',
203 'parseinline', $details['filtered'] ) );
206 case UploadFromBase
::PROTECTED_PAGE
:
207 $wgOut->showPermissionsErrorPage( $details['permissionserrors'] );
210 case UploadFromBase
::OVERWRITE_EXISTING_FILE
:
211 $this->uploadError( wfMsgExt( $details['overwrite'],
215 case UploadFromBase
::FILETYPE_MISSING
:
216 $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
219 case UploadFromBase
::FILETYPE_BADTYPE
:
220 $finalExt = $details['finalExt'];
222 wfMsgExt( 'filetype-banned-type',
223 array( 'parseinline' ),
224 htmlspecialchars( $finalExt ),
226 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
229 $wgLang->formatNum( count( $wgFileExtensions ) )
234 case UploadFromBase
::VERIFICATION_ERROR
:
235 $args = $details['veri'];
236 $code = array_shift( $args );
237 $this->uploadError( wfMsgExt( $code, 'parseinline', $args ) );
240 case UploadFromBase
::UPLOAD_VERIFICATION_ERROR
:
241 $error = $details['error'];
242 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
245 case UploadFromBase
::UPLOAD_WARNING
:
246 $warning = $details['warning'];
247 $this->uploadWarning( $warning );
250 case UploadFromBase
::INTERNAL_ERROR
:
251 $status = $details['internal'];
252 $this->showError( $wgOut->parse( $status->getWikiText() ) );
256 throw new MWException( __METHOD__
. ": Unknown value `{$value}`" );
261 * Really do the upload
262 * Checks are made in SpecialUpload::execute()
264 * @param array $resultDetails contains result-specific dict of additional values
268 function internalProcessUpload( &$resultDetails ) {
271 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
273 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file." );
274 return UploadFromBase
::BEFORE_PROCESSING
;
278 * If the image is protected, non-sysop users won't be able
279 * to modify it by uploading a new revision.
281 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
282 if( $permErrors !== true ) {
283 $resultDetails = array( 'permissionserrors' => $permErrors );
284 return UploadFromBase
::PROTECTED_PAGE
;
287 // Check whether this is a sane upload
288 $result = $this->mUpload
->verifyUpload( $resultDetails );
289 if( $result != UploadFromBase
::OK
)
292 $this->mLocalFile
= $this->mUpload
->getLocalFile();
294 if( !$this->mIgnoreWarning
) {
295 $warnings = $this->mUpload
->checkWarnings();
297 if( count( $warnings ) ) {
298 $resultDetails = array( 'warning' => $warnings );
299 return UploadFromBase
::UPLOAD_WARNING
;
305 * Try actually saving the thing...
306 * It will show an error form on failure. No it will not.
308 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
309 $this->mCopyrightStatus
, $this->mCopyrightSource
);
311 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
313 if ( !$status->isGood() ) {
314 $resultDetails = array( 'internal' => $status );
315 return UploadFromBase
::INTERNAL_ERROR
;
317 // Success, redirect to description page
319 $img = null; // @todo: added to avoid passing a ref to null - should this be defined somewhere?
320 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
321 return UploadFromBase
::SUCCESS
;
326 * Do existence checks on a file and produce a warning
327 * This check is static and can be done pre-upload via AJAX
328 * Returns an HTML fragment consisting of one or more LI elements if there is a warning
329 * Returns an empty string if there is no warning
331 static function getExistsWarning( $exists ) {
332 global $wgUser, $wgContLang;
334 if( $exists === false )
338 $align = $wgContLang->isRtl() ?
'left' : 'right';
340 list( $existsType, $file ) = $exists;
342 $sk = $wgUser->getSkin();
344 if( $existsType == 'exists' ) {
346 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
347 if ( $file->allowInlineDisplay() ) {
348 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
349 $file->getName(), $align, array(), false, true );
350 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
351 $icon = $file->iconThumb();
352 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
353 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
358 $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
360 } elseif( $existsType == 'page-exists' ) {
361 $lnk = $sk->makeKnownLinkObj( $file->getTitle(), '', 'redirect=no' );
362 $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
363 } elseif ( $existsType == 'exists-normalized' ) {
364 # Check if image with lowercase extension exists.
365 # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
366 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
367 if ( $file->allowInlineDisplay() ) {
368 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
369 $file->getTitle()->getText(), $align, array(), false, true );
370 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
371 $icon = $file->iconThumb();
372 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
373 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
379 wfMsgExt( 'fileexists-extension', 'parsemag',
380 $file->getTitle()->getPrefixedText(), $dlink ) .
383 } elseif ( $existsType == 'thumb' ) {
384 # Check if an image without leading '180px-' (or similiar) exists
385 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
386 if ( $file->allowInlineDisplay() ) {
387 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(),
388 wfMsgExt( 'fileexists-thumb', 'parseinline' ),
389 $file->getTitle()->getText(), $align, array(), false, true );
390 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
391 $icon = $file->iconThumb();
392 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
393 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
398 $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
405 * Get a list of warnings
407 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
408 * @return array list of warning messages
410 static function ajaxGetExistsWarning( $filename ) {
411 $file = wfFindFile( $filename );
413 // Force local file so we have an object to do further checks against
414 // if there isn't an exact match...
415 $file = wfLocalFile( $filename );
419 $exists = UploadFromBase
::getExistsWarning( $file );
420 $warning = self
::getExistsWarning( $exists );
421 // FIXME: We probably also want the prefix blacklist and the wasdeleted check here
422 if ( $warning !== '' ) {
423 $s = "<ul>$warning</ul>";
430 * Render a preview of a given license for the AJAX preview on upload
432 * @param string $license
435 public static function ajaxGetLicensePreview( $license ) {
436 global $wgParser, $wgUser;
437 $text = '{{' . $license . '}}';
438 $title = Title
::makeTitle( NS_IMAGE
, 'Sample.jpg' );
439 $options = ParserOptions
::newFromUser( $wgUser );
441 // Expand subst: first, then live templates...
442 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
443 $output = $wgParser->parse( $text, $title, $options );
445 return $output->getText();
449 * Check for duplicate files and throw up a warning before the upload
452 public static function getDupeWarning( $dupes ) {
456 foreach( $dupes as $file ) {
457 $title = $file->getTitle();
458 $msg .= $title->getPrefixedText() .
459 "|" . $title->getText() . "\n";
461 $msg .= "</gallery>";
463 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
464 $wgOut->parse( $msg ) .
472 * Remove a temporarily kept file stashed by saveTempUploadedFile().
476 function unsaveUploadedFile() {
478 $success = $this->mUpload
->unsaveUploadedFile();
480 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
487 /* -------------------------------------------------------------- */
490 * @param string $error as HTML
493 function uploadError( $error ) {
495 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
496 $wgOut->addHTML( '<span class="error">' . $error . '</span>' );
500 * There's something wrong with this file, not enough to reject it
501 * totally but we require manual intervention to save it for real.
502 * Stash it away, then present a form asking to confirm or cancel.
504 * @param string $warning as HTML
507 function uploadWarning( $warnings ) {
509 global $wgUseCopyrightUpload;
511 $this->mSessionKey
= $this->mUpload
->stashSession();
512 if( !$this->mSessionKey
) {
513 # Couldn't save file; an error has been displayed so let's go.
517 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
518 $wgOut->addHTML( '<ul class="warning">' );
519 foreach( $warnings as $warning => $args ) {
521 if( $warning == 'exists' ) {
522 if ( !$this->mDestWarningAck
)
523 $msg = self
::getExistsWarning( $args );
524 } elseif( $warning == 'duplicate' ) {
525 $msg = $this->getDupeWarning( $args );
526 } elseif( $warning == 'filewasdeleted' ) {
527 $ltitle = SpecialPage
::getTitleFor( 'Log' );
528 $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ),
529 'type=delete&page=' . $file->getTitle()->getPrefixedUrl() );
530 $msg = "\t<li>" . wfMsgWikiHtml( 'filewasdeleted', $llink ) . "</li>\n";
532 if( is_bool( $args ) )
534 elseif( !is_array( $args ) )
535 $args = array( $args );
536 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
539 $wgOut->addHTML( $msg );
542 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
544 if ( $wgUseCopyrightUpload ) {
545 $copyright = Xml
::hidden( 'wpUploadCopyStatus', $this->mCopyrightStatus
) . "\n" .
546 Xml
::hidden( 'wpUploadSource', $this->mCopyrightSource
) . "\n";
552 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
553 'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
554 Xml
::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
555 Xml
::hidden( 'wpSessionKey', $this->mSessionKey
) . "\n" .
556 Xml
::hidden( 'wpUploadDescription', $this->mComment
) . "\n" .
557 Xml
::hidden( 'wpLicense', $this->mLicense
) . "\n" .
558 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
) . "\n" .
559 Xml
::hidden( 'wpWatchthis', $this->mWatchthis
) . "\n" .
560 "{$copyright}<br />" .
561 Xml
::submitButton( wfMsg( 'ignorewarning' ), array ( 'name' => 'wpUpload', 'id' => 'wpUpload', 'checked' => 'checked' ) ) . ' ' .
562 Xml
::submitButton( wfMsg( 'reuploaddesc' ), array ( 'name' => 'wpReUpload', 'id' => 'wpReUpload' ) ) .
563 Xml
::closeElement( 'form' ) . "\n"
568 * Displays the main upload form, optionally with a highlighted
569 * error message up at the top.
571 * @param string $msg as HTML
574 function mainUploadForm( $msg='' ) {
575 global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize;
576 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
578 global $wgStylePath, $wgStyleVersion;
580 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
581 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
583 $adc = wfBoolToStr( $useAjaxDestCheck );
584 $alp = wfBoolToStr( $useAjaxLicensePreview );
585 $autofill = wfBoolToStr( $this->mDesiredDestName
== '' );
587 $wgOut->addScript( "<script type=\"text/javascript\">
588 wgAjaxUploadDestCheck = {$adc};
589 wgAjaxLicensePreview = {$alp};
590 wgUploadAutoFill = {$autofill};
592 $wgOut->addScriptFile( 'upload.js' );
593 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
595 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
597 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
601 if( $this->mDesiredDestName
) {
602 $title = Title
::makeTitleSafe( NS_IMAGE
, $this->mDesiredDestName
);
603 // Show a subtitle link to deleted revisions (to sysops et al only)
604 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
606 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
607 array( 'parse', 'replaceafter' ),
608 $wgUser->getSkin()->makeKnownLinkObj(
609 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
610 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
613 $wgOut->addHtml( "<div id=\"contentSub2\">{$link}</div>" );
616 // Show the relevant lines from deletion log (for still deleted files only)
617 if( $title instanceof Title
&& $title->isDeleted() > 0 && !$title->exists() ) {
618 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
622 $cols = intval($wgUser->getOption( 'cols' ));
624 if( $wgUser->getOption( 'editwidth' ) ) {
625 $width = " style=\"width:100%\"";
631 $sub = wfMsgHtml( 'uploaderror' );
632 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
633 "<span class='error'>{$msg}</span>\n" );
635 $wgOut->addHTML( '<div id="uploadtext">' );
636 $wgOut->addWikiMsg( 'uploadtext', $this->mDesiredDestName
);
637 $wgOut->addHTML( "</div>\n" );
639 # Print a list of allowed file extensions, if so configured. We ignore
640 # MIME type here, it's incomprehensible to most people and too long.
641 global $wgCheckFileExtensions, $wgStrictFileExtensions,
642 $wgFileExtensions, $wgFileBlacklist;
644 $allowedExtensions = '';
645 if( $wgCheckFileExtensions ) {
646 $delim = wfMsgExt( 'comma-separator', array( 'escapenoentities' ) );
647 if( $wgStrictFileExtensions ) {
648 # Everything not permitted is banned
650 '<div id="mw-upload-permitted">' .
651 wfMsgWikiHtml( 'upload-permitted', implode( $wgFileExtensions, $delim ) ) .
654 # We have to list both preferred and prohibited
656 '<div id="mw-upload-preferred">' .
657 wfMsgWikiHtml( 'upload-preferred', implode( $wgFileExtensions, $delim ) ) .
659 '<div id="mw-upload-prohibited">' .
660 wfMsgWikiHtml( 'upload-prohibited', implode( $wgFileBlacklist, $delim ) ) .
664 # Everything is permitted.
665 $extensionsList = '';
668 # Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
669 # See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
670 $val = trim( ini_get( 'upload_max_filesize' ) );
671 $last = strtoupper( ( substr( $val, -1 ) ) );
674 $val2 = substr( $val, 0, -1 ) * 1024 * 1024 * 1024;
677 $val2 = substr( $val, 0, -1 ) * 1024 * 1024;
680 $val2 = substr( $val, 0, -1 ) * 1024;
685 $val2 = UploadFromUrl
::isEnabled() ?
min( $wgMaxUploadSize, $val2 ) : $val2;
686 $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
687 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
688 $wgLang->formatSize( $val2 ) ) .
691 $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
692 $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
694 $summary = wfMsgExt( 'fileuploadsummary', 'parseinline' );
696 $licenses = new Licenses();
697 $license = wfMsgExt( 'license', array( 'parseinline' ) );
698 $nolicense = wfMsgHtml( 'nolicense' );
699 $licenseshtml = $licenses->getHtml();
701 $ulb = wfMsgHtml( 'uploadbtn' );
704 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
706 $encDestName = htmlspecialchars( $this->mDesiredDestName
);
708 $watchChecked = $this->watchCheck()
709 ?
'checked="checked"'
711 $warningChecked = $this->mIgnoreWarning ?
'checked' : '';
713 // Prepare form for upload or upload/copy
714 if( UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
716 "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " .
717 "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
718 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
720 "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
721 "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
722 "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
723 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
724 "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='web' " .
725 "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" .
726 "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
728 "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
729 "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
730 "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' disabled='disabled' />" .
731 wfMsgHtml( 'upload_source_url' ) ;
734 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
735 ($this->mDesiredDestName?
"":"onchange='fillDestFilename(\"wpUploadFile\")' ") .
737 "<input type='hidden' name='wpSourceType' value='file' />" ;
739 if ( $useAjaxDestCheck ) {
740 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
741 $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
747 $encComment = htmlspecialchars( $this->mComment
);
750 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL(),
751 'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
752 Xml
::openElement( 'fieldset' ) .
753 Xml
::element( 'legend', null, wfMsg( 'upload' ) ) .
754 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
756 {$this->uploadFormTextTop}
757 <td class='mw-label'>
758 <label for='wpUploadFile'>{$sourcefilename}</label>
760 <td class='mw-input'>
772 <td class='mw-label'>
773 <label for='wpDestFile'>{$destfilename}</label>
775 <td class='mw-input'>
776 <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
777 value=\"{$encDestName}\" onchange='toggleFilenameFiller()' $destOnkeyup />
781 <td class='mw-label'>
782 <label for='wpUploadDescription'>{$summary}</label>
784 <td class='mw-input'>
785 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6'
786 cols='{$cols}'{$width}>$encComment</textarea>
787 {$this->uploadFormTextAfterSummary}
793 if ( $licenseshtml != '' ) {
796 <td class='mw-label'>
797 <label for='wpLicense'>$license</label>
799 <td class='mw-input'>
800 <select name='wpLicense' id='wpLicense' tabindex='4'
801 onchange='licenseSelectorCheck()'>
802 <option value=''>$nolicense</option>
809 if( $useAjaxLicensePreview ) {
812 <td id=\"mw-license-preview\"></td>
819 if ( $wgUseCopyrightUpload ) {
820 $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
821 $copystatus = htmlspecialchars( $this->mCopyrightStatus
);
822 $filesource = wfMsgExt( 'filesource', 'escapenoentities' );
823 $uploadsource = htmlspecialchars( $this->mCopyrightSource
);
826 <td class='mw-label' style='white-space: nowrap;'>
827 <label for='wpUploadCopyStatus'>$filestatus</label></td>
828 <td class='mw-input'>
829 <input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus'
830 value=\"$copystatus\" size='60' />
834 <td class='mw-label'>
835 <label for='wpUploadCopyStatus'>$filesource</label>
837 <td class='mw-input'>
838 <input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus'
839 value=\"$uploadsource\" size='60' />
849 <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
850 <label for='wpWatchthis'>" . wfMsgHtml( 'watchthisupload' ) . "</label>
851 <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked/>
852 <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
858 <td class='mw-input'>
859 <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" . $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
864 <td class='mw-input'>"
866 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
870 Xml
::closeElement( 'table' ) .
871 Xml
::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
872 Xml
::closeElement( 'fieldset' ) .
873 Xml
::closeElement( 'form' )
875 $uploadfooter = wfMsgNoTrans( 'uploadfooter' );
876 if( $uploadfooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadfooter ) ){
877 $wgOut->addWikiText( '<div id="mw-upload-footer-message">' . $uploadfooter . '</div>' );
881 /* -------------------------------------------------------------- */
884 * See if we should check the 'watch this page' checkbox on the form
885 * based on the user's preferences and whether we're being asked
886 * to create a new file or update an existing one.
888 * In the case where 'watch edits' is off but 'watch creations' is on,
889 * we'll leave the box unchecked.
891 * Note that the page target can be changed *on the form*, so our check
892 * state can get out of sync.
894 function watchCheck() {
896 if( $wgUser->getOption( 'watchdefault' ) ) {
901 $local = wfLocalFile( $this->mDesiredDestName
);
902 if( $local && $local->exists() ) {
903 // We're uploading a new version of an existing file.
904 // No creation, so don't watch it if we're not already.
905 return $local->getTitle()->userIsWatching();
907 // New page should get watched if that's our option.
908 return $wgUser->getOption( 'watchcreations' );
913 * Check if a user is the last uploader
916 * @param string $img, image name
918 * @deprecated Use UploadFromBase::userCanReUpload
920 public static function userCanReUpload( User
$user, $img ) {
921 wfDeprecated( __METHOD__
);
923 if( $user->isAllowed( 'reupload' ) )
924 return true; // non-conditional
925 if( !$user->isAllowed( 'reupload-own' ) )
928 $dbr = wfGetDB( DB_SLAVE
);
929 $row = $dbr->selectRow('image',
930 /* SELECT */ 'img_user',
931 /* WHERE */ array( 'img_name' => $img )
936 return $user->getId() == $row->img_user
;
940 * Display an error with a wikitext description
942 function showError( $description ) {
944 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
945 $wgOut->setRobotPolicy( "noindex,nofollow" );
946 $wgOut->setArticleRelated( false );
947 $wgOut->enableClientCache( false );
948 $wgOut->addWikiText( $description );
952 * Get the initial image page text based on a comment and optional file status information
954 static function getInitialPageText( $comment, $license, $copyStatus, $source ) {
955 global $wgUseCopyrightUpload;
956 if ( $wgUseCopyrightUpload ) {
957 if ( $license != '' ) {
958 $licensetxt = '== ' . wfMsgForContent( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
960 $pageText = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n" .
961 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
963 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
965 if ( $license != '' ) {
966 $filedesc = $comment == '' ?
'' : '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n";
967 $pageText = $filedesc .
968 '== ' . wfMsgForContent ( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
970 $pageText = $comment;
977 * If there are rows in the deletion log for this file, show them,
978 * along with a nice little note for the user
980 * @param OutputPage $out
981 * @param string filename
983 private function showDeletionLog( $out, $filename ) {
985 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
986 $pager = new LogPager( $loglist, 'delete', false, $filename );
987 if( $pager->getNumRows() > 0 ) {
988 $out->addHtml( '<div id="mw-upload-deleted-warn">' );
989 $out->addWikiMsg( 'upload-wasdeleted' );
991 $loglist->beginLogEventsList() .
993 $loglist->endLogEventsList()
995 $out->addHtml( '</div>' );