* fixed subtitles language msg
[lhc/web/wiklou.git] / js2 / remoteMwEmbed.js
1 /*
2 * this file exposes some of the functionality of mwEmbed to wikis
3 * that do not yet have js2 enabled
4 */
5
6 var urlparts = getRemoteEmbedPath();
7 var mwEmbedHostPath = urlparts[0];
8 var reqAguments = urlparts[1];
9
10 addOnloadHook( function(){
11 //only do rewrites if MV_EMBED / js2 is "off"
12 if( typeof MV_EMBED_VERSION == 'undefined' ) {
13 doPageSpecificRewrite();
14 }
15 });
16
17 function doPageSpecificRewrite() {
18 // Add media wizard
19 if( wgAction == 'edit' || wgAction == 'submit' ) {
20 load_mv_embed( function() {
21 loadExternalJs( mwEmbedHostPath + '/editPage.js' + reqAguments );
22 } );
23 }
24
25 //timed text dispaly:
26 if(wgPageName.indexOf("TimedText") === 0){
27
28 }
29
30 // Firefogg integration
31 if( wgPageName == "Special:Upload" ){
32 load_mv_embed( function() {
33 loadExternalJs( mwEmbedHostPath + '/uploadPage.js' + reqAguments );
34 } );
35 }
36
37 // Special api proxy page
38 if( wgPageName == 'MediaWiki:ApiProxy' ){
39 var wgEnableIframeApiProxy = true;
40 load_mv_embed( function() {
41 js_log("Wiki:ApiProxy::");
42 loadExternalJs( mwEmbedHostPath + '/apiProxyPage.js' + reqAguments );
43 });
44 }
45
46 // OggHandler rewrite for view pages:
47 var vidIdList = [];
48 var divs = document.getElementsByTagName( 'div' );
49 for( var i = 0; i < divs.length; i++ ) {
50 if( divs[i].id && divs[i].id.substring( 0, 11 ) == 'ogg_player_' ) {
51 vidIdList.push( divs[i].getAttribute( "id" ) );
52 }
53 }
54 if( vidIdList.length > 0 ) {
55 load_mv_embed( function() {
56 mvJsLoader.embedVideoCheck( function() {
57 // Do utility rewrite of OggHandler content:
58 rewrite_for_OggHandler( vidIdList );
59 } );
60 } );
61 }
62 }
63 // will be depreciated in favor of updates to OggHandler
64 function rewrite_for_OggHandler( vidIdList ){
65 function procVidId( vidId ){
66 //don't proccess empty vids
67 if(!vidId)
68 return ;
69 js_log('vidIdList on: ' + vidId +' length: ' + vidIdList.length + ' left in the set: ' + vidIdList );
70
71 // Grab the thumbnail and src of the video
72 var pimg = $j( '#' + vidId + ' img' );
73 var poster_attr = 'poster = "' + pimg.attr( 'src' ) + '" ';
74 var pwidth = pimg.attr( 'width' );
75 var pheight = pimg.attr( 'height' );
76
77 var tag_type = 'video';
78
79 // Check for audio
80 if( pwidth == '22' && pheight == '22' ) {
81 //set width to parent width:
82 pwidth = $j( '#' + vidId ).width();
83 pheight = '100';
84 tag_type = 'audio';
85 poster_attr = '';
86 }
87
88 // Parsed values:
89 var src = '';
90 var duration_attr = '';
91 var wikiTitleKey = $j( '#'+vidId + ' img').filter(':first').attr('src').split('/');
92 wikiTitleKey = unescape( wikiTitleKey[ wikiTitleKey.length - 2 ] );
93 var re = new RegExp( /videoUrl(&quot;:?\s*)*([^&]*)/ );
94 src = re.exec( $j( '#'+vidId ).html() )[2];
95
96 var re = new RegExp( /length(&quot;:?\s*)*([^,]*)/ );
97 var dv = re.exec( $j( '#'+vidId ).html() )[2];
98 if( dv ){
99 duration_attr = 'durationHint="'+ dv +'" ';
100 }
101
102 var re = new RegExp( /offset(&quot;:?\s*)*([^&]*)/ );
103 offset = re.exec( $j( '#'+vidId ).html() )[2];
104 var offset_attr = offset ? 'startOffset="' + offset + '"' : '';
105
106 if( src ) {
107 var html_out = '';
108
109 var common_attr = ' id="mwe_' + vidId +'" '+
110 'wikiTitleKey="' + wikiTitleKey + '" ' +
111 'src="' + src + '" ' +
112 duration_attr +
113 offset_attr + ' ';
114
115 if( tag_type == 'audio' ){
116 html_out='<audio' + common_attr + '></audio>'
117 }else{
118 html_out='<video' + common_attr +
119 poster_attr + ' ' +
120 'style="width:' + pwidth + 'px;height:' + pheight + 'px;">' +
121 '</video>';
122 }
123 //set the video tag inner html and update the height
124 $j( '#' + vidId ).html( html_out )
125 .css('height', pheight + 30);
126
127 }
128 rewrite_by_id( 'mwe_' + vidId, function(){
129 if( vidIdList.length != 0 ){
130 setTimeout( function(){
131 procVidId( vidIdList.pop() )
132 }, 1);
133 }
134 });
135 };
136 //process each item in the vidIdList (with setTimeout to avoid locking)
137 procVidId( vidIdList.pop() );
138 }
139 function getRemoteEmbedPath() {
140 for( var i = 0; i < document.getElementsByTagName( 'script' ).length; i++ ) {
141 var s = document.getElementsByTagName( 'script' )[i];
142 if( s.src.indexOf( '/remoteMwEmbed.js' ) != -1 ) {
143 var reqStr = '';
144 var scriptPath = '';
145 if( s.src.indexOf( '?' ) != -1) {
146 reqStr = s.src.substr( s.src.indexOf( '?' ) );
147 scriptPath = s.src.substr( 0, s.src.indexOf( '?' ) ).replace( '/remoteMwEmbed.js', '' );
148 } else {
149 scriptPath = s.src.replace( '/remoteMwEmbed.js', '' )
150 }
151 // Use the external_media_wizard path:
152 return [scriptPath, reqStr];
153 }
154 }
155 }
156
157 function load_mv_embed( callback ) {
158 // Inject mv_embed if needed
159 if( typeof $mw == 'undefined' ) {
160 var mvurl = mwEmbedHostPath + '/mwEmbed/mv_embed.js' + reqAguments ;
161 importScriptURI( mvurl );
162 }
163 check_for_mv_embed( callback );
164 }
165
166 function check_for_mv_embed( callback ) {
167 if( typeof $mw == 'undefined' ) {
168 setTimeout( function(){
169 check_for_mv_embed( callback );
170 }, 25 );
171 } else {
172 callback();
173 }
174 }