Index: trunk/phase3/skins/common/upload.js |
— | — | @@ -11,13 +11,125 @@ |
12 | 12 | // for MSIE/Mac; non-breaking spaces cause the <option> not to render |
13 | 13 | // but, for some reason, setting the text to itself works |
14 | 14 | var selector = document.getElementById("wpLicense"); |
15 | | - var ua = navigator.userAgent; |
16 | | - var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1); |
17 | | - if (isMacIe) { |
18 | | - for (var i = 0; i < selector.options.length; i++) { |
19 | | - selector.options[i].text = selector.options[i].text; |
| 15 | + if (selector) { |
| 16 | + var ua = navigator.userAgent; |
| 17 | + var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1); |
| 18 | + if (isMacIe) { |
| 19 | + for (var i = 0; i < selector.options.length; i++) { |
| 20 | + selector.options[i].text = selector.options[i].text; |
| 21 | + } |
20 | 22 | } |
21 | 23 | } |
22 | 24 | } |
23 | 25 | |
| 26 | +var wgUploadWarningObj = { |
| 27 | + 'responseCache' : { '' : ' ' }, |
| 28 | + 'nameToCheck' : '', |
| 29 | + 'typing': false, |
| 30 | + 'delay': 500, // ms |
| 31 | + 'timeoutID': false, |
| 32 | + |
| 33 | + 'keypress': function () { |
| 34 | + // Find file to upload |
| 35 | + var destFile = document.getElementById('wpDestFile'); |
| 36 | + var warningElt = document.getElementById( 'wpDestFile-warning' ); |
| 37 | + if ( !destFile || !warningElt ) return ; |
| 38 | + |
| 39 | + this.nameToCheck = destFile.value ; |
| 40 | + |
| 41 | + // Clear timer |
| 42 | + if ( this.timeoutID ) { |
| 43 | + window.clearTimeout( this.timeoutID ); |
| 44 | + } |
| 45 | + // Check response cache |
| 46 | + if ( this.nameToCheck in this.responseCache ) { |
| 47 | + this.setWarning(this.responseCache[this.nameToCheck]); |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + this.setInnerHTML(warningElt, '..'); // TODO: pretty animated GIF |
| 52 | + this.timeoutID = window.setTimeout( 'wgUploadWarningObj.timeout()', this.delay ); |
| 53 | + }, |
| 54 | + |
| 55 | + 'checkNow': function (fname) { |
| 56 | + if ( this.timeoutID ) { |
| 57 | + window.clearTimeout( this.timeoutID ); |
| 58 | + } |
| 59 | + this.nameToCheck = fname; |
| 60 | + this.timeout(); |
| 61 | + }, |
| 62 | + |
| 63 | + 'timeout' : function() { |
| 64 | + var warningElt = document.getElementById( 'wpDestFile-warning' ); |
| 65 | + this.setInnerHTML(warningElt, '....'); // TODO: pretty animated GIF |
| 66 | + |
| 67 | + // Get variables into local scope so that they will be preserved for the |
| 68 | + // anonymous callback. fileName is copied so that multiple overlapping |
| 69 | + // ajax requests can be supported. |
| 70 | + var obj = this; |
| 71 | + var fileName = this.nameToCheck; |
| 72 | + sajax_do_call( 'UploadForm::ajaxGetExistsWarning', [this.nameToCheck], |
| 73 | + function (result) { |
| 74 | + obj.processResult(result, fileName) |
| 75 | + } |
| 76 | + ); |
| 77 | + }, |
| 78 | + |
| 79 | + 'processResult' : function (result, fileName) { |
| 80 | + this.setWarning(result.responseText); |
| 81 | + this.responseCache[fileName] = result.responseText; |
| 82 | + }, |
| 83 | + |
| 84 | + 'setWarning' : function (warning) { |
| 85 | + var warningElt = document.getElementById( 'wpDestFile-warning' ); |
| 86 | + var ackElt = document.getElementById( 'wpDestFileWarningAck' ); |
| 87 | + this.setInnerHTML(warningElt, warning); |
| 88 | + |
| 89 | + // Set a value in the form indicating that the warning is acknowledged and |
| 90 | + // doesn't need to be redisplayed post-upload |
| 91 | + if ( warning == '' || warning == ' ' ) { |
| 92 | + ackElt.value = ''; |
| 93 | + } else { |
| 94 | + ackElt.value = '1'; |
| 95 | + } |
| 96 | + }, |
| 97 | + |
| 98 | + 'setInnerHTML' : function (element, text) { |
| 99 | + // Check for no change to avoid flicker in IE 7 |
| 100 | + if (element.innerHTML != text) { |
| 101 | + element.innerHTML = text; |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +function fillDestFilename(id) { |
| 107 | + if (!document.getElementById) { |
| 108 | + return; |
| 109 | + } |
| 110 | + var path = document.getElementById(id).value; |
| 111 | + // Find trailing part |
| 112 | + var slash = path.lastIndexOf('/'); |
| 113 | + var backslash = path.lastIndexOf('\\'); |
| 114 | + var fname; |
| 115 | + if (slash == -1 && backslash == -1) { |
| 116 | + fname = path; |
| 117 | + } else if (slash > backslash) { |
| 118 | + fname = path.substring(slash+1, 10000); |
| 119 | + } else { |
| 120 | + fname = path.substring(backslash+1, 10000); |
| 121 | + } |
| 122 | + |
| 123 | + // Capitalise first letter and replace spaces by underscores |
| 124 | + fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_'); |
| 125 | + |
| 126 | + // Output result |
| 127 | + var destFile = document.getElementById('wpDestFile'); |
| 128 | + if (destFile) { |
| 129 | + destFile.value = fname; |
| 130 | + if ( wgAjaxUploadDestCheck ) { |
| 131 | + wgUploadWarningObj.checkNow(fname) ; |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | + |
24 | 136 | addOnloadHook(licenseSelectorFixup); |
Index: trunk/phase3/skins/common/wikibits.js |
— | — | @@ -766,73 +766,6 @@ |
767 | 767 | document.getElementById(idb).checked=false; |
768 | 768 | } |
769 | 769 | |
770 | | -var lastFileChecked = "" ; |
771 | | -function checkFileExists () { |
772 | | - // Find file to upload |
773 | | - var destFile = document.getElementById('wpDestFile'); |
774 | | - if ( !destFile ) return ; |
775 | | - fname = destFile.value ; |
776 | | - |
777 | | - if ( fname == lastFileChecked ) return ; |
778 | | - lastFileChecked = fname ; |
779 | | - |
780 | | - // Delete old warning, if any |
781 | | - var existsWarning = document.getElementById('existsWarning'); |
782 | | - if ( existsWarning ) { |
783 | | - var pn = existsWarning.parentNode ; |
784 | | - pn.removeChild ( existsWarning ) ; |
785 | | - } |
786 | | - |
787 | | - // Check for existence |
788 | | - var url = wgServer + wgScriptPath + "/api.php?action=query&prop=info&format=xml&titles=Image:" + fname ; |
789 | | - var xmlHttp = new XMLHttpRequest(); |
790 | | - xmlHttp.open('GET', url, false); |
791 | | - xmlHttp.send(null); |
792 | | - var text = xmlHttp.responseText ; |
793 | | - if ( text.split(" pageid=").length < 2 ) return ; // Page doesn'exist (test is quicker than XML parsing, so...) |
794 | | - |
795 | | - // Set warning |
796 | | - var thetd = destFile.parentNode ; |
797 | | - var nn = document.createElement("span") ; |
798 | | - nn.id = "existsWarning" ; |
799 | | - nn.style.color = "red" ; |
800 | | - var nt = document.createTextNode(" A file with this name already exists; uploading under the same name will replace it!"); |
801 | | - nn.appendChild ( nt ) ; |
802 | | - thetd.appendChild ( nn ) ; |
803 | | - |
804 | | - // Restore the filename |
805 | | - var destFile = document.getElementById('wpDestFile'); |
806 | | - destFile.value = fname; |
807 | | -} |
808 | | - |
809 | | -function fillDestFilename(id) { |
810 | | - if (!document.getElementById) { |
811 | | - return; |
812 | | - } |
813 | | - var path = document.getElementById(id).value; |
814 | | - // Find trailing part |
815 | | - var slash = path.lastIndexOf('/'); |
816 | | - var backslash = path.lastIndexOf('\\'); |
817 | | - var fname; |
818 | | - if (slash == -1 && backslash == -1) { |
819 | | - fname = path; |
820 | | - } else if (slash > backslash) { |
821 | | - fname = path.substring(slash+1, 10000); |
822 | | - } else { |
823 | | - fname = path.substring(backslash+1, 10000); |
824 | | - } |
825 | | - |
826 | | - // Capitalise first letter and replace spaces by underscores |
827 | | - fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_'); |
828 | | - |
829 | | - // Output result |
830 | | - var destFile = document.getElementById('wpDestFile'); |
831 | | - if (destFile) { |
832 | | - destFile.value = fname; |
833 | | - checkFileExists () ; |
834 | | - } |
835 | | -} |
836 | | - |
837 | 770 | function scrollEditBox() { |
838 | 771 | var editBoxEl = document.getElementById("wpTextbox1"); |
839 | 772 | var scrollTopEl = document.getElementById("wpScrolltop"); |
Index: trunk/phase3/includes/AjaxDispatcher.php |
— | — | @@ -84,8 +84,13 @@ |
85 | 85 | wfHttpError( 400, 'Bad Request', |
86 | 86 | "unknown function " . (string) $this->func_name ); |
87 | 87 | } else { |
| 88 | + if ( strpos( $this->func_name, '::' ) !== false ) { |
| 89 | + $func = explode( '::', $this->func_name, 2 ); |
| 90 | + } else { |
| 91 | + $func = $this->func_name; |
| 92 | + } |
88 | 93 | try { |
89 | | - $result = call_user_func_array($this->func_name, $this->args); |
| 94 | + $result = call_user_func_array($func, $this->args); |
90 | 95 | |
91 | 96 | if ( $result === false || $result === NULL ) { |
92 | 97 | wfHttpError( 500, 'Internal Error', |
Index: trunk/phase3/includes/Setup.php |
— | — | @@ -257,6 +257,7 @@ |
258 | 258 | |
259 | 259 | if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch'; |
260 | 260 | if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch'; |
| 261 | +if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning'; |
261 | 262 | |
262 | 263 | wfSeedRandom(); |
263 | 264 | |
Index: trunk/phase3/includes/SpecialUpload.php |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | var $mDestName, $mTempPath, $mFileSize, $mFileProps; |
28 | 28 | var $mCopyrightStatus, $mCopyrightSource, $mReUpload, $mAction, $mUploadClicked; |
29 | 29 | var $mSrcName, $mSessionKey, $mStashed, $mDesiredDestName, $mRemoveTempFile, $mSourceType; |
30 | | - var $mCurlDestHandle; |
| 30 | + var $mDestWarningAck, $mCurlDestHandle; |
31 | 31 | var $mLocalFile; |
32 | 32 | |
33 | 33 | # Placeholders for text injection by hooks (must be HTML) |
— | — | @@ -65,7 +65,7 @@ |
66 | 66 | $this->mCopyrightSource = $request->getText( 'wpUploadSource' ); |
67 | 67 | $this->mWatchthis = $request->getBool( 'wpWatchthis' ); |
68 | 68 | $this->mSourceType = $request->getText( 'wpSourceType' ); |
69 | | - wfDebug( "UploadForm: watchthis is: '$this->mWatchthis'\n" ); |
| 69 | + $this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' ); |
70 | 70 | |
71 | 71 | $this->mAction = $request->getVal( 'action' ); |
72 | 72 | |
— | — | @@ -411,89 +411,9 @@ |
412 | 412 | $warning .= '<li>'.wfMsgHtml( 'emptyfile' ).'</li>'; |
413 | 413 | } |
414 | 414 | |
415 | | - global $wgUser; |
416 | | - $sk = $wgUser->getSkin(); |
417 | | - |
418 | | - // Check for uppercase extension. We allow these filenames but check if an image |
419 | | - // with lowercase extension exists already |
420 | | - if ( $finalExt != strtolower( $finalExt ) ) { |
421 | | - $nt_lc = Title::newFromText( $partname . '.' . strtolower( $finalExt ) ); |
422 | | - $image_lc = wfLocalFile( $nt_lc ); |
| 415 | + if ( !$this->mDestWarningAck ) { |
| 416 | + $warning .= self::getExistsWarning( $this->mLocalFile ); |
423 | 417 | } |
424 | | - |
425 | | - if( $this->mLocalFile->exists() ) { |
426 | | - $dlink = $sk->makeKnownLinkObj( $nt ); |
427 | | - if ( $this->mLocalFile->allowInlineDisplay() ) { |
428 | | - $dlink2 = $sk->makeImageLinkObj( $nt, wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), |
429 | | - $nt->getText(), 'right', array(), false, true ); |
430 | | - } elseif ( !$this->mLocalFile->allowInlineDisplay() && $this->mLocalFile->isSafeFile() ) { |
431 | | - $icon = $this->mLocalFile->iconThumb(); |
432 | | - $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $this->mLocalFile->getURL() . '">' . |
433 | | - $icon->toHtml() . '</a><br />' . $dlink . '</div>'; |
434 | | - } else { |
435 | | - $dlink2 = ''; |
436 | | - } |
437 | | - |
438 | | - $warning .= '<li>' . wfMsgExt( 'fileexists', 'parseline', $dlink ) . '</li>' . $dlink2; |
439 | | - |
440 | | - } elseif ( isset( $image_lc) && $image_lc->exists() ) { |
441 | | - # Check if image with lowercase extension exists. |
442 | | - # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension |
443 | | - $dlink = $sk->makeKnownLinkObj( $nt_lc ); |
444 | | - if ( $image_lc->allowInlineDisplay() ) { |
445 | | - $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), |
446 | | - $nt_lc->getText(), 'right', array(), false, true ); |
447 | | - } elseif ( !$image_lc->allowInlineDisplay() && $image_lc->isSafeFile() ) { |
448 | | - $icon = $image_lc->iconThumb(); |
449 | | - $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $image_lc->getURL() . '">' . |
450 | | - $icon->toHtml() . '</a><br />' . $dlink . '</div>'; |
451 | | - } else { |
452 | | - $dlink2 = ''; |
453 | | - } |
454 | | - |
455 | | - $warning .= '<li>' . wfMsgExt( 'fileexists-extension', 'parsemag' , $partname . '.' |
456 | | - . $finalExt , $dlink ) . '</li>' . $dlink2; |
457 | | - |
458 | | - } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' ) |
459 | | - && ereg( "[0-9]{2}" , substr( $partname , 0, 2) ) ) |
460 | | - { |
461 | | - # Check for filenames like 50px- or 180px-, these are mostly thumbnails |
462 | | - $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $finalExt ); |
463 | | - $image_thb = wfLocalFile( $nt_thb ); |
464 | | - if ($image_thb->exists() ) { |
465 | | - # Check if an image without leading '180px-' (or similiar) exists |
466 | | - $dlink = $sk->makeKnownLinkObj( $nt_thb); |
467 | | - if ( $image_thb->allowInlineDisplay() ) { |
468 | | - $dlink2 = $sk->makeImageLinkObj( $nt_thb, |
469 | | - wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), |
470 | | - $nt_thb->getText(), 'right', array(), false, true ); |
471 | | - } elseif ( !$image_thb->allowInlineDisplay() && $image_thb->isSafeFile() ) { |
472 | | - $icon = $image_thb->iconThumb(); |
473 | | - $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . |
474 | | - $image_thb->getURL() . '">' . $icon->toHtml() . '</a><br />' . |
475 | | - $dlink . '</div>'; |
476 | | - } else { |
477 | | - $dlink2 = ''; |
478 | | - } |
479 | | - |
480 | | - $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) . |
481 | | - '</li>' . $dlink2; |
482 | | - } else { |
483 | | - # Image w/o '180px-' does not exists, but we do not like these filenames |
484 | | - $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' , |
485 | | - substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>'; |
486 | | - } |
487 | | - } |
488 | | - if ( $this->mLocalFile->wasDeleted() ) { |
489 | | - # If the file existed before and was deleted, warn the user of this |
490 | | - # Don't bother doing so if the image exists now, however |
491 | | - $ltitle = SpecialPage::getTitleFor( 'Log' ); |
492 | | - $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ), |
493 | | - 'type=delete&page=' . $nt->getPrefixedUrl() ); |
494 | | - $warning .= wfOpenElement( 'li' ) . wfMsgWikiHtml( 'filewasdeleted', $llink ) . |
495 | | - wfCloseElement( 'li' ); |
496 | | - } |
497 | | - |
498 | 418 | if( $warning != '' ) { |
499 | 419 | /** |
500 | 420 | * Stash the file in a temporary location; the user can choose |
— | — | @@ -519,17 +439,124 @@ |
520 | 440 | global $wgUser; |
521 | 441 | $wgUser->addWatch( $this->mLocalFile->getTitle() ); |
522 | 442 | } |
523 | | - if ( $status === '' ) { |
524 | | - // New upload, redirect to description page |
525 | | - $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() ); |
| 443 | + // Success, redirect to description page |
| 444 | + $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() ); |
| 445 | + wfRunHooks( 'UploadComplete', array( &$img ) ); |
| 446 | + } |
| 447 | + } |
| 448 | + |
| 449 | + /** |
| 450 | + * Do existence checks on a file and produce a warning |
| 451 | + * This check is static and can be done pre-upload via AJAX |
| 452 | + * Returns an HTML fragment consisting of one or more LI elements if there is a warning |
| 453 | + * Returns an empty string if there is no warning |
| 454 | + */ |
| 455 | + static function getExistsWarning( $file ) { |
| 456 | + global $wgUser; |
| 457 | + // Check for uppercase extension. We allow these filenames but check if an image |
| 458 | + // with lowercase extension exists already |
| 459 | + $warning = ''; |
| 460 | + $ext = $file->getExtension(); |
| 461 | + $sk = $wgUser->getSkin(); |
| 462 | + if ( $ext !== '' ) { |
| 463 | + $partname = substr( $file->getName(), 0, -strlen( $ext ) - 1 ); |
| 464 | + } else { |
| 465 | + $partname = $file->getName(); |
| 466 | + } |
| 467 | + |
| 468 | + if ( $ext != strtolower( $ext ) ) { |
| 469 | + $nt_lc = Title::newFromText( $partname . '.' . strtolower( $ext ) ); |
| 470 | + $file_lc = wfLocalFile( $nt_lc ); |
| 471 | + } else { |
| 472 | + $file_lc = false; |
| 473 | + } |
| 474 | + |
| 475 | + if( $file->exists() ) { |
| 476 | + $dlink = $sk->makeKnownLinkObj( $file->getTitle() ); |
| 477 | + if ( $file->allowInlineDisplay() ) { |
| 478 | + $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), |
| 479 | + $file->getName(), 'right', array(), false, true ); |
| 480 | + } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) { |
| 481 | + $icon = $file->iconThumb(); |
| 482 | + $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $file->getURL() . '">' . |
| 483 | + $icon->toHtml() . '</a><br />' . $dlink . '</div>'; |
526 | 484 | } else { |
527 | | - // Reupload, show success page |
528 | | - $this->showSuccess(); |
| 485 | + $dlink2 = ''; |
529 | 486 | } |
530 | | - wfRunHooks( 'UploadComplete', array( &$img ) ); |
| 487 | + |
| 488 | + $warning .= '<li>' . wfMsgExt( 'fileexists', 'parseline', $dlink ) . '</li>' . $dlink2; |
| 489 | + |
| 490 | + } elseif ( $file_lc && $file_lc->exists() ) { |
| 491 | + # Check if image with lowercase extension exists. |
| 492 | + # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension |
| 493 | + $dlink = $sk->makeKnownLinkObj( $nt_lc ); |
| 494 | + if ( $file_lc->allowInlineDisplay() ) { |
| 495 | + $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), |
| 496 | + $nt_lc->getText(), 'right', array(), false, true ); |
| 497 | + } elseif ( !$file_lc->allowInlineDisplay() && $file_lc->isSafeFile() ) { |
| 498 | + $icon = $file_lc->iconThumb(); |
| 499 | + $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $file_lc->getURL() . '">' . |
| 500 | + $icon->toHtml() . '</a><br />' . $dlink . '</div>'; |
| 501 | + } else { |
| 502 | + $dlink2 = ''; |
| 503 | + } |
| 504 | + |
| 505 | + $warning .= '<li>' . wfMsgExt( 'fileexists-extension', 'parsemag' , $partname . '.' |
| 506 | + . $ext , $dlink ) . '</li>' . $dlink2; |
| 507 | + |
| 508 | + } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' ) |
| 509 | + && ereg( "[0-9]{2}" , substr( $partname , 0, 2) ) ) |
| 510 | + { |
| 511 | + # Check for filenames like 50px- or 180px-, these are mostly thumbnails |
| 512 | + $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $ext ); |
| 513 | + $file_thb = wfLocalFile( $nt_thb ); |
| 514 | + if ($file_thb->exists() ) { |
| 515 | + # Check if an image without leading '180px-' (or similiar) exists |
| 516 | + $dlink = $sk->makeKnownLinkObj( $nt_thb); |
| 517 | + if ( $file_thb->allowInlineDisplay() ) { |
| 518 | + $dlink2 = $sk->makeImageLinkObj( $nt_thb, |
| 519 | + wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), |
| 520 | + $nt_thb->getText(), 'right', array(), false, true ); |
| 521 | + } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) { |
| 522 | + $icon = $file_thb->iconThumb(); |
| 523 | + $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . |
| 524 | + $file_thb->getURL() . '">' . $icon->toHtml() . '</a><br />' . |
| 525 | + $dlink . '</div>'; |
| 526 | + } else { |
| 527 | + $dlink2 = ''; |
| 528 | + } |
| 529 | + |
| 530 | + $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) . |
| 531 | + '</li>' . $dlink2; |
| 532 | + } else { |
| 533 | + # Image w/o '180px-' does not exists, but we do not like these filenames |
| 534 | + $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' , |
| 535 | + substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>'; |
| 536 | + } |
531 | 537 | } |
| 538 | + if ( $file->wasDeleted() ) { |
| 539 | + # If the file existed before and was deleted, warn the user of this |
| 540 | + # Don't bother doing so if the image exists now, however |
| 541 | + $ltitle = SpecialPage::getTitleFor( 'Log' ); |
| 542 | + $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ), |
| 543 | + 'type=delete&page=' . $file->getTitle()->getPrefixedUrl() ); |
| 544 | + $warning .= '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>'; |
| 545 | + } |
| 546 | + return $warning; |
532 | 547 | } |
533 | 548 | |
| 549 | + static function ajaxGetExistsWarning( $filename ) { |
| 550 | + $file = wfFindFile( $filename ); |
| 551 | + $s = ' '; |
| 552 | + if ( $file ) { |
| 553 | + $warning = self::getExistsWarning( $file ); |
| 554 | + if ( $warning !== '' ) { |
| 555 | + $s = "<ul>$warning</ul>"; |
| 556 | + } |
| 557 | + } |
| 558 | + return $s; |
| 559 | + } |
| 560 | + |
534 | 561 | /** |
535 | 562 | * Stash a file in a temporary directory for later processing |
536 | 563 | * after the user has confirmed it. |
— | — | @@ -602,24 +629,6 @@ |
603 | 630 | /* -------------------------------------------------------------- */ |
604 | 631 | |
605 | 632 | /** |
606 | | - * Show some text and linkage on successful upload. |
607 | | - * @access private |
608 | | - */ |
609 | | - function showSuccess() { |
610 | | - global $wgUser, $wgOut, $wgContLang; |
611 | | - |
612 | | - $sk = $wgUser->getSkin(); |
613 | | - $ilink = $sk->makeMediaLinkObj( $this->mLocalFile->getTitle() ); |
614 | | - $dname = $wgContLang->getNsText( NS_IMAGE ) . ':'.$this->mDestName; |
615 | | - $dlink = $sk->makeKnownLink( $dname, $dname ); |
616 | | - |
617 | | - $wgOut->addHTML( '<h2>' . wfMsgHtml( 'successfulupload' ) . "</h2>\n" ); |
618 | | - $text = wfMsgWikiHtml( 'fileuploaded', $ilink, $dlink ); |
619 | | - $wgOut->addHTML( $text ); |
620 | | - $wgOut->returnToMain( false ); |
621 | | - } |
622 | | - |
623 | | - /** |
624 | 633 | * @param string $error as HTML |
625 | 634 | * @access private |
626 | 635 | */ |
— | — | @@ -703,9 +712,16 @@ |
704 | 713 | */ |
705 | 714 | function mainUploadForm( $msg='' ) { |
706 | 715 | global $wgOut, $wgUser; |
707 | | - global $wgUseCopyrightUpload; |
708 | | - global $wgRequest, $wgAllowCopyUploads; |
| 716 | + global $wgUseCopyrightUpload, $wgAjaxUploadDestCheck; |
| 717 | + global $wgRequest, $wgAllowCopyUploads, $wgEnableAPI; |
| 718 | + global $wgStylePath; |
709 | 719 | |
| 720 | + $wgOut->addScript( |
| 721 | + "<script type='text/javascript'>wgAjaxUploadDestCheck = " . |
| 722 | + ($wgAjaxUploadDestCheck ? 'true' : 'false' ) . ";</script>\n" . |
| 723 | + "<script type='text/javascript' src=\"$wgStylePath/common/upload.js?1\"></script>\n" |
| 724 | + ); |
| 725 | + |
710 | 726 | if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) ) |
711 | 727 | { |
712 | 728 | wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" ); |
— | — | @@ -776,6 +792,14 @@ |
777 | 793 | "size='40' />" . |
778 | 794 | "<input type='hidden' name='wpSourceType' value='file' />" ; |
779 | 795 | } |
| 796 | + if ( $wgAjaxUploadDestCheck ) { |
| 797 | + $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>"; |
| 798 | + $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"'; |
| 799 | + } else { |
| 800 | + $warningRow = ''; |
| 801 | + $destOnkeyup = ''; |
| 802 | + } |
| 803 | + |
780 | 804 | $encComment = htmlspecialchars( $this->mComment ); |
781 | 805 | |
782 | 806 | $wgOut->addHTML( <<<EOT |
— | — | @@ -791,7 +815,8 @@ |
792 | 816 | <tr> |
793 | 817 | <td align='right'><label for='wpDestFile'>{$destfilename}:</label></td> |
794 | 818 | <td align='left'> |
795 | | - <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' value="$encDestName" onkeyup="checkFileExists();" /> |
| 819 | + <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' |
| 820 | + value="$encDestName" $destOnkeyup /> |
796 | 821 | </td> |
797 | 822 | </tr> |
798 | 823 | <tr> |
— | — | @@ -811,7 +836,6 @@ |
812 | 837 | $wgOut->addHTML( " |
813 | 838 | <td align='right'><label for='wpLicense'>$license:</label></td> |
814 | 839 | <td align='left'> |
815 | | - <script type='text/javascript' src=\"$wgStylePath/common/upload.js\"></script> |
816 | 840 | <select name='wpLicense' id='wpLicense' tabindex='4' |
817 | 841 | onchange='licenseSelectorCheck()'> |
818 | 842 | <option value=''>$nolicense</option> |
— | — | @@ -843,7 +867,6 @@ |
844 | 868 | "); |
845 | 869 | } |
846 | 870 | |
847 | | - |
848 | 871 | $wgOut->addHtml( " |
849 | 872 | <td></td> |
850 | 873 | <td> |
— | — | @@ -853,11 +876,11 @@ |
854 | 877 | <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label> |
855 | 878 | </td> |
856 | 879 | </tr> |
| 880 | + $warningRow |
857 | 881 | <tr> |
858 | 882 | <td></td> |
859 | 883 | <td align='left'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td> |
860 | 884 | </tr> |
861 | | - |
862 | 885 | <tr> |
863 | 886 | <td></td> |
864 | 887 | <td align='left'> |
— | — | @@ -868,6 +891,7 @@ |
869 | 892 | </tr> |
870 | 893 | |
871 | 894 | </table> |
| 895 | + <input type='hidden' name='wpDestFileWarningAck' id='wpDestFileWarningAck' value=''/> |
872 | 896 | </form>" ); |
873 | 897 | } |
874 | 898 | |