r74713 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74712‎ | r74713 | r74714 >
Date:04:35, 13 October 2010
Author:dale
Status:deferred
Tags:
Comment:
improved miro subs basic editor support ( not much error handling yet )
Modified paths:
  • /branches/MwEmbedStandAlone/modules/MiroSubs/MiroSubs.i18n.php (modified) (history)
  • /branches/MwEmbedStandAlone/modules/MiroSubs/mw.MiroSubsConfig.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/TimedText/mw.TimedText.js (modified) (history)

Diff [purge]

Index: branches/MwEmbedStandAlone/modules/MiroSubs/mw.MiroSubsConfig.js
@@ -1,4 +1,7 @@
22
 3+// include all our module messages
 4+mw.includeAllModuleMessages();
 5+
36 /**
47 * Generates a miro subs config also see:
58 * http://dev.universalsubtitles.org/widget/api_demo.html
@@ -76,15 +79,34 @@
7780 },
7881 'videoURL' : _this.getVideoURL(),
7982 'save': function( miroSubs, doneSaveCallback, cancelCallback) {
 83+ // Close down the editor
 84+ // @@( no way to turn off bindings )
 85+ // @@FIXME add api Close dialog
 86+ // mirosubs.api.closeDialog();
 87+ doneSaveCallback();
 88+ $j('.mirosubs-modal-widget-bg,.mirosubs-modal-widget').hide();
 89+
8090 // Convert the miroSubs to srt
81 - var srtText = _this.miroSubs2Srt( miroSubs );
82 - _this.saveSrtText( srtText, function(status){
83 - if( status ){
84 - doneSaveCallback();
85 - } else {
86 - cancelCallback();
 91+ var srtText = _this.miroSubs2Srt( miroSubs );
 92+ _this.getSaveSummary( function( summary ){
 93+ if( summary === false ){
 94+ // Return to current page without saving the text
 95+ location.reload(true);
 96+ return ;
8797 }
88 - });
 98+ _this.saveSrtText( srtText, summary, function(status){
 99+ // No real error handling right now
 100+ // refresh page regardless of save or cancel
 101+ location.reload(true);
 102+
 103+ /* @@todo error handling
 104+ if( status ){
 105+ doneSaveCallback();
 106+ } else {
 107+ cancelCallback();
 108+ }*/
 109+ });
 110+ });
89111 },
90112 'permalink': 'http://commons.wikimedia.org',
91113 // not sure if this is needed
@@ -94,8 +116,43 @@
95117 'embedCode' : 'some code to embed'
96118 };
97119 },
98 - saveSrtText: function( srtText, calllback ){
99 - var _this = this;
 120+ getSaveSummary: function( callback ){
 121+ // Add a dialog to get save summary
 122+ var buttons ={};
 123+ buttons[ gM('mwe-mirosubs-save-subs') ] = function(){
 124+ var summary = $j('#mwe-mirosubs-save-summary').val();
 125+ // Append link to gadget:
 126+ summary+= ' with [[Help:Gadget-MwEmbed/UniversalSubs|UniversalSubs]]';
 127+ callback( summary );
 128+ // set dialog to loading
 129+ $j( this ).html( $j('<div />').append(
 130+ gM('mwe-mirosubs-saving-subs'),
 131+ $j('<div />')
 132+ .loadingSpinner()
 133+ )
 134+ );
 135+ };
 136+ buttons[ gM('mwe-cancel') ] = function(){
 137+ callback( false );
 138+ $j( this ).dialog( 'close' );
 139+ };
 140+ // Reduce the z-index so we can put the model ontop:
 141+ //$j('.mirosubs-modal-widget-bg,.mirosubs-modal-widget').css( 'z-index', 10 );
 142+ mw.addDialog( {
 143+ 'title' : gM("mwe-mirosubs-save-summary"),
 144+ 'width' : 450,
 145+ 'content' : $j('<div />').append(
 146+ $j('<h3 />').text( gM("mwe-mirosubs-save-summary") ),
 147+ $j('<input/>').attr({
 148+ 'id' : 'mwe-mirosubs-save-summary',
 149+ 'size': '35'
 150+ }).val( gM('mwe-mirosubs-save-default') )
 151+ ),
 152+ 'buttons' : buttons
 153+ });
 154+ },
 155+ saveSrtText: function( srtText, summary, callback ){
 156+ var _this = this;
100157 var timedTextTitle = 'TimedText:' +
101158 this.embedPlayer.apiTitleKey +
102159 '.' + this.config.languageKey + '.srt';
@@ -108,15 +165,15 @@
109166 var request = {
110167 'action':'edit',
111168 'title': timedTextTitle,
112 - 'summary': "Updated subtitles with [[Help:Gadget-MwEmbed/UniversalSubs|UniversalSubs]]",
113169 'text': srtText,
 170+ 'summary': summary,
114171 'token': token
115172 };
116173 mw.getJSON( apiUrl, request, function(data){
117174 if( data.edit.result == "Success" ){
118 - calllback( true );
 175+ callback( true );
119176 } else {
120 - calllback( false );
 177+ callback( false );
121178 }
122179 });
123180 });
@@ -148,10 +205,12 @@
149206
150207 // Get the existing subtitles in miro format
151208 getSubsInMiroFormat: function( callback ){
152 - var _this = this;
153 - var miroSubs = [];
 209+ var _this = this;
154210 var playerTimedText = this.embedPlayer.timedText;
 211+
 212+ var letters = 'abcdefghijklmnopqrstuvwxyz';
155213 playerTimedText.setupTextSources( function(){
 214+ var miroJsonSubs = [];
156215 // NOTE the autoselected default language is a tricky issue
157216 // We need to add support for language selection in the config object save callback
158217
@@ -161,16 +220,17 @@
162221 _this.config.languageKey = source.srclang;
163222 for( var i = 0; i < captions.length ; i ++ ){
164223 var caption = captions[i];
165 - miroSubs.push({
166 - 'subtitle_id': i,
 224+ // get random letters
 225+ miroJsonSubs.push({
 226+ 'subtitle_id': 'sub_' + i,
167227 'text': caption.content,
168228 'start_time': caption.start,
169229 'end_time': caption.end,
170230 'sub_order': i
171231 });
172232 }
173 - });
174 - callback( miroSubs );
 233+ });
 234+ callback( miroJsonSubs );
175235 });
176236 }
177237 };
\ No newline at end of file
Index: branches/MwEmbedStandAlone/modules/MiroSubs/MiroSubs.i18n.php
@@ -12,4 +12,8 @@
1313 'mwe-mirosubs-add-universal-subtitles' => 'Universal subtitles editor',
1414 'mwe-mirosubs-not-loggedin' => 'Please login to edit subtitles with universal subtitles',
1515 'mwe-mirosubs-loading-universal-subtitles' => 'Loading universal subtitles editor',
 16+ 'mwe-mirosubs-save-summary' => 'Summary of subtitle edits',
 17+ 'mwe-mirosubs-save-default' => 'Edited subtitles',
 18+ 'mwe-mirosubs-save-subs' => 'Save subtitles',
 19+ 'mwe-mirosubs-saving-subs' => 'Saving subtitles ...'
1620 );
\ No newline at end of file
Index: branches/MwEmbedStandAlone/modules/TimedText/mw.TimedText.js
@@ -345,11 +345,13 @@
346346
347347 // Get the current source sub captions
348348 getCurrentSubSource: function( callback ){
 349+ mw.log("getCurrentSubSource:: enabled source:" + this.enabledSources.length);
349350 for( var i =0; i < this.enabledSources.length; i++ ){
350351 var source = this.enabledSources[i];
351352 if( source.category == 'SUB' ){
352353 source.load( function(){
353354 callback( source);
 355+ return ;
354356 });
355357 }
356358 }
@@ -902,6 +904,7 @@
903905 if( _this.loaded ) {
904906 if( callback ) {
905907 callback();
 908+ return ;
906909 }
907910 };
908911 _this.loaded = true;
@@ -1007,17 +1010,19 @@
10081011 //Check if the p matches the "all in one line" match:
10091012 var m = currentPtext.replace('--&gt;', '-->').match(/\d+\s(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?\n?(.*)/);
10101013 if (m) {
 1014+ var startMs = (m[4])? (parseInt(m[4], 10) / 1000):0;
 1015+ var endMs = (m[8])? (parseInt(m[8], 10) / 1000) : 0;
10111016 captions.push({
10121017 'start':
10131018 (parseInt(m[1], 10) * 60 * 60) +
10141019 (parseInt(m[2], 10) * 60) +
10151020 (parseInt(m[3], 10)) +
1016 - (parseInt(m[4], 10) / 1000),
 1021+ startMs ,
10171022 'end':
10181023 (parseInt(m[5], 10) * 60 * 60) +
10191024 (parseInt(m[6], 10) * 60) +
10201025 (parseInt(m[7], 10)) +
1021 - (parseInt(m[8], 10) / 1000),
 1026+ endMs,
10221027 'content': $j.trim( m[9] )
10231028 });
10241029 return 'next';
@@ -1035,16 +1040,18 @@
10361041 //Check only for time match:
10371042 var m = currentPtext.replace('--&gt;', '-->').match(/(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?/);
10381043 if (m) {
 1044+ var startMs = (m[4])? (parseInt(m[4], 10) / 1000):0;
 1045+ var endMs = (m[8])? (parseInt(m[8], 10) / 1000) : 0;
10391046 curentCap['start']=
10401047 (parseInt(m[1], 10) * 60 * 60) +
10411048 (parseInt(m[2], 10) * 60) +
10421049 (parseInt(m[3], 10)) +
1043 - (parseInt(m[4], 10) / 1000);
 1050+ startMs;
10441051 curentCap['end']=
10451052 (parseInt(m[5], 10) * 60 * 60) +
10461053 (parseInt(m[6], 10) * 60) +
10471054 (parseInt(m[7], 10)) +
1048 - (parseInt(m[8], 10) / 1000);
 1055+ endMs;
10491056 return 'next';
10501057 }
10511058 //Else content for the curentCap

Status & tagging log