r60255 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60254‎ | r60255 | r60256 >
Date:08:53, 21 December 2009
Author:dale
Status:deferred
Tags:
Comment:
* Added support for new module structure to script-loader
* Timed Text fixes and stubs for "edit interface"
Modified paths:
  • /branches/js2-work/phase3/js/editPage.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/jsAutoloadLocalClasses.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/loader.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/archiveOrgSearch.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/TimedText/loader.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mvTimeTextEdit.js (deleted) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mw.TimedText.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mw.TimedTextEdit.js (added) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/TimedText/old_mvTimeTextEdit.js (added) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/includes/jsAutoloadLocalClasses.php
@@ -3,26 +3,74 @@
44 if ( !defined( 'MEDIAWIKI' ) ) die( 1 );
55
66 global $wgJSAutoloadLocalClasses, $wgMwEmbedDirectory;
 7+global $wgJSModuleList;
78
 9+// NOTE this is growing in complexity and globals sloppiness
 10+// we should refactor as a class with some static methods
 11+
 12+//Initialize $wgJSModuleList
 13+$wgJSModuleList = array();
 14+
 15+//Initialize $wgLoaderJs
 16+$wgMwEmbedLoaderJs = '';
 17+
818 /**
9 - * loads javascript class name paths from mwEmbed.js
 19+ * Loads javascript class name paths from mwEmbed.js
1020 */
1121 function wfLoadMwEmbedClassPaths ( ) {
12 - global $wgMwEmbedDirectory;
 22+ global $wgMwEmbedDirectory, $wgJSModuleList, $wgMwEmbedLoaderJs;
 23+ //Set up the replace key:
 24+ $ClassReplaceKey = '/mw\.addClassFilePaths\s*\(\s*{(.*)}\s*\)\s*\;/siU';
1325 // Load classes from mwEmbed.js
1426 if ( is_file( $wgMwEmbedDirectory . 'mwEmbed.js' ) ) {
15 -
16 - // NOTE: ideally we could cache this json var and or update it php side per svn release
1727 // Read the file:
1828 $file_content = file_get_contents( $wgMwEmbedDirectory . 'mwEmbed.js' );
1929 // Call jsClassPathLoader() for each lcPaths() call in the JS source
2030 $replace_test = preg_replace_callback(
21 - '/mw\.addClassFilePaths\s*\(\s*{(.*)}\s*\)\s*/siU',
 31+ $ClassReplaceKey,
2232 'wfClassPathLoader',
2333 $file_content
2434 );
 35+
 36+ // Get the list of enabled modules into $wgJSModuleList
 37+ $replace_test = preg_replace_callback(
 38+ '/mwEnabledModuleList\s*\=\s*\[(.*)\]/siU',
 39+ 'wfBuildModuleList',
 40+ $file_content
 41+ );
 42+
 43+ // Get all the classes from the loader files:
 44+ foreach( $wgJSModuleList as $na => $moduleName){
 45+ $file_content = file_get_contents(
 46+ $wgMwEmbedDirectory . 'modules/' . $moduleName . '/loader.js'
 47+ );
 48+ // Add the mwEmbed loader js to its global collector:
 49+ $wgMwEmbedLoaderJs .= $file_content;
 50+
 51+ $replace_test.= preg_replace_callback(
 52+ $ClassReplaceKey,
 53+ 'wfClassPathLoader',
 54+ $file_content
 55+ );
 56+ }
2557 }
2658 }
 59+function wfBuildModuleList( $jsvar ){
 60+ global $wgMwEmbedDirectory, $wgJSModuleList;
 61+ if(! isset( $jsvar[1] )){
 62+ return false;
 63+ }
 64+ $moduleSet = explode(',', $jsvar[1] );
 65+
 66+ foreach( $moduleSet as $na => $module ){
 67+ $moduleName = str_replace( array( '../', '\'', '"'), '', trim( $module ));
 68+ // Check if there is there are module loader files
 69+ if( is_file( $wgMwEmbedDirectory . 'modules/' . $moduleName . '/loader.js' )){
 70+ array_push( $wgJSModuleList, $moduleName );
 71+ }
 72+ }
 73+ return '';
 74+}
2775 function wfClassPathLoader( $jvar ) {
2876 global $wgJSAutoloadLocalClasses, $wgMwEmbedDirectory;
2977 if ( !isset( $jvar[1] ) )
Index: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mvTimeTextEdit.js
@@ -1,158 +0,0 @@
2 -/*
3 - * JS2-style mvTimedTextEdit.js
4 - */
5 -
6 -// Setup configuration vars (if not set already)
7 -if ( !mwAddMediaConfig )
8 - var mwAddMediaConfig = { };
9 -
10 -var mvTimeTextEdit = { };
11 -
12 -mw.addMessages( {
13 - "mwe-upload-subs-file" : "Upload subtitle",
14 - "mwe-add-subs-file-title" : "Select subtitle to upload",
15 - "mwe-error-only-srt" : "You can only upload srt files.",
16 - "mwe-watch-video" : "Watch video",
17 - "mwe-select-other-language" : "Select another language",
18 - "mwe-saving" : "saving..."
19 -} )
20 -
21 -
22 -mw.ready( function() {
23 - function getSubtitle( f ) {
24 - var name = f.files[0].name;
25 - var srtData = f.files[0].getAsBinary();
26 - srtData = srtData.replace( '\r\n', '\n' );
27 - return srtData;
28 - }
29 - function getVideoTitle() {
30 - var videoTitle = wgPageName.split( '.' );
31 - videoTitle.pop();
32 - videoTitle.pop();
33 - videoTitle = videoTitle.join( '.' ).replace( 'TimedText:', 'File:' );
34 - return videoTitle;
35 - }
36 - function uploadSubtitles() {
37 - var request = {
38 - 'meta' : 'siteinfo',
39 - 'siprop' : 'languages'
40 - };
41 - mw.getJSON( request, function( langDataRaw ) {
42 - var apprefix = wgTitle.split( '.' );
43 - apprefix.pop();
44 - apprefix.pop();
45 - apprefix = apprefix.join( '.' );
46 - var request = {
47 - 'list' : 'allpages',
48 - 'apprefix' : apprefix
49 - };
50 - mw.getJSON(request, function( subData ) {
51 - var availableSubtitles = { };
52 - for ( var i in subData.query.allpages ) {
53 - var subPage = subData.query.allpages[i];
54 - var langKey = subPage.title.split( '.' );
55 - var extension = langKey.pop();
56 - langKey = langKey.pop();
57 - availableSubtitles[langKey] = subPage.title;
58 - }
59 - var langData = { };
60 - var languageSelect = '<select id="timed_text_language">';
61 -
62 - var lagRaw = langDataRaw.query.languages;
63 - for ( var j in lagRaw ) {
64 - var code = lagRaw[j].code;
65 - var language = lagRaw[j]['*'];
66 - langData[ code ] = language;
67 - languageSelect += '<option value="' + code + '">';
68 - if ( availableSubtitles[code] ) {
69 - languageSelect += language + '(' + code + ') +';
70 - } else {
71 - languageSelect += language + '(' + code + ') -';
72 - }
73 - languageSelect += '</option>';
74 - }
75 - languageSelect += '/</select>';
76 - var cBtn = { };
77 - cBtn[ gM( 'mwe-cancel' ) ] = function() {
78 - $j( this ).dialog( 'close' );
79 - }
80 - cBtn[ gM( 'mwe-ok' ) ] = function() {
81 - // get language from form
82 - langKey = $j( '#timed_text_language' ).val();
83 - var title = wgPageName.split( '.' );
84 - title.pop();
85 - title.pop();
86 - title = title.join( '.' ) + '.' + langKey + '.srt';
87 -
88 - var file = $j( '#timed_text_file_upload' );
89 - if ( !file[0].files[0] ) {
90 - // no file to upload just jump to the lang key:
91 - document.location.href = wgArticlePath.replace( '/$1', '?title=' + title + '&action=edit' );
92 - return ;
93 - }
94 - var langKey = file[0].files[0].name.split( '.' );
95 - var extension = langKey.pop();
96 - langKey = langKey.pop();
97 - var mimeTypes = {
98 - 'srt': 'text/x-srt',
99 - 'cmml': 'text/cmml'
100 - }
101 - if ( !mimeTypes[ extension ] ) {
102 - mw.log( 'Error: unknown extension:' + extension );
103 - }
104 -
105 -
106 - if ( extension == "srt" ) {
107 - var srt = getSubtitle( file[0] );
108 - $j( this ).text( gM( 'mwe-saving' ) );
109 - $j( '.ui-dialog-buttonpane' ).remove();
110 -
111 - var editToken = $j( 'input[name=wpEditToken]' ).val();
112 - var request = {
113 - 'action' : 'edit',
114 - 'title' : title,
115 - 'text' : srt,
116 - 'token': editToken
117 - };
118 - mw.getJSON( request, function( dialog ) {
119 - return function( result ) {
120 - document.location.href = wgArticlePath.replace( '/$1', '?title=' + title + '&action=edit' );
121 - $j( dialog ).dialog( 'close' );
122 - }
123 - }( this ) );
124 - } else {
125 - $j( this ).html( gM( "mwe-error-only-srt" ) );
126 - }
127 - }
128 - $j.addDialog( gM( "mwe-add-subs-file-title" ),
129 - '<input type="file" id="timed_text_file_upload"></input><br />' + languageSelect,
130 - cBtn );
131 - $j( '#timed_text_file_upload' ).change( function( ev ) {
132 - if ( this.files[0] ) {
133 - var langKey = this.files[0].name.split( '.' );
134 - var extension = langKey.pop();
135 - langKey = langKey.pop();
136 - $j( '#timed_text_language' ).val( langKey );
137 - }
138 - } );
139 - } );
140 - } );
141 - }
142 - var tselect = ( $j( '#wikiEditor-ui-top' ).length != 0 ) ? '#wikiEditor-ui-top':'#toolbar';
143 - $j( tselect ).hide();
144 - var ttoolbar = $j( '<div>' );
145 - $j( tselect ).after( ttoolbar );
146 -
147 - var button = $j( '<button>' );
148 - button.click( uploadSubtitles )
149 - button.text( gM( "mwe-upload-subs-file" ) );
150 - ttoolbar.append( button );
151 - ttoolbar.append( ' ' );
152 -
153 - var button = $j( '<button>' );
154 - button.click( function() { document.location.href = wgArticlePath.replace( '$1', getVideoTitle() ); } )
155 - button.text( gM( "mwe-watch-video" ) );
156 - ttoolbar.append( button );
157 -
158 -} );
159 -
Index: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/loader.js
@@ -3,6 +3,7 @@
44 */
55 mw.addClassFilePaths( {
66 "mw.TimedText" : "modules/TimedText/mw.TimedText.js",
 7+ "mw.TimedTextEdit" : "modules/TimedText/mw.TimedTextEdit.js",
78 "$j.fn.menu" : "modules/TimedText/jquery.menu.js"
89 });
910
Index: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mw.TimedText.js
@@ -19,6 +19,8 @@
2020 mw.addMessages( {
2121 "mwe-back-btn" : "Back",
2222 "mwe-chose-text" : "Chose text",
 23+ "mwe-add-timed-text" : "Add timed text",
 24+ "mwe-loading-text-edit" : "Loading timed text editor",
2325
2426 "mwe-search" : "Search clip",
2527
@@ -74,7 +76,7 @@
7577 },
7678
7779 /**
78 - * The list of enabled sources
 80+ * The list of enabled sources
7981 */
8082 enabledSources: [ ],
8183
@@ -107,8 +109,16 @@
108110 "LIN",
109111 "CUE"
110112 ],
111 -
 113+
112114 /**
 115+ * Timed text extension to mime map
 116+ */
 117+ timedTextExtMime: {
 118+ 'srt': 'text/x-srt',
 119+ 'cmml': 'text/cmml'
 120+ },
 121+
 122+ /**
113123 * Set of timedText providers
114124 */
115125 timedTextProviders:{
@@ -154,6 +164,7 @@
155165 /**
156166 * Show the timed text menu
157167 * @param {Object} target to display the menu
 168+ * @param {Bollean} autoShow If the menu should be displayed
158169 */
159170 bindMenu: function( target , autoShow ){
160171 var _this = this;
@@ -193,8 +204,7 @@
194205
195206 for( var i in this.enabledSources ) {
196207 var source = this.enabledSources[ i ];
197 - this.updateSourceDisplay( source, currentTime );
198 -
 208+ this.updateSourceDisplay( source, currentTime );
199209 }
200210 },
201211
@@ -204,12 +214,14 @@
205215 * @param {Function} callback Function to call once text sources are loaded
206216 */
207217 loadTextSources: function( callback ){
 218+ var _this = this;
 219+ this.textSources = [ ];
208220 // Get local reference to all timed text sources: ( text/xml, text/x-srt etc )
209221 var inlineSources = this.embedPlayer.mediaElement.getSources( 'text' );
210222 //add all the sources to textSources
211223 for( var i in inlineSources ){
212224 // make a new textSource:
213 - var source = new textSource( inlineSources[i] );
 225+ var source = new TextSource( inlineSources[i] );
214226 this.textSources.push( source );
215227 }
216228
@@ -221,22 +233,39 @@
222234 callback();
223235 return ;
224236 }
225 - // Else try to get sources from text provider:
 237+ // Try to get sources from text provider:
226238 var provider = this.timedTextProviders[ textProviderId ];
227239 var assetKey = this.embedPlayer.wikiTitleKey;
228240 switch( provider.lib ){
229241 case 'mediaWiki':
230242 this.textProvider = new mw.MediaWikiTextProvider( {
231 - api_url: provider.api_url
 243+ 'provider_id' : textProviderId,
 244+ 'api_url': provider.api_url,
 245+ 'embedPlayer': this.embedPlayer
232246 });
233247 break;
234 - }
 248+ }
235249 // Load the textProvider sources
236250 this.textProvider.loadSources( assetKey, function( textSources ){
237 - for( var i in textSources ){
238 - var source = textSources[ i ];
239 - this.textSources.push( source );
240 - }
 251+ for( var i in textSources ){
 252+ var textSource = textSources[ i ];
 253+ // Try to insert the itext source:
 254+ var textElm = document.createElement( 'itext' );
 255+ $j( textElm ).attr( {
 256+ 'category' : 'SUB',
 257+ 'lang' : textSource.lang,
 258+ 'type' : _this.timedTextExtMime[ textSource.extension ],
 259+ 'titleKey' : textSource.titleKey
 260+ } );
 261+ //debugger;
 262+ // Add the sources to the parent embedPlayer
 263+ // ( in case other interfaces want to access them )
 264+ var embedSource = _this.embedPlayer.mediaElement.tryAddSource( textElm );
 265+ // Get a "textSource" object:
 266+ var source = new TextSource( embedSource, _this.textProvider);
 267+ _this.textSources.push( source );
 268+ }
 269+ // All sources loaded run callback:
241270 callback();
242271 } );
243272 },
@@ -329,12 +358,24 @@
330359 var _this = this;
331360 // Build the source list menu item:
332361
333 - return $j( '<ul>' ).append(
334 - // Chose language option:
335 - _this.getLi( gM( 'mwe-chose-text') ).append(
336 - _this.getLanguageMenu()
337 - ),
 362+ $menu = $j( '<ul>' );
 363+ // Chouse text menu item ( if there are sources)
 364+ if( _this.textSources.length != 0 ){
 365+ $menu.append(
 366+ _this.getLi( gM( 'mwe-chose-text') ).append(
 367+ _this.getLanguageMenu()
 368+ )
 369+ )
 370+ }else{
 371+ // Put in the "Make Transcript" link
 372+ $menu.append(
 373+ _this.getLi( gM( 'mwe-add-timed-text'), 'script', function(){
 374+ _this.showTimedTextEditUI( 'add' );
 375+ } )
 376+ );
338377
 378+ }
 379+ $menu.append(
339380 // Layout Menu option
340381 _this.getLi( gM( 'mwe-layout' ) ).append(
341382 _this.getLayoutMenu()
@@ -343,9 +384,27 @@
344385 // Search Menu option
345386 _this.getLi( gM('mwe-search'), 'search')
346387 );
 388+ return $menu;
347389 },
348390
349391 /**
 392+ * Shows the timed text edit ui
 393+ */
 394+
 395+ showTimedTextEditUI: function( mode ){
 396+ var _this = this;
 397+ // Show a loader:
 398+ $j.addLoaderDialog( gM( 'mwe-loading-text-edit' ));
 399+ // Load the timedText edit interface
 400+ mw.load( 'mw.TimedTextEdit', function(){
 401+ $j.closeLoaderDialog();
 402+ if( ! _this.editText ){
 403+ _this.editText = new mw.TimedTextEdit();
 404+ }
 405+ _this.editText.showUI();
 406+ })
 407+ },
 408+ /**
350409 * Utility function to assist in menu build out:
351410 * Get menu line item (li) html: <li><a> msgKey </a></li>
352411 *
@@ -370,7 +429,7 @@
371430
372431 if( source.lang ){
373432 var langKey = source.lang.toLowerCase();
374 - mw.languages[ langKey ];
 433+ _this.getLanguageName ( langKey );
375434 return this.getLi(
376435 gM('mwe-key-language', [langKey, unescape( mw.languages[ source.lang ] ) ] ),
377436 sourceIcon,
@@ -398,6 +457,15 @@
399458 $li.find( 'a' ).append( $j('<span>').text( string ) );
400459 return $li;
401460 },
 461+ /**
 462+ * Get lagnuage name from language key
 463+ */
 464+ getLanguageName: function( lang_key ){
 465+ if( mw.languages[ lang_key ]){
 466+ return mw.languages[ lang_key ];
 467+ }
 468+ return false
 469+ },
402470
403471 /**
404472 * Builds and returns the "layout" menu
@@ -463,7 +531,7 @@
464532 */
465533 selectTextSource: function( source ){
466534 var _this = this;
467 - mw.log(" select source: " + source.lang );
 535+ mw.log(" select source: " + source.lang );
468536
469537 // Update the config language if the source includes language
470538 if( source.lang )
@@ -531,20 +599,33 @@
532600 sourcesWithoutCategory.push( _this.getLiSource( source ) );
533601 }
534602 }
535 - var $langMenu = $j('<ul>');
536 - for(var catKey in catSourceList){
537 - $catChildren = $j('<ul>');
538 - for(var i in catSourceList[ catKey ]){
539 - $catChildren.append(
540 - catSourceList[ catKey ][i]
541 - )
 603+ var $langMenu = $j('<ul>');
 604+ // Check if we have multiple categories ( if not just list them under the parent menu item)
 605+ if( catSourceList.length > 1 ){
 606+ for(var catKey in catSourceList){
 607+ $catChildren = $j('<ul>');
 608+ for(var i in catSourceList[ catKey ]){
 609+ $catChildren.append(
 610+ catSourceList[ catKey ][i]
 611+ )
 612+ }
 613+ // Append a cat menu item for each category list
 614+ $langMenu.append(
 615+ _this.getLi( gM( 'mwe-textcat-' + catKey.toLowerCase() ) ).append(
 616+ $catChildren
 617+ )
 618+ );
542619 }
543 - $langMenu.append(
544 - _this.getLi( gM( 'mwe-textcat-' + catKey.toLowerCase() ) ).append(
545 - $catChildren
546 - )
547 - );
 620+ } else {
 621+ for(var catKey in catSourceList){
 622+ for(var i in catSourceList[ catKey ]){
 623+ $langMenu.append(
 624+ catSourceList[ catKey ][i]
 625+ )
 626+ }
 627+ }
548628 }
 629+
549630 for(var i in sourcesWithoutCategory){
550631 $langMenu.append( sourcesWithoutCategory[i] )
551632 }
@@ -566,8 +647,7 @@
567648 mw.log( 'updateTextDisplay: ' + text );
568649
569650 var $player = $j( '#' + this.embedPlayer.id);
570 - var $textTarget = $player.find( '.itext_' + source.category + ' span' );
571 -
 651+ var $textTarget = $player.find( '.itext_' + source.category + ' span' );
572652 // If we are missing the target add it:
573653 if( $textTarget.length == 0){
574654 this.addItextDiv( source.category )
@@ -650,10 +730,10 @@
651731 * TextSource object extends a base mediaSource object
652732 * with some timedText features
653733 */
654 - var textSource = function( source ){
655 - return this.init( source );
 734+ TextSource = function( source , textProvider){
 735+ return this.init( source, textProvider );
656736 }
657 - textSource.prototype = {
 737+ TextSource.prototype = {
658738
659739 //The load state:
660740 loaded: false,
@@ -670,7 +750,7 @@
671751 * @constructor Inherits mediaSource from embedPlayer
672752 * @param {source} Base source element
673753 */
674 - init: function( source ){
 754+ init: function( source , textProvider){
675755 for( var i in source){
676756 this[i] = source[i];
677757 }
@@ -678,6 +758,10 @@
679759 if( ! this.category ){
680760 this.category = 'SUB';
681761 }
 762+ //Set the textProvider if provided
 763+ if( textProvider ){
 764+ this.textProvider = textProvider;
 765+ }
682766 },
683767
684768 /**
@@ -686,6 +770,7 @@
687771 */
688772 load: function( callback ){
689773 var _this = this;
 774+
690775 //check if its already loaded:
691776 if( _this.loaded ){
692777 if( callback ){
@@ -700,6 +785,9 @@
701786 case 'text/cmml':
702787 var handler = parseCMML;
703788 break;
 789+ case 'text/html':
 790+ var handler = parseSrtHTML;
 791+ break;
704792 default:
705793 var hanlder = null;
706794 break;
@@ -707,22 +795,38 @@
708796 if( !handler ){
709797 mw.log("Error: no handler for type: " + this.getMIMEType() );
710798 return ;
 799+ }
 800+ // Try to load src via src attr:
 801+ if( this.getSrc() ){
 802+ // Issue the load request ( if we can )
 803+ if ( mw.parseUri( document.URL ).host != mw.parseUri( this.getSrc() ).host ){
 804+ mw.log("Error can't load non-json src via jsonp:" + this.getSrc() )
 805+ return ;
 806+ }
 807+ $j.get( this.getSrc(), function( data ){
 808+ // Parse and load captions:
 809+ _this.captions = handler( data );
 810+ // Update the loaded state:
 811+ _this.loaded = true;
 812+ if( callback ){
 813+ callback();
 814+ }
 815+ }, 'text' );
 816+ return ;
 817+ }
 818+
 819+ // Try to load src via provider:
 820+ if( this.textProvider && this.titleKey ){
 821+ this.textProvider.loadTitleKey( this.titleKey, function( data ){
 822+ if( data ){
 823+ _this.captions = handler( data );
 824+ }
 825+ if( callback ){
 826+ callback();
 827+ }
 828+ return ;
 829+ });
711830 }
712 - // Issue the load request ( if we can )
713 - //if ( mw.parseUri( document.URL ).host != mw.parseUri( this.getSrc() ).host ){
714 - // mw.log("Error can't load non-json src via jsonp:" + this.getSrc() )
715 - // return ;
716 - //}
717 -
718 - $j.get( this.getSrc(), function( data ){
719 - // Parse and load captions:
720 - _this.captions = handler( data );
721 - // Update the loaded state:
722 - _this.loaded = true;
723 - if( callback ){
724 - callback();
725 - }
726 - }, 'text' );
727831 },
728832
729833 /**
@@ -858,27 +962,66 @@
859963 }
860964
861965 */
862 -
 966+ var default_textProvider_attr = [
 967+ 'api_url',
 968+ 'provider_id',
 969+ 'timed_text_NS',
 970+ 'embedPlayer'
 971+ ];
 972+
863973 mw.MediaWikiTextProvider = function( options ){
864974 this.init( options )
865975 }
866976 mw.MediaWikiTextProvider.prototype = {
 977+
 978+ // The api url:
867979 api_url: null,
868 - timedTextNS: null,
 980+
 981+ // The timed text namespace
 982+ timed_text_NS: null,
 983+
869984 /**
870985 * @constructor
871986 * @param {Object} options Set of options for the provider
872987 */
873988 init: function( options ){
874 - //Set the api url:
875 - if( options.api_url ){
876 - this.api_url = options.api_url
877 - }
878 - if( options.timedTextNS ){
879 - this.timedTextNS = options.timedTextNS
 989+ for(var i in default_textProvider_attr){
 990+ var attr = default_textProvider_attr[ i ];
 991+ if( options[ attr ] )
 992+ this[ attr ] = options[ attr ];
 993+
880994 }
881995 },
882996
 997+ /**
 998+ * Loads a single text source by titleKey
 999+ * @param {titleKey}
 1000+ */
 1001+ loadTitleKey: function( titleKey, callback ){
 1002+ var request = {
 1003+ 'titles': titleKey,
 1004+ 'prop':'revisions',
 1005+ 'rvprop':'content'
 1006+ };
 1007+ mw.getJSON( this.api_url, request, function( data ){
 1008+ if ( data && data.query && data.query.pages ) {
 1009+ for ( var i in data.query.pages ) {
 1010+ var page = data.query.pages[i];
 1011+ if ( page.revisions ) {
 1012+ for ( var j in page.revisions ) {
 1013+ if ( page.revisions[j]['*'] ) {
 1014+ callback( page.revisions[j]['*'] );
 1015+ return ;
 1016+ }
 1017+ }
 1018+ }
 1019+ }
 1020+ }
 1021+ mw.log("Error: could not load:" + titleKey);
 1022+ callback( false );
 1023+ } );
 1024+ },
 1025+
8831026 /**
8841027 * Loads all available source for a given assetKey
8851028 *
@@ -886,23 +1029,26 @@
8871030 */
8881031 loadSources: function( assetKey, callback ){
8891032 var request = {};
890 - this.getSubPages( assetKey, function( subPages ){
891 - mw.log(' got sub pages... ');
892 - if( !subData.query.allpages ){
 1033+ var _this = this;
 1034+ this.getSourcePages( assetKey, function( sourcePages ){
 1035+ mw.log(' got sub pages... ');
 1036+ if( ! sourcePages.query.allpages ){
 1037+ //Check if a shared asset
8931038 mw.log( 'no subtitle pages found');
8941039 callback();
8951040 return ;
8961041 }
897 - _this.getSources( subPages )
898 - } );
 1042+ // We have sources put them into the player
 1043+ callback( _this.getSources( sourcePages ) );
 1044+ } );
8991045 },
9001046
901 - /*
 1047+ /**
9021048 * Get the subtitle pages
9031049 * @param {String} titleKey Title to get subtitles for
9041050 * @param {Function} callback Function to call once NS subs are grabbed
9051051 */
906 - getSubPages: function( titleKey, callback ){
 1052+ getSourcePages: function( titleKey, callback ){
9071053 var _this = this;
9081054 var request = {
9091055 'list' : 'allpages',
@@ -910,88 +1056,82 @@
9111057 'apnamespace' : this.getTimedTextNS(),
9121058 'prop':'revisions'
9131059 };
914 - mw.getJSON( this.api_url, request, function( subPages ) {
915 - if ( subPages.error && subPages.error.code == 'apunknown_apnamespace' ) {
 1060+ mw.getJSON( this.api_url, request, function( sourcePages ) {
 1061+ if ( sourcePages.error && sourcePages.error.code == 'apunknown_apnamespace' ) {
9161062 var request = {
9171063 'list' : 'allpages',
9181064 'apprefix' : _this.getCanonicalTimedTextNS() + ':' + _this.pe.wikiTitleKey
9191065 };
920 - mw.getJSON( apiUrl, request, function( subData ) {
921 - callback( subPages )
 1066+ mw.getJSON( apiUrl, request, function( sourcePages ) {
 1067+ callback( sourcePages )
9221068 } );
9231069 } else {
924 - callback( subPages );
 1070+ callback( sourcePages );
9251071 }
9261072 } );
9271073 },
 1074+
9281075 /**
929 - * Return the namespace (if not encoded on the page return default
 1076+ * get the sources from sourcePages data object
 1077+ * Put valid sources into the embedPlayer
9301078 */
931 - getTimedTextNS: function(){
932 - if( this.timedTextNS )
933 - return this.timedTextNS;
934 - if ( typeof wgNamespaceIds != 'undefined' && wgNamespaceIds['timedtext'] ) {
935 - this.timedTextNS = wgNamespaceIds['timedtext'];
936 - }else{
937 - //default value is 102 ( probably should store this elsewhere )
938 - this.timedTextNS = 102;
939 - }
940 - return this.timedTextNS;
941 - },
942 - /*
943 - * Return the namespace text
944 - */
945 - getCanonicalTimedTextNS: function(){
946 - return 'TimedText';
947 - },
948 - /**
949 - * Populate the sources
950 - */
951 - getSources: function( subData ) {
 1079+ getSources: function( sourcePages ) {
9521080 var _this = this;
9531081 // look for text tracks:
9541082 var foundTextTracks = false;
955 -
956 - for ( var i in subData.query.allpages ) {
 1083+ var sources = [];
 1084+ for ( var i in sourcePages.query.allpages ) {
9571085
958 - var subPage = subData.query.allpages[i];
 1086+ var subPage = sourcePages.query.allpages[i];
9591087 var langKey = subPage.title.split( '.' );
9601088 var extension = langKey.pop();
9611089 langKey = langKey.pop();
962 -
963 - if ( ! _this.suportedMime[ extension ] ) {
964 - mw.log( 'Error: unknown extension:' + extension );
965 - continue;
966 - }
9671090
968 - if ( !langData[ langKey] ) {
969 - mw.log( 'Error: langkey:' + langKey + ' not found' );
 1091+ if ( ! _this.isSuportedLang( langKey ) ) {
 1092+ mw.log( 'Error: langkey:' + langKey + ' not supported' );
9701093 } else {
971 - var textElm = document.createElement( 'text' );
972 - $j( textElm ).attr( {
973 - 'category' : 'SUB',
974 - 'lang' : langKey,
975 - 'type' : _this.suportedMime[ extension ],
976 - 'title' : langData[ langKey]
977 - } );
978 - // We use the api since ?action raw on the real title has cache issues
979 - $j( textElm ).attr( {
980 - 'apisrc' : hostPath + '/api.php',
981 - 'titleKey' : subPage.title
982 - } );
983 - _this.pe.media_element.tryAddSource( textElm );
984 - foundTextTracks = true;
 1094+ sources.push( {
 1095+ 'extension': extension,
 1096+ 'lang': langKey,
 1097+ 'titleKey': subPage.title
 1098+ } );
9851099 }
9861100 }
987 - // after all text loaded (or we have allready checked commons
988 - if ( foundTextTracks || hostPath.indexOf( 'commons.wikimedia' ) !== -1 ) {
989 - // alert('calling getParseTimedText_rowReady ');
990 - _this.getParseTimedText_rowReady();
991 - } else {
992 - _this.checkSharedRepo();
 1101+ return sources;
 1102+ },
 1103+
 1104+ /**
 1105+ * Return the namespace (if not encoded on the page return default 102 )
 1106+ */
 1107+ getTimedTextNS: function(){
 1108+ if( this.timed_text_NS )
 1109+ return this.timed_text_NS;
 1110+ if ( typeof wgNamespaceIds != 'undefined' && wgNamespaceIds['timedtext'] ) {
 1111+ this.timed_text_NS = wgNamespaceIds['timedtext'];
 1112+ }else{
 1113+ //default value is 102 ( probably should store this elsewhere )
 1114+ this.timed_text_NS = 102;
9931115 }
994 - }
 1116+ return this.timed_text_NS;
 1117+ },
9951118
 1119+ /**
 1120+ * Get the Canonical timed text namespace text
 1121+ */
 1122+ getCanonicalTimedTextNS: function(){
 1123+ return 'TimedText';
 1124+ },
 1125+
 1126+ /**
 1127+ * Check if the language is supported
 1128+ */
 1129+ isSuportedLang: function( lang_key ){
 1130+ if( mw.languages[ lang_key ]){
 1131+ return true;
 1132+ }
 1133+ return false;
 1134+ }
 1135+
9961136 }
9971137
9981138
Index: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/old_mvTimeTextEdit.js
@@ -0,0 +1,158 @@
 2+/*
 3+ * JS2-style mvTimedTextEdit.js
 4+ */
 5+
 6+// Setup configuration vars (if not set already)
 7+if ( !mwAddMediaConfig )
 8+ var mwAddMediaConfig = { };
 9+
 10+var mvTimeTextEdit = { };
 11+
 12+mw.addMessages( {
 13+ "mwe-upload-subs-file" : "Upload subtitle",
 14+ "mwe-add-subs-file-title" : "Select subtitle to upload",
 15+ "mwe-error-only-srt" : "You can only upload srt files.",
 16+ "mwe-watch-video" : "Watch video",
 17+ "mwe-select-other-language" : "Select another language",
 18+ "mwe-saving" : "saving..."
 19+} )
 20+
 21+
 22+mw.ready( function() {
 23+ function getSubtitle( f ) {
 24+ var name = f.files[0].name;
 25+ var srtData = f.files[0].getAsBinary();
 26+ srtData = srtData.replace( '\r\n', '\n' );
 27+ return srtData;
 28+ }
 29+ function getVideoTitle() {
 30+ var videoTitle = wgPageName.split( '.' );
 31+ videoTitle.pop();
 32+ videoTitle.pop();
 33+ videoTitle = videoTitle.join( '.' ).replace( 'TimedText:', 'File:' );
 34+ return videoTitle;
 35+ }
 36+ function uploadSubtitles() {
 37+ var request = {
 38+ 'meta' : 'siteinfo',
 39+ 'siprop' : 'languages'
 40+ };
 41+ mw.getJSON( request, function( langDataRaw ) {
 42+ var apprefix = wgTitle.split( '.' );
 43+ apprefix.pop();
 44+ apprefix.pop();
 45+ apprefix = apprefix.join( '.' );
 46+ var request = {
 47+ 'list' : 'allpages',
 48+ 'apprefix' : apprefix
 49+ };
 50+ mw.getJSON(request, function( subData ) {
 51+ var availableSubtitles = { };
 52+ for ( var i in subData.query.allpages ) {
 53+ var subPage = subData.query.allpages[i];
 54+ var langKey = subPage.title.split( '.' );
 55+ var extension = langKey.pop();
 56+ langKey = langKey.pop();
 57+ availableSubtitles[langKey] = subPage.title;
 58+ }
 59+ var langData = { };
 60+ var languageSelect = '<select id="timed_text_language">';
 61+
 62+ var lagRaw = langDataRaw.query.languages;
 63+ for ( var j in lagRaw ) {
 64+ var code = lagRaw[j].code;
 65+ var language = lagRaw[j]['*'];
 66+ langData[ code ] = language;
 67+ languageSelect += '<option value="' + code + '">';
 68+ if ( availableSubtitles[code] ) {
 69+ languageSelect += language + '(' + code + ') +';
 70+ } else {
 71+ languageSelect += language + '(' + code + ') -';
 72+ }
 73+ languageSelect += '</option>';
 74+ }
 75+ languageSelect += '/</select>';
 76+ var cBtn = { };
 77+ cBtn[ gM( 'mwe-cancel' ) ] = function() {
 78+ $j( this ).dialog( 'close' );
 79+ }
 80+ cBtn[ gM( 'mwe-ok' ) ] = function() {
 81+ // get language from form
 82+ langKey = $j( '#timed_text_language' ).val();
 83+ var title = wgPageName.split( '.' );
 84+ title.pop();
 85+ title.pop();
 86+ title = title.join( '.' ) + '.' + langKey + '.srt';
 87+
 88+ var file = $j( '#timed_text_file_upload' );
 89+ if ( !file[0].files[0] ) {
 90+ // no file to upload just jump to the lang key:
 91+ document.location.href = wgArticlePath.replace( '/$1', '?title=' + title + '&action=edit' );
 92+ return ;
 93+ }
 94+ var langKey = file[0].files[0].name.split( '.' );
 95+ var extension = langKey.pop();
 96+ langKey = langKey.pop();
 97+ var mimeTypes = {
 98+ 'srt': 'text/x-srt',
 99+ 'cmml': 'text/cmml'
 100+ }
 101+ if ( !mimeTypes[ extension ] ) {
 102+ mw.log( 'Error: unknown extension:' + extension );
 103+ }
 104+
 105+
 106+ if ( extension == "srt" ) {
 107+ var srt = getSubtitle( file[0] );
 108+ $j( this ).text( gM( 'mwe-saving' ) );
 109+ $j( '.ui-dialog-buttonpane' ).remove();
 110+
 111+ var editToken = $j( 'input[name=wpEditToken]' ).val();
 112+ var request = {
 113+ 'action' : 'edit',
 114+ 'title' : title,
 115+ 'text' : srt,
 116+ 'token': editToken
 117+ };
 118+ mw.getJSON( request, function( dialog ) {
 119+ return function( result ) {
 120+ document.location.href = wgArticlePath.replace( '/$1', '?title=' + title + '&action=edit' );
 121+ $j( dialog ).dialog( 'close' );
 122+ }
 123+ }( this ) );
 124+ } else {
 125+ $j( this ).html( gM( "mwe-error-only-srt" ) );
 126+ }
 127+ }
 128+ $j.addDialog( gM( "mwe-add-subs-file-title" ),
 129+ '<input type="file" id="timed_text_file_upload"></input><br />' + languageSelect,
 130+ cBtn );
 131+ $j( '#timed_text_file_upload' ).change( function( ev ) {
 132+ if ( this.files[0] ) {
 133+ var langKey = this.files[0].name.split( '.' );
 134+ var extension = langKey.pop();
 135+ langKey = langKey.pop();
 136+ $j( '#timed_text_language' ).val( langKey );
 137+ }
 138+ } );
 139+ } );
 140+ } );
 141+ }
 142+ var tselect = ( $j( '#wikiEditor-ui-top' ).length != 0 ) ? '#wikiEditor-ui-top':'#toolbar';
 143+ $j( tselect ).hide();
 144+ var ttoolbar = $j( '<div>' );
 145+ $j( tselect ).after( ttoolbar );
 146+
 147+ var button = $j( '<button>' );
 148+ button.click( uploadSubtitles )
 149+ button.text( gM( "mwe-upload-subs-file" ) );
 150+ ttoolbar.append( button );
 151+ ttoolbar.append( ' ' );
 152+
 153+ var button = $j( '<button>' );
 154+ button.click( function() { document.location.href = wgArticlePath.replace( '$1', getVideoTitle() ); } )
 155+ button.text( gM( "mwe-watch-video" ) );
 156+ ttoolbar.append( button );
 157+
 158+} );
 159+
Property changes on: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/old_mvTimeTextEdit.js
___________________________________________________________________
Name: svn:eol-style
1160 + native
Index: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mw.TimedTextEdit.js
@@ -0,0 +1,21 @@
 2+/**
 3+* Timed text edit interface based off of participatory culture foundation timed text mockups.
 4+*/
 5+
 6+mw.TimedTextEdit = function(){
 7+ return this.init();
 8+}
 9+mw.TimedTextEdit.prototype = {
 10+ /**
 11+ * @constructor
 12+ */
 13+ init: function(){
 14+
 15+ },
 16+ /**
 17+ * Show the editor UI
 18+ */
 19+ showUI: function(){
 20+
 21+ }
 22+}
\ No newline at end of file
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/archiveOrgSearch.js
@@ -74,7 +74,7 @@
7575 var resource = data.response.docs[resource_id];
7676 var resource = {
7777 // @@todo we should add .ogv or oga if video or audio:
78 - 'titleKey' : resource.identifier + '.ogg',
 78+ 'titleKey' : resource.identifier + '.ogv',
7979 'resourceKey': resource.identifier,
8080 'link' : _this.detailsUrl + resource.identifier,
8181 'title' : resource.title,
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/loader.js
@@ -4,6 +4,7 @@
55 mw.addMessages( {
66 "mwe-loading-add-media-wiz" : "Loading add media wizard"
77 });
 8+
89 // Add class file paths ( From ROOT )
910 mw.addClassFilePaths( {
1011 "$j.fn.dragDropFile" : "modules/AddMedia/jquery.dragDropFile.js",
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js
@@ -147,8 +147,8 @@
148148 }
149149 }
150150
151 - $.addMediaWiz = function( options ){
152 - $.fn.addMediaWiz ( options, function( amwObj ) {
 151+ $.addMediaWizard = function( options ){
 152+ $.fn.addMediaWizard ( options, function( amwObj ) {
153153 // do the add-media-wizard display
154154 amwObj.createUI();
155155 } )
Index: branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js
@@ -189,12 +189,6 @@
190190 // media codecs attribute ( if provided )
191191 'codecs',
192192
193 - // api url ( used for timed text sources )
194 - 'apisrc',
195 -
196 - // titleKey ( used for api lookups )
197 - 'titleKey',
198 -
199193 // Title string for the source asset
200194 'title',
201195
@@ -219,7 +213,16 @@
220214 'default',
221215
222216 // Language key used for subtitle tracks
223 - 'lang'
 217+ 'lang',
 218+
 219+ // titleKey ( used for api lookups )
 220+ 'titleKey',
 221+
 222+ // The provider type ( for what type of api querie to make )
 223+ 'provider_type',
 224+
 225+ // The api url for the provider
 226+ 'provider_url'
224227 );
225228
226229 // Set the browser player warning flag to true by default ( applies to all players so its not part of attribute defaults above )
@@ -375,9 +378,13 @@
376379 case 'audio':
377380 var element_id = element_id;
378381 var playerInx = _this.playerList.length;
379 -
 382+ var ranPlayerSwapFlag = false;
380383 // Local callback to runPlayer swap once element has metadat
381 - function runPlayerSwap(){
 384+ function runPlayerSwap(){
 385+ mw.log("runPlayerSwap" );
 386+ if( ranPlayerSwapFlag )
 387+ return ;
 388+ ranPlayerSwapFlag = true;
382389 var playerInterface = new mw.EmbedPlayer( element , attributes);
383390 _this.swapEmbedPlayerElement( element, playerInterface );
384391
@@ -389,6 +396,8 @@
390397 mw.log(" WaitForMeta ( video missing height width info and has src )");
391398 element.removeEventListener( "loadedmetadata", runPlayerSwap, true );
392399 element.addEventListener( "loadedmetadata", runPlayerSwap, true );
 400+ // Time-out of 3 seconds ( maybe still playable but no timely metadata )
 401+ setTimeout( runPlayerSwap, 3000 );
393402 }else{
394403 runPlayerSwap( element_id )
395404 }
@@ -558,6 +567,11 @@
559568 // End time in npt format
560569 end_npt: null,
561570
 571+ // A provider "id" to idenfiy api request type
 572+ provider_type : null,
 573+
 574+ // The api url for the provider
 575+ provider_url : null,
562576
563577 /**
564578 * MediaSource constructor:
@@ -623,11 +637,13 @@
624638 // if we have time we can use:
625639 if ( this.URLTimeEncoding ) {
626640 // make sure its a valid start time / end time (else set default)
627 - if ( !mw.npt2seconds( start_npt ) )
 641+ if ( !mw.npt2seconds( start_npt ) ){
628642 start_npt = this.start_npt;
629 -
630 - if ( !mw.npt2seconds( end_npt ) )
 643+ }
 644+
 645+ if ( !mw.npt2seconds( end_npt ) ){
631646 end_npt = this.end_npt;
 647+ }
632648
633649 this.src = mw.replaceUrlParams( this.src, {
634650 't': start_npt + '/' + end_npt
@@ -839,7 +855,7 @@
840856 this.durationHint = $j( video_element ).attr( 'durationHint' );
841857 // Convert duration hint if needed:
842858 this.duration = mw.npt2seconds( this.durationHint );
843 - }
 859+ }
844860
845861 // Process the video_element as a source element:
846862 if ( $j( video_element ).attr( "src" ) )
@@ -1049,7 +1065,7 @@
10501066 if ( this.sources[i].src == new_src ) {
10511067 // Source already exists update any new attr:
10521068 this.sources[i].updateSource( element );
1053 - return ;
 1069+ return this.sources[i];
10541070 }
10551071 }
10561072 }
@@ -1062,7 +1078,8 @@
10631079 source.startOffset = praserFloat( this.startOffset );
10641080
10651081 mw.log( 'pushed source to stack' + source + 'sl:' + this.sources.length );
1066 - this.sources.push( source );
 1082+ this.sources.push( source );
 1083+ return source;
10671084 },
10681085
10691086 /**
@@ -1266,11 +1283,11 @@
12671284 *
12681285 * @param {Element} element Source element to grab size from
12691286 */
1270 - setPlayerSize:function( element ){
 1287+ setPlayerSize:function( element ){
12711288 this['height'] = parseInt( $j(element).css( 'height' ).replace( 'px' , '' ) );
12721289 this['width'] = parseInt( $j(element).css( 'width' ).replace( 'px' , '' ) );
12731290
1274 - if( ! this['height'] && ! this['width'] ){
 1291+ if( !this['height'] && !this['width'] ){
12751292 this['height'] = parseInt( $j(element).attr( 'height' ) );
12761293 this['width'] = parseInt( $j(element).attr( 'width' ) );
12771294 }
@@ -1290,8 +1307,7 @@
12911308
12921309 // On load sometimes attr is temporally -1 as we don't have video metadata yet.
12931310 // NOTE: this edge case should be handled by waiting for metadata see: "waitForMeta" in addElement
1294 - if( ( !this['height'] || !this['width'] ) ||
1295 - ( this['height'] == -1 || this['width'] == -1 ) ||
 1311+ if( ( this['height'] == -1 || this['width'] == -1 ) ||
12961312 // Check for firefox defaults
12971313 // Note: ideally firefox would not do random guesses at css values
12981314 ( (this.height == 150 || this.height == 64 ) && this.width == 300 )
@@ -2530,14 +2546,16 @@
25312547 var dl_list = '';
25322548 var dl_txt_list = '';
25332549 $j.each( _this.mediaElement.getSources(), function( index, source ) {
2534 - var dl_line = '<li>' + '<a style="color:white" href="' + source.getSrc() + '"> '
2535 - + source.getTitle() + '</a> ' + '</li>' + "\n";
2536 - if ( source.getSrc().indexOf( '?t=' ) !== -1 ) {
2537 - out += dl_line;
2538 - } else if ( this.getMIMEType() == "text/cmml" || this.getMIMEType() == "text/x-srt" ) {
2539 - dl_txt_list += dl_line;
2540 - } else {
2541 - dl_list += dl_line;
 2550+ if( source.getSrc() ){
 2551+ var dl_line = '<li>' + '<a style="color:white" href="' + source.getSrc() + '"> '
 2552+ + source.getTitle() + '</a> ' + '</li>' + "\n";
 2553+ if ( source.getSrc().indexOf( '?t=' ) !== -1 ) {
 2554+ out += dl_line;
 2555+ } else if ( this.getMIMEType() == "text/cmml" || this.getMIMEType() == "text/x-srt" ) {
 2556+ dl_txt_list += dl_line;
 2557+ } else {
 2558+ dl_list += dl_line;
 2559+ }
25422560 }
25432561 } );
25442562
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -26,38 +26,41 @@
2727 }
2828
2929 /**
 30+* The set of modules that you want enable.
 31+*
 32+* Each enabledModules array value should be a name
 33+* of a folder in mwEmbed/modules
 34+*
 35+* Modules must define a loader.js file in the root
 36+* of the module folder.
 37+*
 38+* The loader file should be short and only include:
 39+* Class paths of the module classes
 40+* Sytle sheets of the module
 41+* Loader function(s) that load module classes
 42+*
 43+* When using the scriptLoader the enabledModules loader code
 44+* is transcluded into base mwEmbed class include.
 45+*/
 46+var mwEnabledModuleList = [
 47+ 'AddMedia',
 48+ 'ClipEdit',
 49+ 'EmbedPlayer',
 50+ 'ApiProxy',
 51+ 'Sequencer',
 52+ 'TimedText'
 53+];
 54+
 55+/**
3056 * Default global config values. Configuration values are set via mw.setConfig
3157 * Configuration values should generally be set prior to dom-ready
3258 */
3359 var mwDefaultConf = {
3460
35 - /**
36 - * The set of modules that you want enable.
37 - *
38 - * Each enabledModules array value should be a name
39 - * of a folder in mwEmbed/modules
40 - *
41 - * Modules must define a loader.js file in the root
42 - * of the module folder.
43 - *
44 - * The loader file should be short and only include:
45 - * Class paths of the module classes
46 - * Sytle sheets of the module
47 - * Loader function(s) that load module classes
48 - *
49 - * When using the scriptLoader the enabledModules loader code
50 - * is transcluded into base mwEmbed class include.
51 - */
52 - 'enabledModules' : [
53 - 'AddMedia',
54 - 'ClipEdit',
55 - 'EmbedPlayer',
56 - 'ApiProxy',
57 - 'Sequencer',
58 - 'TimedText'
59 - ],
6061
 62+ 'enabledModules' : mwEnabledModuleList,
6163
 64+
6265 // Default skin name
6366 'skinName' : 'mvpcf',
6467
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
@@ -91,7 +91,14 @@
9292 if( $jstxt ){
9393 $this->jsout .= $this->doProcessJs( $jstxt );
9494 }
 95+
 96+ // If the special mwEmbed class entry point (include loader js
 97+ if( $classKey == 'mwEmbed' ){
 98+ global $wgMwEmbedLoaderJs;
 99+ $this->jsout .= $wgMwEmbedLoaderJs;
 100+ }
95101 }
 102+
96103 // Check if we should minify the whole thing:
97104 if ( !$this->debug ) {
98105 $this->jsout = self::getMinifiedJs( $this->jsout , $this->requestKey );
@@ -106,7 +113,7 @@
107114 if ( $this->error_msg != '' ) {
108115 //just set the content type (don't send cache header)
109116 header( 'Content-Type: text/javascript' );
110 - echo 'alert(\'Error With ScriptLoader.php ::' . str_replace( "\n", '\'+"\n"+' . "\n'", $this->error_msg ) . '\');';
 117+ echo 'alert(\'Error With ScriptLoader ::' . str_replace( "\n", '\'+"\n"+' . "\n'", $this->error_msg ) . '\');';
111118 echo trim( $this->jsout );
112119 } else {
113120 // All good, let's output "cache" headers
Index: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js
@@ -20,17 +20,23 @@
2121 // Use wikibits onLoad hook: ( since we don't have js2 / mw object loaded )
2222 addOnloadHook( function() {
2323 // Only do rewrites if mwEmbed / js2 is "off"
24 - if ( typeof mwEmbed_VERSION == 'undefined' ) {
25 - setTimeout(function(){
26 - doPageSpecificRewrite();
27 - }, 200 );
 24+ if ( typeof mwEmbed_VERSION == 'undefined' ) {
 25+ doPageSpecificRewrite();
2826 }
2927 } );
3028
3129 /**
3230 * Page specific rewrites for mediaWiki
3331 */
34 -function doPageSpecificRewrite() {
 32+
 33+// Deal with multiple doPageSpecificRewrite
 34+if( !ranRewrites){
 35+ var ranRewrites = 'none';
 36+}
 37+function doPageSpecificRewrite() {
 38+ if( ranRewrites != 'none')
 39+ return ;
 40+ ranRewrites = 'done';
3541 // Add media wizard
3642 if ( wgAction == 'edit' || wgAction == 'submit' ) {
3743 loadMwEmbed( [
@@ -80,11 +86,10 @@
8187 var vidIdList = [];
8288 var divs = document.getElementsByTagName( 'div' );
8389 for ( var i = 0; i < divs.length; i++ ) {
84 - if ( divs[i].id && divs[i].id.substring( 0, 11 ) == 'ogg_player_' ) {
85 - if( divs[i].getAttribute( "id" ) != 'ogg_player_2' )
86 - vidIdList.push( divs[i].getAttribute( "id" ) );
 90+ if ( divs[i].id && divs[i].id.substring( 0, 11 ) == 'ogg_player_' ) {
 91+ vidIdList.push( divs[i].getAttribute( "id" ) );
8792 }
88 - }
 93+ }
8994 if ( vidIdList.length > 0 ) {
9095 var jsSetVideo = [ 'embedPlayer', '$j.ui', 'ctrlBuilder', '$j.cookie', '$j.ui.slider', 'kskinConfig' ];
9196 // Quick sniff use java if IE and native if firefox
@@ -117,14 +122,14 @@
118123 if ( !vidId )
119124 return ;
120125
121 - mw.log( 'vidIdList on: ' + vidId + ' length: ' + vidIdList.length + ' left in the set: ' + vidIdList );
 126+ mw.log( 'vidIdList on: ' + vidId + ' id:' + $j('#' + vidId ).length + ' length: ' + vidIdList.length + ' left in the set: ' + vidIdList );
122127
123128 tag_type = 'video';
124129
125130 // Check type:
126131 var pwidth = $j( '#' + vidId ).width();
127132 var $pimg = $j( '#' + vidId + ' img:first' );
128 - if( $pimg.attr('src').split('/').pop() == 'play.png'){
 133+ if( $pimg.attr('src') && $pimg.attr('src').split('/').pop() == 'play.png'){
129134 tag_type = 'audio';
130135 poster_attr = '';
131136 pheight = 0;
@@ -132,27 +137,32 @@
133138 var poster_attr = 'poster = "' + $pimg.attr( 'src' ) + '" ';
134139 var pheight = $pimg.attr( 'height' );
135140 }
136 -
137 -
 141+
138142 // Parsed values:
139143 var src = '';
140144 var duration_attr = '';
141 -
 145+ var rewriteHTML = $j( '#' + vidId ).html();
142146
 147+ if( rewriteHTML == ''){
 148+ mw.log( "Error: empty rewrite html" );
 149+ return ;
 150+ }else{
 151+ mw.log(" rewrite: " + rewriteHTML + "\n of type: " + typeof rewriteHTML);
 152+ }
143153 var re = new RegExp( /videoUrl(&quot;:?\s*)*([^&]*)/ );
144 - src = re.exec( $j( '#' + vidId ).html() )[2];
 154+ src = re.exec( rewriteHTML )[2];
145155
146156 var wikiTitleKey = src.split( '/' );
147157 wikiTitleKey = unescape( wikiTitleKey[ wikiTitleKey.length - 1 ] );
148158
149159 var re = new RegExp( /length(&quot;:?\s*)*([^,]*)/ );
150 - var dv = re.exec( $j( '#' + vidId ).html() )[2];
 160+ var dv = re.exec( rewriteHTML )[2];
151161 if ( dv ) {
152162 duration_attr = 'durationHint="' + dv + '" ';
153163 }
154164
155165 var re = new RegExp( /offset(&quot;:?\s*)*([^,&]*)/ );
156 - offset = re.exec( $j( '#' + vidId ).html() )[2];
 166+ offset = re.exec( rewriteHTML )[2];
157167 var offset_attr = offset ? 'startOffset="' + offset + '"' : '';
158168
159169 if ( src ) {
@@ -166,7 +176,11 @@
167177 'class="kskin" ';
168178
169179 if ( tag_type == 'audio' ) {
170 - html_out = '<audio' + common_attr + ' style="width:' + pwidth + 'px;"></audio>';
 180+ if( pwidth < 250 ){
 181+ pwidth = 250;
 182+ }
 183+ html_out = '<audio' + common_attr + ' ' +
 184+ 'style="width:' + pwidth + 'px;height:0px;"></audio>';
171185 } else {
172186 html_out = '<video' + common_attr +
173187 poster_attr + ' ' +
@@ -179,10 +193,10 @@
180194
181195 // Do the actual rewrite
182196 $j( '#mwe_' + vidId ).embedPlayer( function() {
183 - if ( vidIdList.length != 0 ) {
 197+ if ( vidIdList.length != 0 ) {
184198 setTimeout( function() {
185199 procVidId( vidIdList.pop() )
186 - }, 10 );
 200+ }, 10 );
187201 }
188202 } );
189203
Index: branches/js2-work/phase3/js/editPage.js
@@ -44,7 +44,7 @@
4545 $.addLoaderDialog( gM( 'mwe-loading-add-media-wiz' ) );
4646 mw.load( 'AddMedia.addMediaWizard', function(){
4747 $.closeLoaderDialog();
48 - $j.addMediaWiz( amwConf );
 48+ $j.addMediaWizard( amwConf );
4949 });
5050 }
5151 };
@@ -62,7 +62,7 @@
6363
6464 $j( '#btn-add-media-wiz' ).attr( 'title', gM( 'mwe-loading-add-media-wiz' ) );
6565 mw.load( 'AddMedia.addMediaWizard', function(){
66 - $j( '#btn-add-media-wiz' ).addMediaWiz(
 66+ $j( '#btn-add-media-wiz' ).addMediaWizard(
6767 amwConf
6868 );
6969 });
@@ -73,7 +73,9 @@
7474 mw.log( 'Failed to bind via build section bind via target:' );
7575 $j( ".tool[rel='file']" ).attr( 'title', gM( 'mwe-loading-add-media-wiz' ) );
7676 mw.load( 'AddMedia.addMediaWizard', function(){
77 - $j( ".tool[rel='file']" ).unbind().addMediaWiz( amwConf );
 77+ if( $j( ".tool[rel='file']" ).length != 0 ){
 78+ $j( ".tool[rel='file']" ).unbind().addMediaWizard( amwConf );
 79+ }
7880 });
7981 }
8082 }

Status & tagging log