r23602 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23601‎ | r23602 | r23603 >
Date:13:26, 1 July 2007
Author:magnusmanske
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/SpecialUpload.php (modified) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/wikibits.js
@@ -766,6 +766,41 @@
767767 document.getElementById(idb).checked=false;
768768 }
769769
 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+// thetd.innerHTML += url ;
 798+ thetd.innerHTML += "<span id='existsWarning' style='color:red'> A file with this name already exists; uploading under the same name will replace it!</span>" ;
 799+
 800+ // Restore the filename
 801+ var destFile = document.getElementById('wpDestFile');
 802+ destFile.value = fname;
 803+}
 804+
770805 function fillDestFilename(id) {
771806 if (!document.getElementById) {
772807 return;
@@ -790,6 +825,7 @@
791826 var destFile = document.getElementById('wpDestFile');
792827 if (destFile) {
793828 destFile.value = fname;
 829+ checkFileExists () ;
794830 }
795831 }
796832
Index: trunk/phase3/includes/SpecialUpload.php
@@ -791,7 +791,7 @@
792792 <tr>
793793 <td align='right'><label for='wpDestFile'>{$destfilename}:</label></td>
794794 <td align='left'>
795 - <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' value="$encDestName" />
 795+ <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' value="$encDestName" onkeyup="checkFileExists();" />
796796 </td>
797797 </tr>
798798 <tr>
Index: trunk/phase3/RELEASE-NOTES
@@ -114,6 +114,7 @@
115115 Patch by Edward Z. Yang.
116116 * Introduce 'ShowRawCssJs' hook; see docs/hooks.txt for more information
117117 * (bug 10404) Show rights log fragment for the selected user in Special:Userrights
 118+* New javascript for upload page that will show a warning if a file with the "destination filename" already exists.
118119
119120 == Bugfixes since 1.10 ==
120121

Follow-up revisions

RevisionCommit summaryAuthorDate
r23662Merged revisions 23581-23661 via svnmerge from...david03:01, 3 July 2007

Status & tagging log