r82780 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82779‎ | r82780 | r82781 >
Date:01:29, 25 February 2011
Author:dale
Status:deferred
Tags:
Comment:
fixed $.cookie object usage
fixed timed text loading to use parser where needed.
Modified paths:
  • /trunk/extensions/MwEmbedSupport/MwEmbedModules/MwEmbedSupport/mwEmbedSupport.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/MediaPlayers.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/TimedText/resources/mw.TimedText.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaTransformOutput.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MwEmbedSupport/MwEmbedModules/MwEmbedSupport/mwEmbedSupport.js
@@ -157,13 +157,13 @@
158158 return 'mw_message_swap_index_' + key + '_' + index;
159159 };
160160
161 - var doSpecialSwap = false;
162 -
163 -
 161+ var doSpecialSwap = false;
164162
 163+ var text = mediaWiki.messages.get( key );
 164+ if( !text){
 165+ return '<' + key + '>';
 166+ }
165167
166 - var text = mediaWiki.messages.get( key )
167 -
168168 // replace links:
169169 text = text.replace( /\[(\S+)\s+([^\]]*)\]/g, function( matched, link, linkText ) {
170170 var indexIdAttribute = '';
Index: trunk/extensions/TimedMediaHandler/TimedMediaTransformOutput.php
@@ -251,7 +251,7 @@
252252 $data = $api->getResultData();
253253 // Get the list of language Names
254254 $langNames = Language::getLanguageNames();
255 -
 255+
256256 if( $data['query'] && $data['query']['allpages'] ){
257257 foreach( $data['query']['allpages'] as $na => $page ){
258258 $subTitle = Title::newFromText( $page['title'] ) ;
@@ -269,6 +269,7 @@
270270 $this->textTracks[] = array(
271271 'kind' => 'subtitles',
272272 'data-mwtitle' => $subTitle->getNsText() . ':' . $subTitle->getDBkey(),
 273+ 'data-mwprovider' => 'local',
273274 'type' => 'text/x-srt',
274275 // TODO Should add a special entry point and output proper WebVTT format:
275276 // http://www.whatwg.org/specs/web-apps/current-work/webvtt.html
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/TimedText/resources/mw.TimedText.js
@@ -18,7 +18,8 @@
1919 mw.mergeConfig( 'EmbedPlayer.SourceAttributes', [
2020 'srclang',
2121 'category',
22 - 'label'
 22+ 'label',
 23+ 'data-mwtitle'
2324 ]);
2425
2526 /**
@@ -129,7 +130,7 @@
130131 // Load user preferences config:
131132 var preferenceConfig = $.cookie( 'TimedText.Prefrences' );
132133 if( preferenceConfig !== null ) {
133 - this.config = preferenceConfig;
 134+ this.config = JSON.parse( preferenceConfig );
134135 }
135136 // Set up embedPlayer hooks:
136137
@@ -398,23 +399,7 @@
399400 loadTextSources: function( callback ) {
400401 var _this = this;
401402 this.textSources = [ ];
402 - // Get local reference to all timed text sources: ( text/xml, text/x-srt etc )
403 - var inlineSources = this.embedPlayer.mediaElement.getSources( 'text' );
404403
405 - // Add all the sources to textSources
406 - for( var i = 0 ; i < inlineSources.length ; i++ ) {
407 - // Make a new textSource:
408 - var source = new TextSource( inlineSources[i] );
409 - this.textSources.push( source );
410 - }
411 -
412 - // If there are inline sources or no apiTitleKey we are done loading
413 - if( this.textSources.length != 0 || !this.embedPlayer.apiTitleKey ) {
414 - // No other sources just issue the callback:
415 - callback();
416 - return ;
417 - }
418 -
419404 // Try to get sources from text provider:
420405 var provider_id = ( this.embedPlayer.apiProvider ) ? this.embedPlayer.apiProvider : 'local';
421406 var apiUrl = mw.getApiProviderURL( provider_id );
@@ -430,6 +415,21 @@
431416 'apiUrl': apiUrl,
432417 'embedPlayer': this.embedPlayer
433418 } );
 419+ // Get local reference to all timed text sources: ( text/xml, text/x-srt etc )
 420+ var inlineSources = this.embedPlayer.mediaElement.getSources( 'text' );
 421+
 422+ // Add all the sources to textSources
 423+ for( var i = 0 ; i < inlineSources.length ; i++ ) {
 424+ // Make a new textSource:
 425+ var source = new TextSource( inlineSources[i] , this.textProvider);
 426+ this.textSources.push( source);
 427+ }
 428+
 429+ // If there are inline sources don't check the api )
 430+ if( this.textSources.length != 0 ){
 431+ callback();
 432+ return ;
 433+ }
434434
435435 // Load the textProvider sources
436436 this.textProvider.loadSources( apiTitleKey, function( textSources ) {
@@ -933,7 +933,7 @@
934934 */
935935 refreshDisplay: function() {
936936 // Update the configuration object
937 - $.cookie( 'TimedText.Prefrences', this.config );
 937+ $.cookie( 'TimedText.Prefrences', JSON.stringify( this.config ) );
938938
939939 // Empty out previous text to force an interface update:
940940 this.prevText = [];
@@ -1071,7 +1071,6 @@
10721072 mw.log(" addItextDiv: " + category );
10731073 // Get the relative positioned player class from the controlBuilder:
10741074 var $playerTarget = this.embedPlayer.$interface;
1075 -
10761075 //Remove any existing track divs for this player;
10771076 $playerTarget.find('.track_' + category ).remove();
10781077
@@ -1165,11 +1164,14 @@
11661165 /**
11671166 * @constructor Inherits mediaSource from embedPlayer
11681167 * @param {source} Base source element
 1168+ * @param {Object} Pointer to the textProvider
11691169 */
1170 - init: function( source , textProvider) {
1171 - for( var i in source) {
1172 - this[i] = source[i];
 1170+ init: function( source , textProvider) {
 1171+ // Inherits mediaSource
 1172+ for( var i in source){
 1173+ this[ i ] = source[ i];
11731174 }
 1175+
11741176 // Set default category to subtitle if unset:
11751177 if( ! this.category ) {
11761178 this.category = 'SUB';
@@ -1177,7 +1179,16 @@
11781180 //Set the textProvider if provided
11791181 if( textProvider ) {
11801182 this.textProvider = textProvider;
 1183+
 1184+ // switch type to mw-srt if we are going to load via api
 1185+ // ( this is need because we want to represent one thing to search engines / crawlers,
 1186+ // while representing the mw-srt type internally so that mediawiki parsed text
 1187+ // gets converted to html before going into the video
 1188+ if( this.mwtitle ){
 1189+ this.mimeType = 'text/mw-srt';
 1190+ }
11811191 }
 1192+ return this;
11821193 },
11831194
11841195 /**
@@ -1195,7 +1206,6 @@
11961207 }
11971208 };
11981209 _this.loaded = true;
1199 -
12001210 // Set parser handler:
12011211 switch( this.getMIMEType() ) {
12021212 //Special mediaWiki srt format ( support wiki-text in srt's )
@@ -1216,13 +1226,12 @@
12171227 mw.log("Error: no handler for type: " + this.getMIMEType() );
12181228 return ;
12191229 }
1220 -
12211230 // Try to load src via textProvider:
1222 - if( this.textProvider && this.titleKey ) {
1223 - this.textProvider.loadTitleKey( this.titleKey, function( data ) {
 1231+ if( this.textProvider && this.mwtitle) {
 1232+ this.textProvider.loadTitleKey( this.mwtitle, function( data ) {
12241233 if( data ) {
12251234 _this.captions = handler( data );
1226 - }
 1235+ }
12271236 mw.log("mw.TimedText:: loaded from titleKey: " + _this.captions.length + ' captions');
12281237 // Update the loaded state:
12291238 _this.loaded = true;
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/MediaPlayers.js
@@ -134,7 +134,7 @@
135135 */
136136 setFormatPreference : function ( mimeFormat ) {
137137 this.preference['formatPreference'] = mimeFormat;
138 - $.cookie( 'EmbedPlayer.Preference', this.preference);
 138+ $.cookie( 'EmbedPlayer.Preference', JSON.stringify( this.preference) );
139139 },
140140
141141 /**
@@ -152,7 +152,7 @@
153153 selectedPlayer = this.players[i];
154154 mw.log( 'EmbedPlayer::setPlayerPreference: choosing ' + playerId + ' for ' + mimeType );
155155 this.preference[ mimeType ] = playerId;
156 - $.cookie( 'EmbedPlayer.Preference', this.preference );
 156+ $.cookie( 'EmbedPlayer.Preference', JSON.stringify( this.preference ) );
157157 break;
158158 }
159159 }
@@ -176,7 +176,7 @@
177177 this.preference = { };
178178 // See if we have a cookie set to a clientSupported type:
179179 if( $.cookie( 'EmbedPlayer.Preference' ) ) {
180 - this.preference = $.cookie( 'EmbedPlayer.Preference' );
 180+ this.preference = JSON.parse( $.cookie( 'EmbedPlayer.Preference' ) );
181181 }
182182 }
183183 };

Status & tagging log