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 global $wgAllowCopyUploads;
46 $this->mDesiredDestName
= $request->getText( 'wpDestFile' );
47 $this->mIgnoreWarning
= $request->getCheck( 'wpIgnoreWarning' );
48 $this->mComment
= $request->getText( 'wpUploadDescription' );
50 if( !$request->wasPosted() ) {
51 # GET requests just give the main form; no data except destination
52 # filename and description
56 # Placeholders for text injection by hooks (empty per default)
57 $this->uploadFormTextTop
= "";
58 $this->uploadFormTextAfterSummary
= "";
60 $this->mReUpload
= $request->getCheck( 'wpReUpload' );
61 $this->mUploadClicked
= $request->getCheck( 'wpUpload' );
63 $this->mLicense
= $request->getText( 'wpLicense' );
64 $this->mCopyrightStatus
= $request->getText( 'wpUploadCopyStatus' );
65 $this->mCopyrightSource
= $request->getText( 'wpUploadSource' );
66 $this->mWatchthis
= $request->getBool( 'wpWatchthis' );
67 $this->mSourceType
= $request->getText( 'wpSourceType' );
68 $this->mDestWarningAck
= $request->getText( 'wpDestFileWarningAck' );
70 $this->mAction
= $request->getVal( 'action' );
72 $desiredDestName = $request->getText( 'wpDestFile' );
73 if( !$desiredDestName )
74 $desiredDestName = $request->getText( 'wpUploadFile' );
76 $this->mSessionKey
= $request->getInt( 'wpSessionKey' );
77 if( !empty( $this->mSessionKey
) &&
78 isset( $_SESSION['wsUploadData'][$this->mSessionKey
]['version'] ) &&
79 $_SESSION['wsUploadData'][$this->mSessionKey
]['version'] ==
80 UploadFromBase
::SESSION_VERSION
) {
82 * Confirming a temporarily stashed upload.
83 * We don't want path names to be forged, so we keep
84 * them in the session on the server and just give
85 * an opaque key to the user agent.
88 $this->mUpload
= new UploadFromStash( $desiredDestName );
89 $data = $_SESSION['wsUploadData'][$this->mSessionKey
];
90 $this->mUpload
->initialize( $data );
94 *Check for a newly uploaded file.
96 if( $wgAllowCopyUploads && $this->mSourceType
== 'web' ) {
97 $this->mUpload
= new UploadFromUrl( $desiredDestName );
98 $this->mUpload
->initialize( $request->getText( 'wpUploadFileURL' ) );
100 $this->mUpload
= new UploadFromUpload( $desiredDestName );
101 $this->mUpload
->initialize(
102 $request->getFileTempName( 'wpUploadFile' ),
103 $request->getFileSize( 'wpUploadFile' ),
104 $request->getFileName( 'wpUploadFile' )
117 global $wgUser, $wgOut;
118 global $wgEnableUploads;
120 # Check uploading enabled
121 if( !$wgEnableUploads ) {
122 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext', array( $this->mDesiredDestName
) );
127 if( !$wgUser->isAllowed( 'upload' ) ) {
128 if( !$wgUser->isLoggedIn() ) {
129 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
131 $wgOut->permissionRequired( 'upload' );
137 if( $wgUser->isBlocked() ) {
138 $wgOut->blockedPage();
143 $wgOut->readOnlyPage();
147 if( $this->mReUpload
) {
148 // User did not choose to ignore warnings
149 if( !$this->mUpload
->unsaveUploadedFile() ) {
152 # Because it is probably checked and shouldn't be
153 $this->mIgnoreWarning
= false;
155 $this->mainUploadForm();
156 } elseif( $this->mUpload
&& (
157 'submit' == $this->mAction ||
158 $this->mUploadClicked
160 $this->processUpload();
162 $this->mainUploadForm();
166 $this->mUpload
->cleanupTempFile();
171 * Checks are made in SpecialUpload::execute()
175 function processUpload(){
176 global $wgUser, $wgOut, $wgFileExtensions, $wgLang;
179 $value = $this->internalProcessUpload( $details );
180 header("X-Internal-Process-Upload: $value");
183 case UploadFromBase
::SUCCESS
:
184 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
187 case UploadFromBase
::BEFORE_PROCESSING
:
188 // Do... nothing? Why?
191 case UploadFromBase
::LARGE_FILE_SERVER
:
192 $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
195 case UploadFromBase
::EMPTY_FILE
:
196 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
199 case UploadFromBase
::MIN_LENGHT_PARTNAME
:
200 $this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
203 case UploadFromBase
::ILLEGAL_FILENAME
:
204 $this->uploadError( wfMsgExt( 'illegalfilename',
205 'parseinline', $details['filtered'] ) );
208 case UploadFromBase
::PROTECTED_PAGE
:
209 $wgOut->showPermissionsErrorPage( $details['permissionserrors'] );
212 case UploadFromBase
::OVERWRITE_EXISTING_FILE
:
213 $this->uploadError( wfMsgExt( $details['overwrite'],
217 case UploadFromBase
::FILETYPE_MISSING
:
218 $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
221 case UploadFromBase
::FILETYPE_BADTYPE
:
222 $finalExt = $details['finalExt'];
224 wfMsgExt( 'filetype-banned-type',
225 array( 'parseinline' ),
226 htmlspecialchars( $finalExt ),
228 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
231 $wgLang->formatNum( count( $wgFileExtensions ) )
236 case UploadFromBase
::VERIFICATION_ERROR
:
237 $args = $details['veri'];
238 $code = array_shift( $args );
239 $this->uploadError( wfMsgExt( $code, 'parseinline', $args ) );
242 case UploadFromBase
::UPLOAD_VERIFICATION_ERROR
:
243 $error = $details['error'];
244 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
247 case UploadFromBase
::UPLOAD_WARNING
:
248 $warning = $details['warning'];
249 $this->uploadWarning( $warning );
252 case UploadFromBase
::INTERNAL_ERROR
:
253 $status = $details['internal'];
254 $this->showError( $wgOut->parse( $status->getWikiText() ) );
258 throw new MWException( __METHOD__
. ": Unknown value `{$value}`" );
263 * Really do the upload
264 * Checks are made in SpecialUpload::execute()
266 * @param array $resultDetails contains result-specific dict of additional values
270 function internalProcessUpload( &$resultDetails ) {
273 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
275 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file." );
276 return UploadFromBase
::BEFORE_PROCESSING
;
279 $nt = $this->mUpload
->getTitle();
280 // Hold back returning errors for a bit so that verifyUpload can fill in the details
281 if ( $nt instanceof Title
) {
283 * If the image is protected, non-sysop users won't be able
284 * to modify it by uploading a new revision.
286 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
287 if( $permErrors !== true ) {
288 $resultDetails = array( 'permissionserrors' => $permErrors );
289 return UploadFromBase
::PROTECTED_PAGE
;
293 // Check whether this is a sane upload
294 $result = $this->mUpload
->verifyUpload( $resultDetails );
295 if( $result != UploadFromBase
::OK
)
298 $this->mLocalFile
= $this->mUpload
->getLocalFile();
300 if( !$this->mIgnoreWarning
) {
301 $warnings = $this->mUpload
->checkWarnings();
303 if( count( $warnings ) ) {
304 $resultDetails = array( 'warning' => $warnings );
305 return UploadFromBase
::UPLOAD_WARNING
;
311 * Try actually saving the thing...
312 * It will show an error form on failure. No it will not.
314 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
315 $this->mCopyrightStatus
, $this->mCopyrightSource
);
317 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
319 if ( !$status->isGood() ) {
320 $resultDetails = array( 'internal' => $status );
321 return UploadFromBase
::INTERNAL_ERROR
;
323 // Success, redirect to description page
325 $img = null; // @todo: added to avoid passing a ref to null - should this be defined somewhere?
326 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
327 return UploadFromBase
::SUCCESS
;
332 * Do existence checks on a file and produce a warning
333 * This check is static and can be done pre-upload via AJAX
334 * Returns an HTML fragment consisting of one or more LI elements if there is a warning
335 * Returns an empty string if there is no warning
337 static function getExistsWarning( $exists ) {
338 global $wgUser, $wgContLang;
340 if( $exists === false )
344 $align = $wgContLang->isRtl() ?
'left' : 'right';
346 list( $existsType, $file ) = $exists;
348 $sk = $wgUser->getSkin();
350 if( $existsType == 'exists' ) {
352 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
353 if ( $file->allowInlineDisplay() ) {
354 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
355 $file->getName(), $align, array(), false, true );
356 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
357 $icon = $file->iconThumb();
358 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
359 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
364 $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
366 } elseif( $existsType == 'page-exists' ) {
367 $lnk = $sk->makeKnownLinkObj( $file->getTitle(), '', 'redirect=no' );
368 $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
369 } elseif ( $existsType == 'exists-normalized' ) {
370 # Check if image with lowercase extension exists.
371 # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
372 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
373 if ( $file->allowInlineDisplay() ) {
374 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
375 $file->getTitle()->getText(), $align, array(), false, true );
376 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
377 $icon = $file->iconThumb();
378 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
379 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
385 wfMsgExt( 'fileexists-extension', 'parsemag',
386 $file->getTitle()->getPrefixedText(), $dlink ) .
389 } elseif ( $existsType == 'thumb' ) {
390 # Check if an image without leading '180px-' (or similiar) exists
391 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
392 if ( $file->allowInlineDisplay() ) {
393 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(),
394 wfMsgExt( 'fileexists-thumb', 'parseinline' ),
395 $file->getTitle()->getText(), $align, array(), false, true );
396 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
397 $icon = $file->iconThumb();
398 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
399 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
404 $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
411 * Get a list of warnings
413 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
414 * @return array list of warning messages
416 static function ajaxGetExistsWarning( $filename ) {
417 $file = wfFindFile( $filename );
419 // Force local file so we have an object to do further checks against
420 // if there isn't an exact match...
421 $file = wfLocalFile( $filename );
425 $exists = UploadFromBase
::getExistsWarning( $file );
426 $warning = self
::getExistsWarning( $exists );
427 // FIXME: We probably also want the prefix blacklist and the wasdeleted check here
428 if ( $warning !== '' ) {
429 $s = "<ul>$warning</ul>";
436 * Render a preview of a given license for the AJAX preview on upload
438 * @param string $license
441 public static function ajaxGetLicensePreview( $license ) {
442 global $wgParser, $wgUser;
443 $text = '{{' . $license . '}}';
444 $title = Title
::makeTitle( NS_IMAGE
, 'Sample.jpg' );
445 $options = ParserOptions
::newFromUser( $wgUser );
447 // Expand subst: first, then live templates...
448 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
449 $output = $wgParser->parse( $text, $title, $options );
451 return $output->getText();
455 * Check for duplicate files and throw up a warning before the upload
458 public static function getDupeWarning( $dupes ) {
462 foreach( $dupes as $file ) {
463 $title = $file->getTitle();
464 $msg .= $title->getPrefixedText() .
465 "|" . $title->getText() . "\n";
467 $msg .= "</gallery>";
469 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
470 $wgOut->parse( $msg ) .
478 * Remove a temporarily kept file stashed by saveTempUploadedFile().
482 function unsaveUploadedFile() {
484 $success = $this->mUpload
->unsaveUploadedFile();
486 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
493 /* -------------------------------------------------------------- */
496 * @param string $error as HTML
499 function uploadError( $error ) {
501 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
502 $wgOut->addHTML( '<span class="error">' . $error . '</span>' );
506 * There's something wrong with this file, not enough to reject it
507 * totally but we require manual intervention to save it for real.
508 * Stash it away, then present a form asking to confirm or cancel.
510 * @param string $warning as HTML
513 function uploadWarning( $warnings ) {
515 global $wgUseCopyrightUpload;
517 $this->mSessionKey
= $this->mUpload
->stashSession();
518 if( !$this->mSessionKey
) {
519 # Couldn't save file; an error has been displayed so let's go.
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=' . $file->getTitle()->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;
583 global $wgRequest, $wgAllowCopyUploads;
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 = $wgAllowCopyUploads ?
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( $wgAllowCopyUploads && $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>' );