1 function licenseSelectorCheck() {
2 var selector
= document
.getElementById( "wpLicense" );
3 var selection
= selector
.options
[selector
.selectedIndex
].value
;
4 if( selector
.selectedIndex
> 0 ) {
5 if( selection
== "" ) {
6 // Option disabled, but browser is broken and doesn't respect this
7 selector
.selectedIndex
= 0;
10 // We might show a preview
11 wgUploadLicenseObj
.fetchPreview( selection
);
14 function wgUploadSetup() {
15 //disable source type if not checked:
16 var e
= document
.getElementById('wpSourceTypeURL');
19 var ein
= document
.getElementById('wpUploadFileURL');
21 ein
.setAttribute('disabled', 'disabled');
25 // for MSIE/Mac; non-breaking spaces cause the <option> not to render
26 // but, for some reason, setting the text to itself works
27 var selector
= document
.getElementById("wpLicense");
29 var ua
= navigator
.userAgent
;
30 var isMacIe
= (ua
.indexOf("MSIE") != -1) && (ua
.indexOf("Mac") != -1);
32 for (var i
= 0; i
< selector
.options
.length
; i
++) {
33 selector
.options
[i
].text
= selector
.options
[i
].text
;
39 var wgUploadWarningObj
= {
40 'responseCache' : { '' : ' ' },
46 'keypress': function () {
47 if ( !wgAjaxUploadDestCheck
|| !sajax_init_object() ) return;
49 // Find file to upload
50 var destFile
= document
.getElementById('wpDestFile');
51 var warningElt
= document
.getElementById( 'wpDestFile-warning' );
52 if ( !destFile
|| !warningElt
) return ;
54 this.nameToCheck
= destFile
.value
;
57 if ( this.timeoutID
) {
58 window
.clearTimeout( this.timeoutID
);
60 // Check response cache
61 for (cached
in this.responseCache
) {
62 if (this.nameToCheck
== cached
) {
63 this.setWarning(this.responseCache
[this.nameToCheck
]);
68 this.timeoutID
= window
.setTimeout( 'wgUploadWarningObj.timeout()', this.delay
);
71 'checkNow': function (fname
) {
72 if ( !wgAjaxUploadDestCheck
|| !sajax_init_object() ) return;
73 if ( this.timeoutID
) {
74 window
.clearTimeout( this.timeoutID
);
76 this.nameToCheck
= fname
;
80 'timeout' : function() {
81 if ( !wgAjaxUploadDestCheck
|| !sajax_init_object() ) return;
82 injectSpinner( document
.getElementById( 'wpDestFile' ), 'destcheck' );
84 // Get variables into local scope so that they will be preserved for the
85 // anonymous callback. fileName is copied so that multiple overlapping
86 // ajax requests can be supported.
88 var fileName
= this.nameToCheck
;
89 sajax_do_call( 'UploadForm::ajaxGetExistsWarning', [this.nameToCheck
],
91 obj
.processResult(result
, fileName
)
96 'processResult' : function (result
, fileName
) {
97 removeSpinner( 'destcheck' );
98 this.setWarning(result
.responseText
);
99 this.responseCache
[fileName
] = result
.responseText
;
102 'setWarning' : function (warning
) {
103 var warningElt
= document
.getElementById( 'wpDestFile-warning' );
104 var ackElt
= document
.getElementById( 'wpDestFileWarningAck' );
105 this.setInnerHTML(warningElt
, warning
);
107 // Set a value in the form indicating that the warning is acknowledged and
108 // doesn't need to be redisplayed post-upload
109 if ( warning
== '' || warning
== ' ' ) {
115 'setInnerHTML' : function (element
, text
) {
116 // Check for no change to avoid flicker in IE 7
117 if (element
.innerHTML
!= text
) {
118 element
.innerHTML
= text
;
123 function fillDestFilename(id
) {
124 if (!wgUploadAutoFill
) {
127 if (!document
.getElementById
) {
130 //remove any previously flagged errors
131 var e
= document
.getElementById('mw-upload-permitted');
132 if(e
) e
. className
= '';
134 var e
= document
.getElementById('mw-upload-prohibited');
135 if(e
) e
.className
= '';
137 var path
= document
.getElementById(id
).value
;
138 // Find trailing part
139 var slash
= path
.lastIndexOf('/');
140 var backslash
= path
.lastIndexOf('\\');
142 if (slash
== -1 && backslash
== -1) {
144 } else if (slash
> backslash
) {
145 fname
= path
.substring(slash
+1, 10000);
147 fname
= path
.substring(backslash
+1, 10000);
149 //check for the wgFileExtensions and clear if not a valid fname extension
151 //urls are less likely to have a usefull extension don't include them in the extention check
152 if( wgFileExtensions
&& id
!= 'wpUploadFileURL' ){
154 if( fname
.lastIndexOf('.')!=-1 ){
155 var ext
= fname
.substr( fname
.lastIndexOf('.')+1 );
156 for(var i
=0; i
< wgFileExtensions
.length
; i
++){
157 if( wgFileExtensions
[i
].toLowerCase() == ext
.toLowerCase() )
162 //clear the upload set mw-upload-permitted to error
163 document
.getElementById(id
).value
= '';
164 var e
= document
.getElementById('mw-upload-permitted');
165 if(e
) e
. className
= 'error';
167 var e
= document
.getElementById('mw-upload-prohibited');
168 if(e
) e
.className
= 'error';
170 //clear the wpDestFile as well:
171 var e
= document
.getElementById('wpDestFile')
179 // Capitalise first letter and replace spaces by underscores
180 fname
= fname
.charAt(0).toUpperCase().concat(fname
.substring(1,10000)).replace(/ /g
, '_');
183 var destFile
= document
.getElementById('wpDestFile');
185 destFile
.value
= fname
;
186 wgUploadWarningObj
.checkNow(fname
) ;
190 function toggleFilenameFiller() {
191 if(!document
.getElementById
) return;
192 var upfield
= document
.getElementById('wpUploadFile');
193 var destName
= document
.getElementById('wpDestFile').value
;
194 if (destName
=='' || destName
==' ') {
195 wgUploadAutoFill
= true;
197 wgUploadAutoFill
= false;
201 var wgUploadLicenseObj
= {
203 'responseCache' : { '' : '' },
205 'fetchPreview': function( license
) {
206 if( !wgAjaxLicensePreview
|| !sajax_init_object() ) return;
207 for (cached
in this.responseCache
) {
208 if (cached
== license
) {
209 this.showPreview( this.responseCache
[license
] );
213 injectSpinner( document
.getElementById( 'wpLicense' ), 'license' );
214 sajax_do_call( 'UploadForm::ajaxGetLicensePreview', [license
],
216 wgUploadLicenseObj
.processResult( result
, license
);
221 'processResult' : function( result
, license
) {
222 removeSpinner( 'license' );
223 this.showPreview( result
.responseText
);
224 this.responseCache
[license
] = result
.responseText
;
227 'showPreview' : function( preview
) {
228 var previewPanel
= document
.getElementById( 'mw-license-preview' );
229 if( previewPanel
.innerHTML
!= preview
)
230 previewPanel
.innerHTML
= preview
;
235 addOnloadHook( wgUploadSetup
);