From e67d86ac64f10e2aec83b62b7b68cd5753599dad Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Sun, 1 Jul 2007 13:26:57 +0000 Subject: [PATCH] New javascript for upload page that will show a warning if a file with the "destination filename" already exists. This uses api.php. As it is only used after someone already specified a file to upload, stress to servers should be minimal. Note that there is a hardcoded English warning text in there; not sure how to i18e it. --- RELEASE-NOTES | 1 + includes/SpecialUpload.php | 2 +- skins/common/wikibits.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 0a681dae39..1185fbba28 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index 28cd820da9..2922d15de7 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -791,7 +791,7 @@ class UploadForm { - + diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index 496112711e..7cbe0038c8 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -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 += " A file with this name already exists; uploading under the same name will replace it!" ; + + // 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 () ; } } -- 2.20.1