r58721 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58720‎ | r58721 | r58722 >
Date:17:44, 7 November 2009
Author:j
Status:deferred
Tags:
Comment:
TimedText javascript interface to upload srt files, js2 part
Modified paths:
  • /trunk/phase3/js2/mwEmbed/libTimedText/mvTimeTextEdit.js (added) (history)
  • /trunk/phase3/js2/mwEmbed/mv_embed.js (modified) (history)
  • /trunk/phase3/js2/remoteMwEmbed.js (modified) (history)

Diff [purge]

Index: trunk/phase3/js2/mwEmbed/mv_embed.js
@@ -144,7 +144,8 @@
145145 "mvFirefoggRender" : "libSequencer/mvFirefoggRender.js",
146146 "mvTimedEffectsEdit": "libSequencer/mvTimedEffectsEdit.js",
147147
148 - "mvTextInterface" : "libTimedText/mvTextInterface.js"
 148+ "mvTextInterface" : "libTimedText/mvTextInterface.js",
 149+ "mvTimedTextEdit" : "libTimedText/mvTimedTextEdit.js"
149150 });
150151
151152 // Dependency mapping for CSS files for self-contained included plugins:
@@ -2022,4 +2023,4 @@
20232024 function js_error( string ) {
20242025 alert( string );
20252026 return false;
2026 -}
\ No newline at end of file
 2027+}
Index: trunk/phase3/js2/mwEmbed/libTimedText/mvTimeTextEdit.js
@@ -0,0 +1,98 @@
 2+/*
 3+ * JS2-style edit.js
 4+ */
 5+
 6+// Setup configuration vars (if not set already)
 7+if( !mwAddMediaConfig )
 8+ var mwAddMediaConfig = {};
 9+
 10+var mvTimedTextEdit = {};
 11+
 12+js2AddOnloadHook( function() {
 13+ function getSubtitle(f) {
 14+ var name = f.files[0].name;
 15+ var srtData = f.files[0].getAsBinary();
 16+ srtData = srtData.replace('\r\n', '\n');
 17+ return srtData;
 18+ }
 19+ function uploadSubtitles() {
 20+ do_api_req({
 21+ 'data': {
 22+ 'meta' : 'siteinfo',
 23+ 'siprop' : 'languages'
 24+ }
 25+ }, function( langDataRaw ) {
 26+ var langData = {};
 27+ var languageSelect = '<select id="timed_text_language">';
 28+
 29+ var lagRaw = langDataRaw.query.languages;
 30+ for(var j in lagRaw){
 31+ var code = lagRaw[j].code;
 32+ var language = lagRaw[j]['*'];
 33+ langData[ code ] = language;
 34+ languageSelect += '<option value="'+code+'">'+language+'('+code+')</option>';
 35+ }
 36+ languageSelect += '/</select>';
 37+ var cBtn = {};
 38+ cBtn[ gM('mwe-cancel') ] = function(){
 39+ $j(this).dialog('close');
 40+ }
 41+ cBtn[ gM('mwe-ok') ] = function(){
 42+ var file = $j('#timed_text_file_upload');
 43+ var langKey = file[0].files[0].name.split('.');
 44+ var extension = langKey.pop();
 45+ langKey = langKey.pop();
 46+ var mimeTypes = {
 47+ 'srt': 'text/x-srt',
 48+ 'cmml': 'text/cmml'
 49+ }
 50+ if( !mimeTypes[ extension ] ){
 51+ js_log('Error: unknown extension:'+ extension);
 52+ }
 53+ //get language from form
 54+ langKey = $j('#timed_text_language').val();
 55+
 56+ if(extension == "srt") {
 57+ var srt = getSubtitle(file[0]);
 58+ $j(this).html("saving...");
 59+ $j('.ui-dialog-buttonpane').remove();
 60+
 61+ var editToken = $j('input[name=wpEditToken]').val();
 62+ var title = wgTitle.split('.');
 63+ title.pop();
 64+ title.pop();
 65+ title = title.join('.') + '.' + langKey + '.srt';
 66+ do_api_req({
 67+ 'data': {
 68+ 'action' : 'edit',
 69+ 'title' : title,
 70+ 'text' : srt,
 71+ 'token': editToken
 72+ }
 73+ }, function(dialog) {
 74+ return function( result ) {
 75+ document.location.href = wgArticlePath.replace('/$1', '?title=' + title + '&action=edit');
 76+ $j(dialog).dialog('close');
 77+ }}(this)
 78+ );
 79+ } else {
 80+ $j(this).html("error only srt works right now.");
 81+ }
 82+ }
 83+ $j.addDialog("Select Subtitle to upload",
 84+ '<input type="file" id="timed_text_file_upload"></input><br>' + languageSelect,
 85+ cBtn);
 86+ $j('#timed_text_file_upload').change(function(ev) {
 87+ var langKey = this.files[0].name.split('.');
 88+ var extension = langKey.pop();
 89+ langKey = langKey.pop();
 90+ $j('#timed_text_language').val( langKey );
 91+ });
 92+ });
 93+ }
 94+ var button = $j('<button>');
 95+ button.click(uploadSubtitles)
 96+ button.text("Upload Subtitle");
 97+ $j('#toolbar').append(button);
 98+});
 99+
Index: trunk/phase3/js2/remoteMwEmbed.js
@@ -24,7 +24,9 @@
2525
2626 //timed text dispaly:
2727 if(wgPageName.indexOf("TimedText") === 0){
28 -
 28+ load_mv_embed( function() {
 29+ loadExternalJs( mwEmbedHostPath + '/mwEmbed/libTimedText/mvTimeTextEdit.js' + reqAguments );
 30+ } );
2931 }
3032
3133 // Firefogg integration

Status & tagging log