r60370 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60369‎ | r60370 | r60371 >
Date:21:46, 24 December 2009
Author:dale
Status:deferred
Tags:
Comment:
* bug 21941 fixed player supports overlays check.
* Added support for wikiText in srt. So things like [[w:Name of person]] can link out to that persons article.
see start of video http://commons.wikimedia.org/wiki/User:MediaBot
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mw.TimedText.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/TimedText/remotes/RemoteMwTimedText.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/skins/kskin/kskinConfig.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/skins/kskin/kskinConfig.js
@@ -119,11 +119,14 @@
120120
121121
122122 // Options menu display:
123 - $tp.find( '.k-options' ).unbind().click( function() {
124 - if ( $j( '#' + embedObj.id + ' .k-menu' ).length == 0 ) {
 123+ $tp.find( '.k-options' ).unbind().click( function() {
 124+ // Get an updated refrence to the embed object
 125+ var embedObj = $tp.get( 0 );
 126+ if ( $j( '#' + embedObj.id + ' .k-menu' ).length == 0 ) {
125127 // Stop the player if it does not support overlays:
126 - if ( !embedObj.supports['overlay'] )
 128+ if ( !embedObj.supports['overlays'] ){
127129 $tp.get( 0 ).stop();
 130+ }
128131 // Add the options
129132 _this.addOptionsBinding( $tp );
130133 }
Index: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mw.TimedText.js
@@ -97,6 +97,13 @@
9898 */
9999 textSourceSetupFlag: null,
100100
 101+
 102+ /*
 103+ * Hard coded to "commons" right now .. but we will want to support per-asset provider id's
 104+ * in addition to a standard "callback" system from cross domain grabbing of srt's
 105+ */
 106+ textProviderId : 'commons',
 107+
101108 /**
102109 * Valid "iText" categories
103110 */
@@ -120,6 +127,7 @@
121128 */
122129 timedTextExtMime: {
123130 'srt': 'text/x-srt',
 131+ 'mw-srt': 'text/mw-srt',
124132 'cmml': 'text/cmml'
125133 },
126134
@@ -260,8 +268,6 @@
261269 }
262270
263271 //If there are no inline sources check timedTextProviders & wikiTitleKey
264 - // ( hard coded to "commons" right now )
265 - var textProviderId = 'commons';
266272 if( !this.embedPlayer.wikiTitleKey || !this.timedTextProviders){
267273 //no other sources just issue the callback:
268274 callback();
@@ -269,12 +275,12 @@
270276 }
271277
272278 // Try to get sources from text provider:
273 - var provider = this.timedTextProviders[ textProviderId ];
 279+ var provider = this.timedTextProviders[ this.textProviderId ];
274280 var assetKey = this.embedPlayer.wikiTitleKey;
275281 switch( provider.lib ){
276282 case 'mediaWiki':
277283 this.textProvider = new mw.MediaWikiTextProvider( {
278 - 'provider_id' : textProviderId,
 284+ 'provider_id' : this.textProviderId,
279285 'api_url': provider.api_url,
280286 'embedPlayer': this.embedPlayer
281287 } );
@@ -443,6 +449,8 @@
444450
445451 /**
446452 * Shows the timed text edit ui
 453+ *
 454+ * @param {String} mode Mode or page to display ( to diffrenciate between edit vs new transcript)
447455 */
448456 showTimedTextEditUI: function( mode ){
449457 var _this = this;
@@ -851,15 +859,16 @@
852860 }
853861 // Set parser handler:
854862 switch( this.getMIMEType() ){
 863+ //Special mediaWiki srt format ( support wiki-text in srt's )
 864+ case 'text/mw-srt':
 865+ var handler = parseMwSrt;
 866+ break;
855867 case 'text/x-srt':
856868 var handler = parseSrt;
857869 break;
858870 case 'text/cmml':
859871 var handler = parseCMML;
860872 break;
861 - case 'text/html':
862 - var handler = parseSrtHTML;
863 - break;
864873 default:
865874 var hanlder = null;
866875 break;
@@ -929,6 +938,72 @@
930939 return false;
931940 }
932941 }
 942+ /**
 943+ * parse mediaWiki html srt
 944+ */
 945+ function parseMwSrt( data ){
 946+ var captions = [ ];
 947+ var curentCap = [];
 948+ var parseNextAsTime = false;
 949+ // Optimize: we could use javascript strings instead of XML parsing
 950+ $j( '<div>' + data + '</div>' ).find('p').each( function(){
 951+ currentPtext = $j(this).html();
 952+ mw.log( currentPtext );
 953+
 954+ //Check if the p matches the "all in one line" match:
 955+ var m = currentPtext.replace('--&gt;', '-->').match(/\d+\s(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?(.*)/);
 956+ if (m) {
 957+ captions.push({
 958+ 'start':
 959+ (parseInt(m[1], 10) * 60 * 60) +
 960+ (parseInt(m[2], 10) * 60) +
 961+ (parseInt(m[3], 10)) +
 962+ (parseInt(m[4], 10) / 1000),
 963+ 'end':
 964+ (parseInt(m[5], 10) * 60 * 60) +
 965+ (parseInt(m[6], 10) * 60) +
 966+ (parseInt(m[7], 10)) +
 967+ (parseInt(m[8], 10) / 1000),
 968+ 'content': $j.trim( m[9] )
 969+ });
 970+ return 'next';
 971+ }
 972+ // Else check for multi-line match:
 973+ if( parseInt( currentPtext ) == currentPtext ){
 974+ if( curentCap.length != 0) {
 975+ captions.push( curentCap );
 976+ }
 977+ curentCap = {
 978+ 'content': ''
 979+ };
 980+ return 'next';
 981+ }
 982+ //Check only for time match:
 983+ var m = currentPtext.replace('--&gt;', '-->').match(/(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?/);
 984+ if (m) {
 985+ curentCap['start']=
 986+ (parseInt(m[1], 10) * 60 * 60) +
 987+ (parseInt(m[2], 10) * 60) +
 988+ (parseInt(m[3], 10)) +
 989+ (parseInt(m[4], 10) / 1000);
 990+ curentCap['end']=
 991+ (parseInt(m[5], 10) * 60 * 60) +
 992+ (parseInt(m[6], 10) * 60) +
 993+ (parseInt(m[7], 10)) +
 994+ (parseInt(m[8], 10) / 1000);
 995+ return 'next';
 996+ }
 997+ //Else content for the curentCap
 998+ if( currentPtext != '<br>' ){
 999+ curentCap['content'] += currentPtext;
 1000+ }
 1001+ });
 1002+ //Push last subtitle:
 1003+ if( curentCap.length != 0){
 1004+ captions.push( curentCap );
 1005+ }
 1006+ return captions;
 1007+ }
9331008 /**
9341009 * srt timed text parse hanndle:
9351010 * @param {String} data Srt string to be parsed
@@ -1071,23 +1146,13 @@
10721147 */
10731148 loadTitleKey: function( titleKey, callback ){
10741149 var request = {
1075 - 'titles': titleKey,
1076 - 'prop':'revisions',
1077 - 'rvprop':'content'
 1150+ 'action': 'parse',
 1151+ 'page': titleKey
10781152 };
1079 - mw.getJSON( this.api_url, request, function( data ){
1080 - if ( data && data.query && data.query.pages ) {
1081 - for ( var i in data.query.pages ) {
1082 - var page = data.query.pages[i];
1083 - if ( page.revisions ) {
1084 - for ( var j in page.revisions ) {
1085 - if ( page.revisions[j]['*'] ) {
1086 - callback( page.revisions[j]['*'] );
1087 - return ;
1088 - }
1089 - }
1090 - }
1091 - }
 1153+ mw.getJSON( this.api_url, request, function( data ){
 1154+ if ( data && data.parse && data.parse.text['*'] ) {
 1155+ callback( data.parse.text['*'] );
 1156+ return;
10921157 }
10931158 mw.log("Error: could not load:" + titleKey);
10941159 callback( false );
@@ -1158,7 +1223,13 @@
11591224 var langKey = subPage.title.split( '.' );
11601225 var extension = langKey.pop();
11611226 langKey = langKey.pop();
1162 -
 1227+
 1228+ //NOTE: we hard code the mw-srt type
 1229+ // ( This is because mediaWiki srt files can have wiki-text and parsed as such )
 1230+ if( extension == 'srt' ){
 1231+ extension = 'mw-srt';
 1232+ }
 1233+
11631234 if ( ! _this.isSuportedLang( langKey ) ) {
11641235 mw.log( 'Error: langkey:' + langKey + ' not supported' );
11651236 } else {
Index: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/remotes/RemoteMwTimedText.js
@@ -2,7 +2,7 @@
33 * Stop-gap for mediaWiki timed text support
44 *
55 * Does some tranformations to normal wiki timed Text pages to make them look
6 -* like the php output that we will eventually want to support
 6+* like the php output that we will eventually want to have
77 */
88 mw.addMessages( {
99 "mwe-language-subtiles-for-clip": "$1 subtitles for clip: $2",
@@ -105,6 +105,9 @@
106106 mw.log("Error: no timedText method on embedPlayer" );
107107 return ;
108108 }
 109+ // Set the userLanguage:
 110+ player.timedText.config.userLanugage = langKey;
 111+
109112 //Make sure the timed text sources are loaded:
110113 player.timedText.setupTextSources( function(){
111114
Index: branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js
@@ -1463,8 +1463,7 @@
14641464 _this['parent_' + method] = _this[method];
14651465 }
14661466 _this[ method ] = playerInterface[method];
1467 - }
1468 -
 1467+ }
14691468 _this.getDuration();
14701469 _this.showPlayer();
14711470 _this.ready_to_play = true;

Status & tagging log