r48002 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48001‎ | r48002 | r48003 >
Date:00:23, 4 March 2009
Author:dale
Status:deferred
Tags:
Comment:
start of firefogg refactor to use chunk upload api
added dependency to jQuery to make things cleaner
Modified paths:
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/firefogg.js (deleted) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/firefogg_nojquery.js (added) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvFirefogg.js (added) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvUploader.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libEmbedObj/mv_nativeEmbed.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/firefogg.js
@@ -1,341 +0,0 @@
2 -/**script to support firefog uploads
3 -based on http://www.firefogg.org/dev/index.html
4 -*/
5 -
6 -//add on ready hook if not being called from uploader:
7 -if(typeof mvUploader =='undefined'){
8 - addOnloadHook(function(){
9 - init_firefogg();
10 - });
11 -}
12 -var min_firefogg_version = '0.9.3';
13 -function init_firefogg( iObj ){
14 - if(!iObj)
15 - iObj = {};
16 - //init based on if Firefogg is available
17 - if(typeof(Firefogg) == 'undefined') {
18 - //alert('Firefogg ISS null');
19 - e = document.getElementById('wgfogg_not_installed');
20 - if(e)
21 - e.style.display = 'inline';
22 -
23 - //no support for firefogg
24 - return false;
25 - }else{
26 - e = document.getElementById('wgfogg_not_installed');
27 - if(e)
28 - e.style.display='none';
29 -
30 - e = document.getElementById('wgfogg_wrong_version');
31 - if(e)
32 - e.style.display='none';
33 -
34 - e = document.getElementById('wgfogg_installed');
35 - if(e)
36 - e.style.display='inline';
37 -
38 - fe = document.getElementById('wgEnableFirefogg');
39 - if(fe){
40 - js_log('wgEnableFirefogg found:');
41 - //get a new fogg object with default options
42 - var fogg = new upFirefogg( iObj );
43 -
44 - //do the version check:
45 - var fv = fogg.fogg.version;
46 - if(fv.replace(/[^0-9]/gi, '') < min_firefogg_version.replace(/[^0-9]/gi, '') ){
47 - e = document.getElementById('wgfogg_wrong_version');
48 - if(e)
49 - e.style.display='inline';
50 -
51 - e = document.getElementById('wgfogg_installed');
52 - if(e)
53 - e.style.display='none';
54 - }
55 -
56 - //make sure the checkbox accurately reflects the current state:
57 - if(fogg.enabled == false)
58 - fe.checked = false;
59 -
60 - addHandler( fe, 'click', function(){
61 - if( fogg.enabled==false ){
62 - fogg.enable_fogg();
63 - }else{
64 - fogg.disable_fogg();
65 - }
66 - });
67 - }else{
68 - js_log('could not find wgEnableFirefogg');
69 - }
70 - }
71 - //we did init with support
72 - return true;
73 -}
74 -
75 -var default_firefogg_options = {
76 - 'upload_done_action':'redirect',
77 - 'enabled':false
78 -}
79 -var upFirefogg = function(iObj){
80 - return this.init( iObj );
81 -}
82 -upFirefogg.prototype = {
83 - init:function( iObj ){
84 - for(var i in default_firefogg_options){
85 - if(iObj[i]){
86 - this[i] = iObj[i];
87 - }else{
88 - this[i] = default_firefogg_options[i];
89 - }
90 - }
91 - //init the Firefogg obj
92 - this.fogg = new Firefogg();
93 - },
94 - enable_fogg:function(){
95 - var _this = this;
96 -
97 - //enable the FOGG_TOGGLE
98 - _this.enabled=true;
99 -
100 - //make sure file is "checked"
101 - e = document.getElementById('wpSourceTypeFile');
102 - if(e) e.checked = true;
103 -
104 - //hide normal file upload stuff (this would all be much shorter code with jquery)
105 - e = document.getElementById('wg-base-upload');
106 - if(e) e.style.display='none';
107 -
108 - //show fogg stuff:
109 - sfe = document.getElementById('fogg-video-file');
110 - if(sfe) sfe.style.display='inline';
111 -
112 -
113 - addHandler( sfe, 'click', function(){
114 - //add binding:
115 - _this.select_fogg();
116 - });
117 - },
118 - select_fogg:function(){
119 - var _this = this;
120 - if(_this.fogg.selectVideo()) {
121 - //update destination filename:
122 - if( _this.fogg.sourceFilename ){
123 - var destFileInput = document.getElementById( 'wpDestFile');
124 - var sf = _this.fogg.sourceFilename;
125 -
126 - var ext = '';
127 - if( sf.lastIndexOf('.') != -1){
128 - ext = sf.substring( sf.lastIndexOf('.')+1 );
129 - }
130 - //set upload warning
131 - if( ext == 'ogg' || ext == 'ogv' ){
132 - e = document.getElementById('wgfogg_waring_ogg_upload');
133 - if(e)
134 - e.style.display='block';
135 - return false;
136 - }else if( ext == 'avi' || ext == 'mov' || ext == 'mp4' || ext=='mp2' ||
137 - ext == 'mpeg' || ext == 'mpeg2' || ext == 'mpeg4' ||
138 - ext == 'dv' ){
139 - //hide ogg warning
140 - e = document.getElementById('wgfogg_waring_ogg_upload');
141 - if(e)
142 - e.style.display='none';
143 - sf = sf.replace(ext, 'ogg');
144 - destFileInput.value = sf;
145 - }else{
146 - //not video extension error:
147 - e = document.getElementById('wgfogg_waring_bad_extension');
148 - if(e)
149 - e.style.display='block';
150 - return false;
151 - }
152 - }
153 - //setup the form handling
154 - var editForm = document.getElementById( 'mw-upload-form' );
155 - //set up the org_onsubmit if not set:
156 - if( typeof( _this.org_onsubmit ) == 'undefined' )
157 - _this.org_onsubmit = editForm.onsubmit;
158 -
159 - editForm.onsubmit = function() {
160 - //run the original onsubmit (if not run yet set flag to avoid excessive chaining )
161 - if( typeof( _this.org_onsubmit ) == 'function' ){
162 - //error in org submit return false;
163 - if( ! _this.org_onsubmit()){
164 - return false;
165 - }
166 - }
167 - //get the input
168 - var formData = _this.getEditFormData( editForm );
169 -
170 - //display the loader:
171 - e = document.getElementById('dlbox-centered')
172 - e.style.display='block';
173 -
174 - e = document.getElementById('dlbox-overlay')
175 - e.style.display='block';
176 -
177 - //for some unknown reason we have to drop down the #p-search z-index:
178 - e = document.getElementById('p-search');
179 - if(e) e.style.zIndex = 1;
180 -
181 -
182 - //@@todo read this from the config file rather than hard code it:
183 - var options = JSON.stringify({'maxSize': 400, 'videoBitrate': 400});
184 - _this.fogg.encode(options);
185 - var encodingStatus = function() {
186 - var status = _this.fogg.status();
187 -
188 - //update progress bar
189 - _this.fogg_update_progress( _this.fogg.progress() );
190 -
191 - //loop to get new status if still encoding
192 - if( _this.fogg.state == 'encoding' ) {
193 - setTimeout(encodingStatus, 500);
194 - }
195 - //encoding done, state can also be 'encoding failed'
196 - else if ( _this.fogg.state == 'encoding done' ) {
197 - //hide the fogg-status-transcode
198 - e = document.getElementById('fogg-status-transcode');
199 - e.style.display='none';
200 - //show the fogg-status-upload
201 - e = document.getElementById('fogg-status-upload');
202 - e.style.display='inline';
203 -
204 - //hard code some values
205 - formData['wpSourceType']='file';
206 -
207 - var data = JSON.stringify( formData );
208 - //send to the post url:
209 - _this.fogg.post( editForm.action, 'wpUploadFile', data);
210 - var uploadStatus = function() {
211 - var status = _this.fogg.status();
212 - //js_log(' up stats: ' + status + ' p:' + _this.fogg.progress() + ' state: '+ _this.fogg.state + ' result page:' + result_page);
213 -
214 - //update progress bar
215 - _this.fogg_update_progress( _this.fogg.progress() );
216 -
217 - //loop to get new status if still uploading
218 - if(_this.fogg.state == 'uploading') {
219 - setTimeout(uploadStatus, 500);
220 - }
221 - //upload sucesfull, state can also be 'upload failed'
222 - else if( _this.fogg.state == 'upload done' ) {
223 - //js_log( 'firefogg:upload done: ');
224 - //@@todo handle errors same problem as #695 in remoteSearchDriver.js
225 - //we need to add image uploading to the api rather than parse the HTML output of the pages
226 - var result_page = _this.fogg.responseText;
227 - var sstring = 'var wgTitle = "' + formData['wpDestFile'].replace('_',' ');
228 - if( result_page && result_page.toLowerCase().indexOf( sstring.toLowerCase() ) != -1){
229 - js_log('upload done got redirect found: ' +sstring + ' r:' + _this.upload_done_action);
230 - if( _this.upload_done_action == 'redirect'){
231 - window.location = wgArticlePath.replace(/\$1/, 'File:' + formData['wpDestFile'] );
232 - }else{
233 - //check if the add_done_action is a callback:
234 - if( typeof _this.upload_done_action == 'function' )
235 - _this.upload_done_action();
236 - }
237 - }else{
238 - js_log('upload page error: did not find: ' +sstring);
239 - var error_txt = 'Unkown error';
240 - if(!result_page){
241 - //@@todo fix this:
242 - //the mediaWiki upload system does not have an API so we can\'t accuratly read errors
243 - error_txt = 'Your upload should be accessible <a href="' +
244 - wgArticlePath.replace(/\$1/, 'File:' + formData['wpDestFile'] ) + '">'+
245 - 'here</a> \n';
246 - }else{
247 - sp = result_page.indexOf('<span class="error">');
248 - if(sp!=-1){
249 - se = result_page.indexOf('</span>', sp);
250 - error_txt = result_page.substr(sp, (sp-se));
251 - }else{
252 - //look for warning:
253 - sp = result_page.indexOf('<ul class="warning">')
254 - if(sp!=-1){
255 - se = result_page.indexOf('</ul>', sp);
256 - error_txt = result_page.substr(sp, (sp-se));
257 - }
258 - }
259 - }
260 - e = document.getElementById('dlbox-centered');
261 - if(e)
262 - e.innerHTML = '<h3>Upload Completed:</h3>' + error_txt;
263 - }
264 - }
265 - //upload error:
266 - else{
267 - alert('firefogg upload error: ' + _this.fogg.state);
268 - }
269 - }
270 - uploadStatus();
271 - }else if(_this.fogg.state == 'encoding fail'){
272 - //@@todo error handling:
273 - alert('encoding failed');
274 - }
275 - }
276 - encodingStatus();
277 - //don't submit the form (let firefogg handle it)
278 - return false;
279 - }; //addHandler mapping
280 - }else{
281 - //remove upload binding if no file was selected
282 - }
283 - },
284 - getEditFormData:function( editForm ){
285 - var data = {};
286 - //get all the form fields:
287 - var inputs = editForm.getElementsByTagName('input');
288 - for(var i=0;i < inputs.length; i++){
289 - if( inputs[i].getAttribute('name') != 'wpUploadFile'){
290 - if( inputs[i].getAttribute('type')=='checkbox'){
291 - if(inputs[i].checked){
292 - data[ inputs[i].getAttribute('name') ] = 'true';
293 - }else{
294 - data[ inputs[i].getAttribute('name') ] = 'false';
295 - }
296 - }else{
297 - data[ inputs[i].getAttribute('name') ] = inputs[i].value;
298 - }
299 - }
300 - }
301 - var inputs = editForm.getElementsByTagName('textarea');
302 - for(var i=0;i < inputs.length; i++){
303 - data[ inputs[i].getAttribute('name') ] = inputs[i].value;
304 - }
305 - return data;
306 - },
307 - disable_fogg:function(){
308 - //show normal file upload
309 - e = document.getElementById('wg-base-upload');
310 - if(e) e.style.display='inline';
311 -
312 - //hide ogg warning
313 - e = document.getElementById('wgfogg_waring_ogg_upload');
314 - if(e)
315 - e.style.display='none';
316 -
317 - //hide not ogg extension error
318 - e = document.getElementById('wgfogg_waring_bad_extension');
319 - if(e)
320 - e.style.display='block';
321 -
322 - //hide fogg stuff
323 - e = document.getElementById('fogg-video-file');
324 - if(e) e.style.display='none';
325 -
326 - if( this.upload_done_action == 'redirect' ){
327 - var editForm = document.getElementById( 'mw-upload-form' );
328 - //restore the original form action
329 - editForm.onsubmit = this.org_onsubmit;
330 - }
331 - //disable the fogg:
332 - this.enabled=false;
333 - },
334 - fogg_update_progress:function(progress){
335 - var progressbar = document.getElementById('fogg-progressbar');
336 - if(progressbar)
337 - progressbar.style.width= parseInt(progress*100) +'%';
338 - var progstatus = document.getElementById('fogg-pstatus');
339 - if(progstatus)
340 - progstatus.innerHTML = parseInt(progress*100) + '% - ';
341 - }
342 -}
\ No newline at end of file
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/firefogg_nojquery.js
@@ -0,0 +1,341 @@
 2+/**script to support firefog uploads
 3+based on http://www.firefogg.org/dev/index.html
 4+*/
 5+
 6+//add on ready hook if not being called from uploader:
 7+if(typeof mvUploader =='undefined'){
 8+ addOnloadHook(function(){
 9+ init_firefogg();
 10+ });
 11+}
 12+var min_firefogg_version = '0.9.3';
 13+function init_firefogg( iObj ){
 14+ if(!iObj)
 15+ iObj = {};
 16+ //init based on if Firefogg is available
 17+ if(typeof(Firefogg) == 'undefined') {
 18+ //alert('Firefogg ISS null');
 19+ e = document.getElementById('wgfogg_not_installed');
 20+ if(e)
 21+ e.style.display = 'inline';
 22+
 23+ //no support for firefogg
 24+ return false;
 25+ }else{
 26+ e = document.getElementById('wgfogg_not_installed');
 27+ if(e)
 28+ e.style.display='none';
 29+
 30+ e = document.getElementById('wgfogg_wrong_version');
 31+ if(e)
 32+ e.style.display='none';
 33+
 34+ e = document.getElementById('wgfogg_installed');
 35+ if(e)
 36+ e.style.display='inline';
 37+
 38+ fe = document.getElementById('wgEnableFirefogg');
 39+ if(fe){
 40+ js_log('wgEnableFirefogg found:');
 41+ //get a new fogg object with default options
 42+ var fogg = new upFirefogg( iObj );
 43+
 44+ //do the version check:
 45+ var fv = fogg.fogg.version;
 46+ if( fv.replace(/[^0-9]/gi, '') < min_firefogg_version.replace(/[^0-9]/gi, '') ){
 47+ e = document.getElementById('wgfogg_wrong_version');
 48+ if(e)
 49+ e.style.display='inline';
 50+
 51+ e = document.getElementById('wgfogg_installed');
 52+ if(e)
 53+ e.style.display='none';
 54+ }
 55+
 56+ //make sure the checkbox accurately reflects the current state:
 57+ if( fogg.enabled == false )
 58+ fe.checked = false;
 59+
 60+ addHandler( fe, 'click', function(){
 61+ if( fogg.enabled==false ){
 62+ fogg.enable_fogg();
 63+ }else{
 64+ fogg.disable_fogg();
 65+ }
 66+ });
 67+ }else{
 68+ alert('could not find wgEnableFirefogg');
 69+ }
 70+ }
 71+ //we did init with support
 72+ return true;
 73+}
 74+
 75+var default_firefogg_options = {
 76+ 'upload_done_action':'redirect',
 77+ 'enabled':false
 78+}
 79+var upFirefogg = function(iObj){
 80+ return this.init( iObj );
 81+}
 82+upFirefogg.prototype = {
 83+ init:function( iObj ){
 84+ for(var i in default_firefogg_options){
 85+ if(iObj[i]){
 86+ this[i] = iObj[i];
 87+ }else{
 88+ this[i] = default_firefogg_options[i];
 89+ }
 90+ }
 91+ //init the Firefogg obj
 92+ this.fogg = new Firefogg();
 93+ },
 94+ enable_fogg:function(){
 95+ var _this = this;
 96+
 97+ //enable the FOGG_TOGGLE
 98+ _this.enabled=true;
 99+
 100+ //make sure file is "checked"
 101+ e = document.getElementById('wpSourceTypeFile');
 102+ if(e) e.checked = true;
 103+
 104+ //hide normal file upload stuff (this would all be much shorter code with jquery)
 105+ e = document.getElementById('wg-base-upload');
 106+ if(e) e.style.display='none';
 107+
 108+ //show fogg stuff:
 109+ sfe = document.getElementById('fogg-video-file');
 110+ if(sfe) sfe.style.display='inline';
 111+
 112+
 113+ addHandler( sfe, 'click', function(){
 114+ //add binding:
 115+ _this.select_fogg();
 116+ });
 117+ },
 118+ select_fogg:function(){
 119+ var _this = this;
 120+ if(_this.fogg.selectVideo()) {
 121+ //update destination filename:
 122+ if( _this.fogg.sourceFilename ){
 123+ var destFileInput = document.getElementById( 'wpDestFile');
 124+ var sf = _this.fogg.sourceFilename;
 125+
 126+ var ext = '';
 127+ if( sf.lastIndexOf('.') != -1){
 128+ ext = sf.substring( sf.lastIndexOf('.')+1 );
 129+ }
 130+ //set upload warning
 131+ if( ext == 'ogg' || ext == 'ogv' ){
 132+ e = document.getElementById('wgfogg_waring_ogg_upload');
 133+ if(e)
 134+ e.style.display='block';
 135+ return false;
 136+ }else if( ext == 'avi' || ext == 'mov' || ext == 'mp4' || ext=='mp2' ||
 137+ ext == 'mpeg' || ext == 'mpeg2' || ext == 'mpeg4' ||
 138+ ext == 'dv' ){
 139+ //hide ogg warning
 140+ e = document.getElementById('wgfogg_waring_ogg_upload');
 141+ if(e)
 142+ e.style.display='none';
 143+ sf = sf.replace(ext, 'ogg');
 144+ destFileInput.value = sf;
 145+ }else{
 146+ //not video extension error:
 147+ e = document.getElementById('wgfogg_waring_bad_extension');
 148+ if(e)
 149+ e.style.display='block';
 150+ return false;
 151+ }
 152+ }
 153+ //setup the form handling
 154+ var editForm = document.getElementById( 'mw-upload-form' );
 155+ //set up the org_onsubmit if not set:
 156+ if( typeof( _this.org_onsubmit ) == 'undefined' )
 157+ _this.org_onsubmit = editForm.onsubmit;
 158+
 159+ editForm.onsubmit = function() {
 160+ //run the original onsubmit (if not run yet set flag to avoid excessive chaining )
 161+ if( typeof( _this.org_onsubmit ) == 'function' ){
 162+ //error in org submit return false;
 163+ if( ! _this.org_onsubmit()){
 164+ return false;
 165+ }
 166+ }
 167+ //get the input
 168+ var formData = _this.getEditFormData( editForm );
 169+
 170+ //display the loader:
 171+ e = document.getElementById('dlbox-centered')
 172+ e.style.display='block';
 173+
 174+ e = document.getElementById('dlbox-overlay')
 175+ e.style.display='block';
 176+
 177+ //for some unknown reason we have to drop down the #p-search z-index:
 178+ e = document.getElementById('p-search');
 179+ if(e) e.style.zIndex = 1;
 180+
 181+
 182+ //@@todo read this from the config file rather than hard code it:
 183+ var options = JSON.stringify({'maxSize': 400, 'videoBitrate': 400});
 184+ _this.fogg.encode(options);
 185+ var encodingStatus = function() {
 186+ var status = _this.fogg.status();
 187+
 188+ //update progress bar
 189+ _this.fogg_update_progress( _this.fogg.progress() );
 190+
 191+ //loop to get new status if still encoding
 192+ if( _this.fogg.state == 'encoding' ) {
 193+ setTimeout(encodingStatus, 500);
 194+ }
 195+ //encoding done, state can also be 'encoding failed'
 196+ else if ( _this.fogg.state == 'encoding done' ) {
 197+ //hide the fogg-status-transcode
 198+ e = document.getElementById('fogg-status-transcode');
 199+ e.style.display='none';
 200+ //show the fogg-status-upload
 201+ e = document.getElementById('fogg-status-upload');
 202+ e.style.display='inline';
 203+
 204+ //hard code some values
 205+ formData['wpSourceType']='file';
 206+
 207+ var data = JSON.stringify( formData );
 208+ //send to the post url:
 209+ _this.fogg.post( editForm.action, 'wpUploadFile', data);
 210+ var uploadStatus = function() {
 211+ var status = _this.fogg.status();
 212+ //js_log(' up stats: ' + status + ' p:' + _this.fogg.progress() + ' state: '+ _this.fogg.state + ' result page:' + result_page);
 213+
 214+ //update progress bar
 215+ _this.fogg_update_progress( _this.fogg.progress() );
 216+
 217+ //loop to get new status if still uploading
 218+ if(_this.fogg.state == 'uploading') {
 219+ setTimeout(uploadStatus, 500);
 220+ }
 221+ //upload sucesfull, state can also be 'upload failed'
 222+ else if( _this.fogg.state == 'upload done' ) {
 223+ //js_log( 'firefogg:upload done: ');
 224+ //@@todo handle errors same problem as #695 in remoteSearchDriver.js
 225+ //we need to add image uploading to the api rather than parse the HTML output of the pages
 226+ var result_page = _this.fogg.responseText;
 227+ var sstring = 'var wgTitle = "' + formData['wpDestFile'].replace('_',' ');
 228+ if( result_page && result_page.toLowerCase().indexOf( sstring.toLowerCase() ) != -1){
 229+ js_log('upload done got redirect found: ' +sstring + ' r:' + _this.upload_done_action);
 230+ if( _this.upload_done_action == 'redirect'){
 231+ window.location = wgArticlePath.replace(/\$1/, 'File:' + formData['wpDestFile'] );
 232+ }else{
 233+ //check if the add_done_action is a callback:
 234+ if( typeof _this.upload_done_action == 'function' )
 235+ _this.upload_done_action();
 236+ }
 237+ }else{
 238+ js_log('upload page error: did not find: ' +sstring);
 239+ var error_txt = 'Unkown error';
 240+ if(!result_page){
 241+ //@@todo fix this:
 242+ //the mediaWiki upload system does not have an API so we can\'t accuratly read errors
 243+ error_txt = 'Your upload should be accessible <a href="' +
 244+ wgArticlePath.replace(/\$1/, 'File:' + formData['wpDestFile'] ) + '">'+
 245+ 'here</a> \n';
 246+ }else{
 247+ sp = result_page.indexOf('<span class="error">');
 248+ if(sp!=-1){
 249+ se = result_page.indexOf('</span>', sp);
 250+ error_txt = result_page.substr(sp, (sp-se));
 251+ }else{
 252+ //look for warning:
 253+ sp = result_page.indexOf('<ul class="warning">')
 254+ if(sp!=-1){
 255+ se = result_page.indexOf('</ul>', sp);
 256+ error_txt = result_page.substr(sp, (sp-se));
 257+ }
 258+ }
 259+ }
 260+ e = document.getElementById('dlbox-centered');
 261+ if(e)
 262+ e.innerHTML = '<h3>Upload Completed:</h3>' + error_txt;
 263+ }
 264+ }
 265+ //upload error:
 266+ else{
 267+ alert('firefogg upload error: ' + _this.fogg.state);
 268+ }
 269+ }
 270+ uploadStatus();
 271+ }else if(_this.fogg.state == 'encoding fail'){
 272+ //@@todo error handling:
 273+ alert('encoding failed');
 274+ }
 275+ }
 276+ encodingStatus();
 277+ //don't submit the form (let firefogg handle it)
 278+ return false;
 279+ }; //addHandler mapping
 280+ }else{
 281+ //remove upload binding if no file was selected
 282+ }
 283+ },
 284+ getEditFormData:function( editForm ){
 285+ var data = {};
 286+ //get all the form fields:
 287+ var inputs = editForm.getElementsByTagName('input');
 288+ for(var i=0;i < inputs.length; i++){
 289+ if( inputs[i].getAttribute('name') != 'wpUploadFile'){
 290+ if( inputs[i].getAttribute('type')=='checkbox'){
 291+ if(inputs[i].checked){
 292+ data[ inputs[i].getAttribute('name') ] = 'true';
 293+ }else{
 294+ data[ inputs[i].getAttribute('name') ] = 'false';
 295+ }
 296+ }else{
 297+ data[ inputs[i].getAttribute('name') ] = inputs[i].value;
 298+ }
 299+ }
 300+ }
 301+ var inputs = editForm.getElementsByTagName('textarea');
 302+ for(var i=0;i < inputs.length; i++){
 303+ data[ inputs[i].getAttribute('name') ] = inputs[i].value;
 304+ }
 305+ return data;
 306+ },
 307+ disable_fogg:function(){
 308+ //show normal file upload
 309+ e = document.getElementById('wg-base-upload');
 310+ if(e) e.style.display='inline';
 311+
 312+ //hide ogg warning
 313+ e = document.getElementById('wgfogg_waring_ogg_upload');
 314+ if(e)
 315+ e.style.display='none';
 316+
 317+ //hide not ogg extension error
 318+ e = document.getElementById('wgfogg_waring_bad_extension');
 319+ if(e)
 320+ e.style.display='block';
 321+
 322+ //hide fogg stuff
 323+ e = document.getElementById('fogg-video-file');
 324+ if(e) e.style.display='none';
 325+
 326+ if( this.upload_done_action == 'redirect' ){
 327+ var editForm = document.getElementById( 'mw-upload-form' );
 328+ //restore the original form action
 329+ editForm.onsubmit = this.org_onsubmit;
 330+ }
 331+ //disable the fogg:
 332+ this.enabled=false;
 333+ },
 334+ fogg_update_progress:function(progress){
 335+ var progressbar = document.getElementById('fogg-progressbar');
 336+ if(progressbar)
 337+ progressbar.style.width= parseInt(progress*100) +'%';
 338+ var progstatus = document.getElementById('fogg-pstatus');
 339+ if(progstatus)
 340+ progstatus.innerHTML = parseInt(progress*100) + '% - ';
 341+ }
 342+}
\ No newline at end of file
Property changes on: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/firefogg_nojquery.js
___________________________________________________________________
Added: svn:mergeinfo
Added: svn:eol-style
1343 + native
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvFirefogg.js
@@ -0,0 +1,265 @@
 2+/* firefogg refactor using jQuery
 3+ invovked using the
 4+ */
 5+
 6+var default_firefogg_options = {
 7+ 'upload_done_action':'redirect',
 8+ 'enabled':false
 9+}
 10+var mvFirefogg = function(initObj){
 11+ return this.init( initObj );
 12+}
 13+mvFirefogg.prototype = {
 14+
 15+ min_firefogg_version : '0.9.3',
 16+ enabled : false, //if firefogg is enabled or not.
 17+ upload_mode:'autodetect', //can be 'post', 'chunks' or autodetect. (autodetect issues an api call)
 18+ encoder_settings:{ //@@todo maybe allow server to set this?
 19+ 'maxSize': 400,
 20+ 'videoBitrate': 400
 21+ },
 22+ init : function( iObj ){
 23+ if(!iObj)
 24+ iObj = {};
 25+ js_log("wtf");
 26+ //inherit iObj properties:
 27+ for(var i in default_firefogg_options){
 28+ if(iObj[i]){
 29+ this[i] = iObj[i];
 30+ }else{
 31+ this[i] = default_firefogg_options[i];
 32+ }
 33+ }
 34+ this.setupFirefogg();
 35+ },
 36+ setupFirefogg : function(){
 37+ var _this = this;
 38+ if(typeof(Firefogg) == 'undefined'){
 39+ $j('#wgfogg_not_installed').show();
 40+ return false;
 41+ }
 42+ //make sure all the error msgs are hidden:
 43+ $j('#wgfogg_not_installed,#wgfogg_wrong_version').hide();
 44+
 45+ //show firefogg enabler:
 46+ $j('#wgfogg_installed,#wgEnableFirefogg').show();
 47+
 48+ if( $j('#wgEnableFirefogg').length > 0 ){
 49+ this.fogg = new Firefogg();
 50+ //do the version check:
 51+ if( this.fogg.version.replace(/[^0-9]/gi, '') < this.min_firefogg_version.replace(/[^0-9]/gi, '' ) ){
 52+ //show wrong version error:
 53+ $j('#wgfogg_wrong_version').show();
 54+ //hide the installed parent div:
 55+ $j('#wgfogg_installed').hide();
 56+ }
 57+ //make sure the checkbox accurately reflects the current state per config:
 58+ $j('#wgEnableFirefogg').get(0).checked = this.enabled;
 59+
 60+ //setup the click bindding:
 61+ $j('#wgEnableFirefogg').click( function(){
 62+ if( _this.enabled ){
 63+ _this.disable_fogg();
 64+ }else{
 65+ _this.enable_fogg();
 66+ }
 67+ });
 68+ }else{
 69+ js_log('could not find wgEnableFirefogg');
 70+ }
 71+ },
 72+ enable_fogg:function(){
 73+ var _this = this;
 74+
 75+ //enable the FOGG_TOGGLE
 76+ this.enabled=true;
 77+
 78+ //make sure file is "checked"
 79+ $j('#wpSourceTypeFile').get(0).checked = true;
 80+
 81+ //hide normal file upload stuff (this would all be much shorter code with jquery)
 82+ $j('#wg-base-upload').hide();
 83+
 84+ //show fogg & add click binding:
 85+ $j('#fogg-video-file').show().click( function(){
 86+ _this.select_fogg();
 87+ });
 88+ },
 89+ disable_fogg:function(){
 90+ //not enabled:
 91+ this.enabled=false;
 92+
 93+ $j('#wg-base-upload').show();
 94+
 95+ //hide any errors warnings and video select:
 96+ $j('#wgfogg_waring_ogg_upload,#wgfogg_waring_bad_extension,#fogg-video-file').hide();
 97+ },
 98+ fogg_update_progress:function(progress){
 99+ $j('#fogg-progressbar').css('width', parseInt(progress*100) +'%');
 100+ $j('#fogg-pstatus').html( parseInt(progress*100) + '% - ');
 101+ },
 102+ select_fogg:function(){
 103+ var _this = this;
 104+ if(_this.fogg.selectVideo()) {
 105+ //update destination filename:
 106+ if( _this.fogg.sourceFilename ){
 107+ var sf = _this.fogg.sourceFilename;
 108+ var ext = '';
 109+ if( sf.lastIndexOf('.') != -1){
 110+ ext = sf.substring( sf.lastIndexOf('.')+1 );
 111+ }
 112+ //set upload warning
 113+ if( ext == 'ogg' || ext == 'ogv' ){
 114+ $j('#wgfogg_waring_ogg_upload').show();
 115+ return false;
 116+ }else if( ext == 'avi' || ext == 'mov' || ext == 'mp4' || ext=='mp2' ||
 117+ ext == 'mpeg' || ext == 'mpeg2' || ext == 'mpeg4' ||
 118+ ext == 'dv' ){
 119+ //hide ogg warning
 120+ $j('#wgfogg_waring_ogg_upload').hide();
 121+ sf = sf.replace(ext, 'ogg');
 122+ $j('#wpDestFile').val( sf );
 123+ }else{
 124+ //not video extension error:
 125+ $j('#wgfogg_waring_bad_extension').show();
 126+ return false;
 127+ }
 128+ }
 129+
 130+ //setup the form handling
 131+ var editForm = $j('#mw-upload-form').get(0);
 132+
 133+ //set up the org_onsubmit if not set:
 134+ if( typeof( _this.org_onsubmit ) == 'undefined' )
 135+ _this.org_onsubmit = editForm.onsubmit;
 136+
 137+ editForm.onsubmit = function() {
 138+ //run the original onsubmit (if not run yet set flag to avoid excessive chaining )
 139+ if( typeof( _this.org_onsubmit ) == 'function' ){
 140+ if( ! _this.org_onsubmit() ){
 141+ //error in org submit return false;
 142+ return false;
 143+ }
 144+ }
 145+ //get the input
 146+ //var formData = _this.getEditFormData( editForm );
 147+ var tmpAryData = $j( editForm ).serializeArray();
 148+ for(var i=0; i < tmpAryData.length; i++){
 149+ if( tmpAryData[i]['name'] )
 150+ formData[ mpAryData[i]['name'] ] = mpAryData[i]['value'];
 151+ }
 152+
 153+ //display the loader:
 154+ $j('#dlbox-centered,#dlbox-overlay').show();
 155+
 156+ //for some unknown reason we have to drop down the #p-search z-index:
 157+ $j('#p-search').css('z-index', 1);
 158+
 159+ //check the upload mode:
 160+ if( _this.upload_mode == 'autodetect'){
 161+
 162+ }else{
 163+
 164+ }
 165+ var options = JSON.stringify( _this.encoder_settings );
 166+ _this.fogg.encode(options);
 167+
 168+ var encodingStatus = function() {
 169+ var status = _this.fogg.status();
 170+
 171+ //update progress bar
 172+ _this.fogg_update_progress( _this.fogg.progress() );
 173+
 174+ //loop to get new status if still encoding
 175+ if( _this.fogg.state == 'encoding' ) {
 176+ setTimeout(encodingStatus, 500);
 177+ }
 178+ //encoding done, state can also be 'encoding failed'
 179+ else if ( _this.fogg.state == 'encoding done' ) {
 180+ //hide the fogg-status-transcode
 181+ $j('#fogg-status-transcode').hide();
 182+
 183+ //show the fogg-status-upload
 184+ $j('#fogg-status-upload').show();
 185+
 186+ //hard code some values
 187+ formData['wpSourceType']='file';
 188+
 189+ var data = JSON.stringify( formData );
 190+ //send to the post url:
 191+ _this.fogg.post( editForm.action, 'wpUploadFile', data);
 192+ var uploadStatus = function() {
 193+ var status = _this.fogg.status();
 194+ //js_log(' up stats: ' + status + ' p:' + _this.fogg.progress() + ' state: '+ _this.fogg.state + ' result page:' + result_page);
 195+
 196+ //update progress bar
 197+ _this.fogg_update_progress( _this.fogg.progress() );
 198+
 199+ //loop to get new status if still uploading
 200+ if(_this.fogg.state == 'uploading') {
 201+ setTimeout(uploadStatus, 500);
 202+ }
 203+ //upload sucesfull, state can also be 'upload failed'
 204+ else if( _this.fogg.state == 'upload done' ) {
 205+ //js_log( 'firefogg:upload done: ');
 206+ //@@todo handle errors same problem as #695 in remoteSearchDriver.js
 207+ //we need to add image uploading to the api rather than parse the HTML output of the pages
 208+ var result_page = _this.fogg.responseText;
 209+ var sstring = 'var wgTitle = "' + formData['wpDestFile'].replace('_',' ');
 210+ if( result_page && result_page.toLowerCase().indexOf( sstring.toLowerCase() ) != -1){
 211+ js_log('upload done got redirect found: ' +sstring + ' r:' + _this.upload_done_action);
 212+ if( _this.upload_done_action == 'redirect'){
 213+ window.location = wgArticlePath.replace(/\$1/, 'File:' + formData['wpDestFile'] );
 214+ }else{
 215+ //check if the add_done_action is a callback:
 216+ if( typeof _this.upload_done_action == 'function' )
 217+ _this.upload_done_action();
 218+ }
 219+ }else{
 220+ js_log('upload page error: did not find: ' +sstring);
 221+ var error_txt = 'Unkown error';
 222+ if(!result_page){
 223+ //@@todo fix this:
 224+ //the mediaWiki upload system does not have an API so we can\'t accuratly read errors
 225+ error_txt = 'Your upload should be accessible <a href="' +
 226+ wgArticlePath.replace(/\$1/, 'File:' + formData['wpDestFile'] ) + '">'+
 227+ 'here</a> \n';
 228+ }else{
 229+ sp = result_page.indexOf('<span class="error">');
 230+ if(sp!=-1){
 231+ se = result_page.indexOf('</span>', sp);
 232+ error_txt = result_page.substr(sp, (sp-se));
 233+ }else{
 234+ //look for warning:
 235+ sp = result_page.indexOf('<ul class="warning">')
 236+ if(sp!=-1){
 237+ se = result_page.indexOf('</ul>', sp);
 238+ error_txt = result_page.substr(sp, (sp-se));
 239+ }
 240+ }
 241+ }
 242+ e = document.getElementById('dlbox-centered');
 243+ if(e)
 244+ e.innerHTML = '<h3>Upload Completed:</h3>' + error_txt;
 245+ }
 246+ }
 247+ //upload error:
 248+ else{
 249+ alert('firefogg upload error: ' + _this.fogg.state);
 250+ }
 251+ }
 252+ uploadStatus();
 253+ }else if(_this.fogg.state == 'encoding fail'){
 254+ //@@todo error handling:
 255+ alert('encoding failed');
 256+ }
 257+ }
 258+ encodingStatus();
 259+ //don't submit the form (let firefogg handle it)
 260+ return false;
 261+ }; //addHandler mapping
 262+ }else{
 263+ //remove upload binding if no file was selected
 264+ }
 265+ }
 266+}
\ No newline at end of file
Property changes on: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvFirefogg.js
___________________________________________________________________
Added: svn:mergeinfo
Added: svn:eol-style
1267 + native
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvUploader.js
@@ -39,31 +39,35 @@
4040 this.on_upload_page = ( wgPageName== "Special:Upload")?true:false;
4141 js_log('f:mvUploader: onuppage:' + this.on_upload_page);
4242 //grab firefogg.js:
43 - mvJsLoader.doLoad({'upFirefogg' : 'libAddMedia/firefogg.js'},function(){
44 - //if we are not on the upload page grab the upload html via ajax:
45 - if( !_this.on_upload_page){
46 - $j.get(wgArticlePath.replace(/\$1/, 'Special:Upload'), {}, function(data){
47 - //add upload.js:
48 - $j.getScript( stylepath + '/common/upload.js', function(){
49 - //really _really_ need an "upload api"!
50 - wgAjaxUploadDestCheck = true;
51 - wgAjaxLicensePreview = false;
52 - wgUploadAutoFill = true;
53 - //strip out inline scripts:
54 - sp = data.indexOf('<div id="content">');
55 - se = data.indexOf('<!-- end content -->');
56 - if(sp!=-1 && se !=-1){
57 - result_data = data.substr(sp, (se-sp) ).replace('/\<script\s.*?\<\/script\>/gi',' ');
58 - js_log("trying to set: " + result_data );
59 - //$j('#'+_this.target_div).html( result_data );
60 - }
61 - _this.setupFirefogg();
62 - });
63 - });
64 - }else{
65 - _this.setupFirefogg();
66 - }
67 - });
 43+ mvJsLoader.doLoad({
 44+ 'mvFirefogg' : 'libAddMedia/mvFirefogg.js'
 45+ },function(){
 46+ //if we are not on the upload page grab the upload html via ajax:
 47+ //@@todo refactor with
 48+ if( !_this.on_upload_page){
 49+ $j.get(wgArticlePath.replace(/\$1/, 'Special:Upload'), {}, function(data){
 50+ //add upload.js:
 51+ $j.getScript( stylepath + '/common/upload.js', function(){
 52+ //really _really_ need an "upload api"!
 53+ wgAjaxUploadDestCheck = true;
 54+ wgAjaxLicensePreview = false;
 55+ wgUploadAutoFill = true;
 56+ //strip out inline scripts:
 57+ sp = data.indexOf('<div id="content">');
 58+ se = data.indexOf('<!-- end content -->');
 59+ if(sp!=-1 && se !=-1){
 60+ result_data = data.substr(sp, (se-sp) ).replace('/\<script\s.*?\<\/script\>/gi',' ');
 61+ js_log("trying to set: " + result_data );
 62+ //$j('#'+_this.target_div).html( result_data );
 63+ }
 64+ _this.setupFirefogg();
 65+ });
 66+ });
 67+ }else{
 68+ _this.setupFirefogg();
 69+ }
 70+ }
 71+ );
6872 },
6973 setupFirefogg:function(){
7074 var _this = this;
@@ -77,7 +81,7 @@
7882 //set up the upload_done action
7983 //redirect if we are on the upload page
8084 //do a callback if in called from gui)
81 - var intFirefoggObj = (this.on_upload_page)?
 85+ var intFirefoggObj = ( this.on_upload_page )?
8286 {'upload_done_action':'redirect'}:
8387 {'upload_done_action':function( rTitle ){
8488 js_log('add_done_action callback for uploader');
@@ -85,10 +89,10 @@
8690 _this.upload_done_action( rTitle );
8791 }
8892 };
 93+ js_log('new mvFirefogg');
8994 //if firefog is not taking over the submit we can here:
90 - if( ! init_firefogg( intFirefoggObj ) ){
91 - //no firefogg installed
92 - }
 95+ _this.fogg = new mvFirefogg( intFirefoggObj );
 96+
9397 },
9498 //same add code as specialUpload if($wgEnableFirefogg){
9599 addFirefoggHtml:function(){
Index: trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js
@@ -26,7 +26,7 @@
2727
2828 //if we should use the scriptLoader
2929 //( lets you group requests, minimize javascript, and use mediaWiki localization infastructure)
30 -var MV_USE_SCRIPT_LOADER = true;
 30+var MV_USE_SCRIPT_LOADER = false;
3131
3232 //the name of the player skin (default is mvpcf)
3333 var mv_skin_name = 'mvpcf';
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libEmbedObj/mv_nativeEmbed.js
@@ -92,8 +92,8 @@
9393 this.setSliderValue( ( this.currentTime - this.start_offset ) / this.duration );
9494 this.setStatus( seconds2ntp(this.currentTime) + '/'+ seconds2ntp(this.start_offset+this.duration ));
9595 }else{
96 - this.setSliderValue(this.currentTime/this.duration );
97 - this.setStatus( seconds2ntp(this.currentTime) + '/'+ seconds2ntp(this.duration ));
 96+ this.setSliderValue( this.currentTime / this.duration );
 97+ this.setStatus( seconds2ntp(this.currentTime) + '/' + seconds2ntp(this.duration ));
9898 }
9999 }
100100 }

Status & tagging log