* De-crappified JS upload dest check feature. Converted to sajax framework. Comprehen...
authorTim Starling <tstarling@users.mediawiki.org>
Sun, 1 Jul 2007 18:24:47 +0000 (18:24 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sun, 1 Jul 2007 18:24:47 +0000 (18:24 +0000)
* Added support for static member functions as AJAX callbacks.
* Moved all upload-related javascript to upload.js.
* Needs artwork, see TODO in upload.js.
* Removed UploadForm::showSuccess() as per wikitech-l discussion. Redirect to description page unconditionally.

includes/AjaxDispatcher.php
includes/Setup.php
includes/SpecialUpload.php
skins/common/upload.js
skins/common/wikibits.js

index 452c3b3..7b85ed2 100644 (file)
@@ -84,8 +84,13 @@ class AjaxDispatcher {
                        wfHttpError( 400, 'Bad Request',
                                "unknown function " . (string) $this->func_name );
                } else {
+                       if ( strpos( $this->func_name, '::' ) !== false ) {
+                               $func = explode( '::', $this->func_name, 2 );
+                       } else {
+                               $func = $this->func_name;
+                       }
                        try {
-                               $result = call_user_func_array($this->func_name, $this->args);
+                               $result = call_user_func_array($func, $this->args);
 
                                if ( $result === false || $result === NULL ) {
                                        wfHttpError( 500, 'Internal Error',
index 9e70747..5a20b86 100644 (file)
@@ -257,6 +257,7 @@ $wgPostCommitUpdateList = array();
 
 if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
+if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
 
 wfSeedRandom();
 
index 2922d15..85579f3 100644 (file)
@@ -26,7 +26,7 @@ class UploadForm {
        var $mDestName, $mTempPath, $mFileSize, $mFileProps;
        var $mCopyrightStatus, $mCopyrightSource, $mReUpload, $mAction, $mUploadClicked;
        var $mSrcName, $mSessionKey, $mStashed, $mDesiredDestName, $mRemoveTempFile, $mSourceType;
-       var $mCurlDestHandle;
+       var $mDestWarningAck, $mCurlDestHandle;
        var $mLocalFile;
 
        # Placeholders for text injection by hooks (must be HTML)
@@ -65,7 +65,7 @@ class UploadForm {
                $this->mCopyrightSource   = $request->getText( 'wpUploadSource' );
                $this->mWatchthis         = $request->getBool( 'wpWatchthis' );
                $this->mSourceType        = $request->getText( 'wpSourceType' );
-               wfDebug( "UploadForm: watchthis is: '$this->mWatchthis'\n" );
+               $this->mDestWarningAck    = $request->getText( 'wpDestFileWarningAck' );
 
                $this->mAction            = $request->getVal( 'action' );
 
@@ -411,89 +411,9 @@ class UploadForm {
                                $warning .= '<li>'.wfMsgHtml( 'emptyfile' ).'</li>';
                        }
 
-                       global $wgUser;
-                       $sk = $wgUser->getSkin();
-
-                       // Check for uppercase extension. We allow these filenames but check if an image
-                       // with lowercase extension exists already
-                       if ( $finalExt != strtolower( $finalExt ) ) {
-                               $nt_lc = Title::newFromText( $partname . '.' . strtolower( $finalExt ) );
-                               $image_lc = wfLocalFile( $nt_lc );
-                       }
-
-                       if( $this->mLocalFile->exists() ) {
-                               $dlink = $sk->makeKnownLinkObj( $nt );
-                               if ( $this->mLocalFile->allowInlineDisplay() ) {
-                                       $dlink2 = $sk->makeImageLinkObj( $nt, wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
-                                               $nt->getText(), 'right', array(), false, true );
-                               } elseif ( !$this->mLocalFile->allowInlineDisplay() && $this->mLocalFile->isSafeFile() ) {
-                                       $icon = $this->mLocalFile->iconThumb();
-                                       $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $this->mLocalFile->getURL() . '">' . 
-                                               $icon->toHtml() . '</a><br />' . $dlink . '</div>';
-                               } else {
-                                       $dlink2 = '';
-                               }
-
-                               $warning .= '<li>' . wfMsgExt( 'fileexists', 'parseline', $dlink ) . '</li>' . $dlink2;
-
-                       } elseif ( isset( $image_lc) && $image_lc->exists() ) {
-                               # Check if image with lowercase extension exists.
-                               # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
-                               $dlink = $sk->makeKnownLinkObj( $nt_lc );
-                               if ( $image_lc->allowInlineDisplay() ) {
-                                       $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
-                                               $nt_lc->getText(), 'right', array(), false, true );
-                               } elseif ( !$image_lc->allowInlineDisplay() && $image_lc->isSafeFile() ) {
-                                       $icon = $image_lc->iconThumb();
-                                       $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $image_lc->getURL() . '">' . 
-                                               $icon->toHtml() . '</a><br />' . $dlink . '</div>';
-                               } else {
-                                       $dlink2 = '';
-                               }
-
-                               $warning .= '<li>' . wfMsgExt( 'fileexists-extension', 'parsemag' , $partname . '.' 
-                                       . $finalExt , $dlink ) . '</li>' . $dlink2;                             
-
-                       } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' ) 
-                               && ereg( "[0-9]{2}" , substr( $partname , 0, 2) ) )
-                       {
-                               # Check for filenames like 50px- or 180px-, these are mostly thumbnails
-                               $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $finalExt );
-                               $image_thb = wfLocalFile( $nt_thb );
-                               if ($image_thb->exists() ) {
-                                       # Check if an image without leading '180px-' (or similiar) exists
-                                       $dlink = $sk->makeKnownLinkObj( $nt_thb);
-                                       if ( $image_thb->allowInlineDisplay() ) {
-                                               $dlink2 = $sk->makeImageLinkObj( $nt_thb, 
-                                                       wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
-                                                       $nt_thb->getText(), 'right', array(), false, true );
-                                       } elseif ( !$image_thb->allowInlineDisplay() && $image_thb->isSafeFile() ) {
-                                               $icon = $image_thb->iconThumb();
-                                               $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . 
-                                                       $image_thb->getURL() . '">' . $icon->toHtml() . '</a><br />' . 
-                                                       $dlink . '</div>';
-                                       } else {
-                                               $dlink2 = '';
-                                       }
-
-                                       $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) . 
-                                               '</li>' . $dlink2;      
-                               } else {
-                                       # Image w/o '180px-' does not exists, but we do not like these filenames
-                                       $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' , 
-                                               substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>';
-                               }
-                       }
-                       if ( $this->mLocalFile->wasDeleted() ) {
-                               # If the file existed before and was deleted, warn the user of this
-                               # Don't bother doing so if the image exists now, however
-                               $ltitle = SpecialPage::getTitleFor( 'Log' );
-                               $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ), 
-                                       'type=delete&page=' . $nt->getPrefixedUrl() );
-                               $warning .= wfOpenElement( 'li' ) . wfMsgWikiHtml( 'filewasdeleted', $llink ) . 
-                                       wfCloseElement( 'li' );
+                       if ( !$this->mDestWarningAck ) {
+                               $warning .= self::getExistsWarning( $this->mLocalFile );
                        }
-
                        if( $warning != '' ) {
                                /**
                                 * Stash the file in a temporary location; the user can choose
@@ -519,15 +439,122 @@ class UploadForm {
                                global $wgUser;
                                $wgUser->addWatch( $this->mLocalFile->getTitle() );
                        }
-                       if ( $status === '' ) {
-                               // New upload, redirect to description page
-                               $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
+                       // Success, redirect to description page
+                       $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
+                       wfRunHooks( 'UploadComplete', array( &$img ) );
+               }
+       }
+
+       /**
+        * Do existence checks on a file and produce a warning
+        * This check is static and can be done pre-upload via AJAX
+        * Returns an HTML fragment consisting of one or more LI elements if there is a warning
+        * Returns an empty string if there is no warning
+        */
+       static function getExistsWarning( $file ) {
+               global $wgUser;
+               // Check for uppercase extension. We allow these filenames but check if an image
+               // with lowercase extension exists already
+               $warning = '';
+               $ext = $file->getExtension();
+               $sk = $wgUser->getSkin();
+               if ( $ext !== '' ) {
+                       $partname = substr( $file->getName(), 0, -strlen( $ext ) - 1 );
+               } else {
+                       $partname = $file->getName();
+               }
+
+               if ( $ext != strtolower( $ext ) ) {
+                       $nt_lc = Title::newFromText( $partname . '.' . strtolower( $ext ) );
+                       $file_lc = wfLocalFile( $nt_lc );
+               } else {
+                       $file_lc = false;
+               }
+
+               if( $file->exists() ) {
+                       $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
+                       if ( $file->allowInlineDisplay() ) {
+                               $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
+                                       $file->getName(), 'right', array(), false, true );
+                       } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
+                               $icon = $file->iconThumb();
+                               $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $file->getURL() . '">' . 
+                                       $icon->toHtml() . '</a><br />' . $dlink . '</div>';
                        } else {
-                               // Reupload, show success page
-                               $this->showSuccess();
+                               $dlink2 = '';
+                       }
+
+                       $warning .= '<li>' . wfMsgExt( 'fileexists', 'parseline', $dlink ) . '</li>' . $dlink2;
+
+               } elseif ( $file_lc && $file_lc->exists() ) {
+                       # Check if image with lowercase extension exists.
+                       # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
+                       $dlink = $sk->makeKnownLinkObj( $nt_lc );
+                       if ( $file_lc->allowInlineDisplay() ) {
+                               $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
+                                       $nt_lc->getText(), 'right', array(), false, true );
+                       } elseif ( !$file_lc->allowInlineDisplay() && $file_lc->isSafeFile() ) {
+                               $icon = $file_lc->iconThumb();
+                               $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . $file_lc->getURL() . '">' . 
+                                       $icon->toHtml() . '</a><br />' . $dlink . '</div>';
+                       } else {
+                               $dlink2 = '';
+                       }
+
+                       $warning .= '<li>' . wfMsgExt( 'fileexists-extension', 'parsemag' , $partname . '.' 
+                               . $ext , $dlink ) . '</li>' . $dlink2;                          
+
+               } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' ) 
+                       && ereg( "[0-9]{2}" , substr( $partname , 0, 2) ) )
+               {
+                       # Check for filenames like 50px- or 180px-, these are mostly thumbnails
+                       $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $ext );
+                       $file_thb = wfLocalFile( $nt_thb );
+                       if ($file_thb->exists() ) {
+                               # Check if an image without leading '180px-' (or similiar) exists
+                               $dlink = $sk->makeKnownLinkObj( $nt_thb);
+                               if ( $file_thb->allowInlineDisplay() ) {
+                                       $dlink2 = $sk->makeImageLinkObj( $nt_thb, 
+                                               wfMsgExt( 'fileexists-thumb', 'parseinline', $dlink ), 
+                                               $nt_thb->getText(), 'right', array(), false, true );
+                               } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) {
+                                       $icon = $file_thb->iconThumb();
+                                       $dlink2 = '<div style="float:right" id="mw-media-icon"><a href="' . 
+                                               $file_thb->getURL() . '">' . $icon->toHtml() . '</a><br />' . 
+                                               $dlink . '</div>';
+                               } else {
+                                       $dlink2 = '';
+                               }
+
+                               $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) . 
+                                       '</li>' . $dlink2;      
+                       } else {
+                               # Image w/o '180px-' does not exists, but we do not like these filenames
+                               $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' , 
+                                       substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>';
                        }
-                       wfRunHooks( 'UploadComplete', array( &$img ) );
                }
+               if ( $file->wasDeleted() ) {
+                       # If the file existed before and was deleted, warn the user of this
+                       # Don't bother doing so if the image exists now, however
+                       $ltitle = SpecialPage::getTitleFor( 'Log' );
+                       $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ), 
+                               'type=delete&page=' . $file->getTitle()->getPrefixedUrl() );
+                       $warning .= '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
+               }
+               return $warning;
+       }
+
+       static function ajaxGetExistsWarning( $filename ) {
+               $file = wfFindFile( $filename );
+               $s = '&nbsp;';
+               if ( $file ) {
+                       $warning = self::getExistsWarning( $file );
+                       if ( $warning !== '' ) {
+                               $s = "<ul>$warning</ul>";
+                       }
+               }
+               return $s;
        }
 
        /**
@@ -601,24 +628,6 @@ class UploadForm {
 
        /* -------------------------------------------------------------- */
 
-       /**
-        * Show some text and linkage on successful upload.
-        * @access private
-        */
-       function showSuccess() {
-               global $wgUser, $wgOut, $wgContLang;
-
-               $sk = $wgUser->getSkin();
-               $ilink = $sk->makeMediaLinkObj( $this->mLocalFile->getTitle() );
-               $dname = $wgContLang->getNsText( NS_IMAGE ) . ':'.$this->mDestName;
-               $dlink = $sk->makeKnownLink( $dname, $dname );
-
-               $wgOut->addHTML( '<h2>' . wfMsgHtml( 'successfulupload' ) . "</h2>\n" );
-               $text = wfMsgWikiHtml( 'fileuploaded', $ilink, $dlink );
-               $wgOut->addHTML( $text );
-               $wgOut->returnToMain( false );
-       }
-
        /**
         * @param string $error as HTML
         * @access private
@@ -703,8 +712,15 @@ class UploadForm {
         */
        function mainUploadForm( $msg='' ) {
                global $wgOut, $wgUser;
-               global $wgUseCopyrightUpload;
-               global $wgRequest, $wgAllowCopyUploads;
+               global $wgUseCopyrightUpload, $wgAjaxUploadDestCheck;
+               global $wgRequest, $wgAllowCopyUploads, $wgEnableAPI;
+               global $wgStylePath;
+
+               $wgOut->addScript( 
+                       "<script type='text/javascript'>wgAjaxUploadDestCheck = " . 
+                               ($wgAjaxUploadDestCheck ? 'true' : 'false' ) . ";</script>\n" . 
+                       "<script type='text/javascript' src=\"$wgStylePath/common/upload.js?1\"></script>\n" 
+               );
 
                if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
                {
@@ -776,6 +792,14 @@ class UploadForm {
                                "size='40' />" .
                                "<input type='hidden' name='wpSourceType' value='file' />" ;
                }
+               if ( $wgAjaxUploadDestCheck ) {
+                       $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'>&nbsp</td></tr>";
+                       $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
+               } else {
+                       $warningRow = '';
+                       $destOnkeyup = '';
+               }
+
                $encComment = htmlspecialchars( $this->mComment );
 
                $wgOut->addHTML( <<<EOT
@@ -791,7 +815,8 @@ class UploadForm {
                <tr>
                        <td align='right'><label for='wpDestFile'>{$destfilename}:</label></td>
                        <td align='left'>
-                               <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' value="$encDestName" onkeyup="checkFileExists();" />
+                               <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' 
+                                       value="$encDestName" $destOnkeyup />
                        </td>
                </tr>
                <tr>
@@ -811,7 +836,6 @@ EOT
                        $wgOut->addHTML( "
                        <td align='right'><label for='wpLicense'>$license:</label></td>
                        <td align='left'>
-                               <script type='text/javascript' src=\"$wgStylePath/common/upload.js\"></script>
                                <select name='wpLicense' id='wpLicense' tabindex='4'
                                        onchange='licenseSelectorCheck()'>
                                        <option value=''>$nolicense</option>
@@ -843,7 +867,6 @@ EOT
                ");
                }
 
-
                $wgOut->addHtml( "
                <td></td>
                <td>
@@ -853,11 +876,11 @@ EOT
                        <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
                </td>
        </tr>
+       $warningRow
        <tr>
                <td></td>
                <td align='left'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
        </tr>
-
        <tr>
                <td></td>
                <td align='left'>
@@ -868,6 +891,7 @@ EOT
        </tr>
 
        </table>
+       <input type='hidden' name='wpDestFileWarningAck' id='wpDestFileWarningAck' value=''/>
        </form>" );
        }
 
index 160fbf2..7c66e6d 100644 (file)
@@ -11,11 +11,123 @@ function licenseSelectorFixup() {
        // for MSIE/Mac; non-breaking spaces cause the <option> not to render
        // but, for some reason, setting the text to itself works
        var selector = document.getElementById("wpLicense");
-       var ua = navigator.userAgent;
-       var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1);
-       if (isMacIe) {
-               for (var i = 0; i < selector.options.length; i++) {
-                       selector.options[i].text = selector.options[i].text;
+       if (selector) {
+               var ua = navigator.userAgent;
+               var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1);
+               if (isMacIe) {
+                       for (var i = 0; i < selector.options.length; i++) {
+                               selector.options[i].text = selector.options[i].text;
+                       }
+               }
+       }
+}
+
+var wgUploadWarningObj = {
+       'responseCache' : { '' : '&nbsp;' },
+       'nameToCheck' : '',
+       'typing': false,
+       'delay': 500, // ms
+       'timeoutID': false,
+
+       'keypress': function () {
+               // Find file to upload
+               var destFile = document.getElementById('wpDestFile');
+               var warningElt = document.getElementById( 'wpDestFile-warning' );
+               if ( !destFile || !warningElt ) return ;
+
+               this.nameToCheck = destFile.value ;
+
+               // Clear timer 
+               if ( this.timeoutID ) {
+                       window.clearTimeout( this.timeoutID );
+               }
+               // Check response cache
+               if ( this.nameToCheck in this.responseCache ) {
+                       this.setWarning(this.responseCache[this.nameToCheck]);
+                       return;
+               }
+
+               this.setInnerHTML(warningElt, '..'); // TODO: pretty animated GIF
+               this.timeoutID = window.setTimeout( 'wgUploadWarningObj.timeout()', this.delay );
+       },
+
+       'checkNow': function (fname) {
+               if ( this.timeoutID ) {
+                       window.clearTimeout( this.timeoutID );
+               }
+               this.nameToCheck = fname;
+               this.timeout();
+       },
+       
+       'timeout' : function() {
+               var warningElt = document.getElementById( 'wpDestFile-warning' );
+               this.setInnerHTML(warningElt, '....'); // TODO: pretty animated GIF
+
+               // Get variables into local scope so that they will be preserved for the 
+               // anonymous callback. fileName is copied so that multiple overlapping 
+               // ajax requests can be supported.
+               var obj = this;
+               var fileName = this.nameToCheck;
+               sajax_do_call( 'UploadForm::ajaxGetExistsWarning', [this.nameToCheck], 
+                       function (result) {
+                               obj.processResult(result, fileName)
+                       }
+               );
+       },
+
+       'processResult' : function (result, fileName) {
+               this.setWarning(result.responseText);
+               this.responseCache[fileName] = result.responseText;
+       },
+
+       'setWarning' : function (warning) {
+               var warningElt = document.getElementById( 'wpDestFile-warning' );
+               var ackElt = document.getElementById( 'wpDestFileWarningAck' );
+               this.setInnerHTML(warningElt, warning);
+
+               // Set a value in the form indicating that the warning is acknowledged and 
+               // doesn't need to be redisplayed post-upload
+               if ( warning == '' || warning == '&nbsp' ) {
+                       ackElt.value = '';
+               } else {
+                       ackElt.value = '1';
+               }
+       },
+
+       'setInnerHTML' : function (element, text) {
+               // Check for no change to avoid flicker in IE 7
+               if (element.innerHTML != text) {
+                       element.innerHTML = text;
+               }
+       }
+}
+
+function fillDestFilename(id) {
+       if (!document.getElementById) {
+               return;
+       }
+       var path = document.getElementById(id).value;
+       // Find trailing part
+       var slash = path.lastIndexOf('/');
+       var backslash = path.lastIndexOf('\\');
+       var fname;
+       if (slash == -1 && backslash == -1) {
+               fname = path;
+       } else if (slash > backslash) {
+               fname = path.substring(slash+1, 10000);
+       } else {
+               fname = path.substring(backslash+1, 10000);
+       }
+
+       // Capitalise first letter and replace spaces by underscores
+       fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
+
+       // Output result
+       var destFile = document.getElementById('wpDestFile');
+       if (destFile) {
+               destFile.value = fname;
+               if ( wgAjaxUploadDestCheck ) {
+                       wgUploadWarningObj.checkNow(fname) ;
                }
        }
 }
index a496e24..d7b19c4 100644 (file)
@@ -766,73 +766,6 @@ function toggle_element_check(ida,idb) {
        document.getElementById(idb).checked=false;
 }
 
-var lastFileChecked = "" ;
-function checkFileExists () {
-  // Find file to upload
-       var destFile = document.getElementById('wpDestFile');
-       if ( !destFile ) return ;
-       fname = destFile.value ;
-       
-       if ( fname == lastFileChecked ) return ;
-       lastFileChecked = fname ;
-       
-       // Delete old warning, if any
-  var existsWarning = document.getElementById('existsWarning');
-  if ( existsWarning ) {
-    var pn = existsWarning.parentNode ;
-    pn.removeChild ( existsWarning ) ;
-  }
-  
-  // Check for existence
-  var url = wgServer + wgScriptPath + "/api.php?action=query&prop=info&format=xml&titles=Image:" + fname ;
-  var xmlHttp = new XMLHttpRequest();
-  xmlHttp.open('GET', url, false);
-  xmlHttp.send(null);  
-  var text = xmlHttp.responseText ;
-  if ( text.split(" pageid=").length < 2 ) return ; // Page doesn'exist (test is quicker than XML parsing, so...)
-  
-  // Set warning
-  var thetd = destFile.parentNode ;
-  var nn = document.createElement("span") ;
-  nn.id = "existsWarning" ;
-  nn.style.color = "red" ;
-  var nt = document.createTextNode(" A file with this name already exists; uploading under the same name will replace it!");
-  nn.appendChild ( nt ) ;
-  thetd.appendChild ( nn ) ;
-  
-  // Restore the filename
-  var destFile = document.getElementById('wpDestFile');
-  destFile.value = fname;
-}
-
-function fillDestFilename(id) {
-       if (!document.getElementById) {
-               return;
-       }
-       var path = document.getElementById(id).value;
-       // Find trailing part
-       var slash = path.lastIndexOf('/');
-       var backslash = path.lastIndexOf('\\');
-       var fname;
-       if (slash == -1 && backslash == -1) {
-               fname = path;
-       } else if (slash > backslash) {
-               fname = path.substring(slash+1, 10000);
-       } else {
-               fname = path.substring(backslash+1, 10000);
-       }
-
-       // Capitalise first letter and replace spaces by underscores
-       fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
-
-       // Output result
-       var destFile = document.getElementById('wpDestFile');
-       if (destFile) {
-               destFile.value = fname;
-               checkFileExists () ;
-       }
-}
-
 function scrollEditBox() {
        var editBoxEl = document.getElementById("wpTextbox1");
        var scrollTopEl = document.getElementById("wpScrolltop");