New javascript for upload page that will show a warning if a file with the "destinati...
authorMagnus Manske <magnusmanske@users.mediawiki.org>
Sun, 1 Jul 2007 13:26:57 +0000 (13:26 +0000)
committerMagnus Manske <magnusmanske@users.mediawiki.org>
Sun, 1 Jul 2007 13:26:57 +0000 (13:26 +0000)
RELEASE-NOTES
includes/SpecialUpload.php
skins/common/wikibits.js

index 0a681da..1185fbb 100644 (file)
@@ -114,6 +114,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   Patch by Edward Z. Yang.
 * Introduce 'ShowRawCssJs' hook; see docs/hooks.txt for more information
 * (bug 10404) Show rights log fragment for the selected user in Special:Userrights
+* New javascript for upload page that will show a warning if a file with the "destination filename" already exists.
 
 == Bugfixes since 1.10 ==
 
index 28cd820..2922d15 100644 (file)
@@ -791,7 +791,7 @@ 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" />
+                               <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' value="$encDestName" onkeyup="checkFileExists();" />
                        </td>
                </tr>
                <tr>
index 4961127..7cbe003 100644 (file)
@@ -766,6 +766,41 @@ 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 ;
+//  thetd.innerHTML += url ;
+  thetd.innerHTML += "<span id='existsWarning' style='color:red'> A file with this name already exists; uploading under the same name will replace it!</span>" ;
+  
+  // Restore the filename
+  var destFile = document.getElementById('wpDestFile');
+  destFile.value = fname;
+}
+
 function fillDestFilename(id) {
        if (!document.getElementById) {
                return;
@@ -790,6 +825,7 @@ function fillDestFilename(id) {
        var destFile = document.getElementById('wpDestFile');
        if (destFile) {
                destFile.value = fname;
+               checkFileExists () ;
        }
 }