r84939 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84938‎ | r84939 | r84940 >
Date:23:43, 28 March 2011
Author:dale
Status:ok
Tags:
Comment:
bug 28150 fixed local vs remote text providers ( presently only commons is well supported )
Modified paths:
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/TimedText/resources/mw.TimedText.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/handlers/TextHandler/TextHandler.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TimedMediaHandler/handlers/TextHandler/TextHandler.php
@@ -83,6 +83,7 @@
8484 }
8585 wfDebug("Get text tracks from remote api \n");
8686 $query = $this->getTextPagesQuery();
 87+
8788 // Error in getting timed text namespace return empty array;
8889 if( $query === false ){
8990 return array();
@@ -100,7 +101,7 @@
101102 $params = new FauxRequest( $this->getTextPagesQuery() );
102103 $api = new ApiMain( $params );
103104 $api->execute();
104 - $data = $api->getResultData();
 105+ $data = $api->getResultData();
105106 // Get the list of language Names
106107 return $this->getTextTracksFromData( $data );
107108 }
@@ -128,7 +129,6 @@
129130 $interWikiPrefix = ( $providerName == 'local' )? '' : $providerName . ':';
130131
131132 $langNames = Language::getLanguageNames();
132 -
133133 if( $data['query'] && $data['query']['allpages'] ){
134134 foreach( $data['query']['allpages'] as $na => $page ){
135135 $subTitle = Title::newFromText( $interWikiPrefix . $page['title'] ) ;
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/TimedText/resources/mw.TimedText.js
@@ -398,11 +398,13 @@
399399 */
400400 loadTextSources: function( callback ) {
401401 var _this = this;
402 - this.textSources = [ ];
403 -
404 - // Try to get sources from text provider:
405 - var provider_id = ( this.embedPlayer.apiProvider ) ? this.embedPlayer.apiProvider : 'local';
406 - var apiUrl = mw.getApiProviderURL( provider_id );
 402+ this.textSources = [];
 403+
 404+ // Setup the provider id ( set to local if not found )
 405+ var providerId = $( this.embedPlayer ).attr('data-mwprovider') ?
 406+ $( this.embedPlayer ).attr('data-mwprovider') :
 407+ 'local';
 408+ var apiUrl = mw.getApiProviderURL( providerId );
407409 var apiTitleKey = this.embedPlayer.apiTitleKey;
408410 if( !apiUrl || !apiTitleKey ) {
409411 mw.log("Error: loading source without apiProvider or apiTitleKey");
@@ -411,15 +413,21 @@
412414
413415 //For now only support mediaWikTrack provider library
414416 this.textProvider = new mw.MediaWikTrackProvider( {
415 - 'provider_id' : provider_id,
 417+ 'providerId' : providerId,
416418 'apiUrl': apiUrl,
417419 'embedPlayer': this.embedPlayer
418420 } );
 421+
419422 // Get local reference to all timed text sources: ( text/xml, text/x-srt etc )
420423 var inlineSources = this.embedPlayer.mediaElement.getSources( 'text' );
421424
422425 // Add all the sources to textSources
423426 for( var i = 0 ; i < inlineSources.length ; i++ ) {
 427+ // Check if the inline source has a text provider:
 428+ var textSourceProvider = $( this.embedPlayer ).attr('data-mwprovider') ?
 429+ $( this.embedPlayer ).attr('data-mwprovider') :
 430+ this.textProvider;
 431+
424432 // Make a new textSource:
425433 var source = new TextSource( inlineSources[i] , this.textProvider);
426434 this.textSources.push( source);
@@ -672,6 +680,7 @@
673681 },
674682
675683 // Simple interface to add a transcription request
 684+ // TODO this should probably be moved to a gadget
676685 getAddSubRequest: function(){
677686 var _this = this;
678687 var buttons = {};
@@ -1490,8 +1499,8 @@
14911500 */
14921501 var default_textProvider_attr = [
14931502 'apiUrl',
1494 - 'provider_id',
1495 - 'timed_text_NS',
 1503+ 'providerId',
 1504+ 'timedTextNS',
14961505 'embedPlayer'
14971506 ];
14981507
@@ -1504,7 +1513,7 @@
15051514 apiUrl: null,
15061515
15071516 // The timed text namespace
1508 - timed_text_NS: null,
 1517+ timedTextNS: null,
15091518
15101519 /**
15111520 * @constructor
@@ -1526,9 +1535,13 @@
15271536 loadTitleKey: function( titleKey, callback ) {
15281537 var request = {
15291538 'action': 'parse',
1530 - 'page': titleKey,
 1539+ 'page': titleKey
 1540+ /**
 1541+ * For now we don't use cache helpers since the request is
 1542+ * going over jsonp we kill any outer cache anyway
15311543 'smaxage' : 300,
15321544 'maxage' : 300
 1545+ */
15331546 };
15341547 mw.getJSON( this.apiUrl, request, function( data ) {
15351548 if ( data && data.parse && data.parse.text['*'] ) {
@@ -1574,9 +1587,13 @@
15751588 'apprefix' : unescape( titleKey ),
15761589 'apnamespace' : this.getTimedTextNS(),
15771590 'aplimit' : 200,
1578 - 'prop':'revisions',
 1591+ 'prop':'revisions'
 1592+ /**
 1593+ * For now we don't use cache helpers since the request is
 1594+ * going over jsonp we kill any outer cache anyway
15791595 'smaxage' : 300,
15801596 'maxage' : 300
 1597+ */
15811598 };
15821599 mw.getJSON( this.apiUrl, request, function( sourcePages ) {
15831600 // If "timedText" is not a valid namespace try "just" with prefix:
@@ -1635,15 +1652,15 @@
16361653 * Return the namespace ( if not encoded on the page return default 102 )
16371654 */
16381655 getTimedTextNS: function() {
1639 - if( this.timed_text_NS )
1640 - return this.timed_text_NS;
 1656+ if( this.timedTextNS )
 1657+ return this.timedTextNS;
16411658 if ( typeof wgNamespaceIds != 'undefined' && wgNamespaceIds['timedtext'] ) {
1642 - this.timed_text_NS = wgNamespaceIds['timedtext'];
 1659+ this.timedTextNS = wgNamespaceIds['timedtext'];
16431660 }else{
16441661 //default value is 102 ( probably should store this elsewhere )
1645 - this.timed_text_NS = 102;
 1662+ this.timedTextNS = 102;
16461663 }
1647 - return this.timed_text_NS;
 1664+ return this.timedTextNS;
16481665 },
16491666
16501667 /**

Status & tagging log