2 * this file exposes some of the functionality of mwEmbed to wikis
3 * that do not yet have js2 enabled
6 var urlparts
= getRemoteEmbedPath();
7 var mwEmbedHostPath
= urlparts
[0];
8 var reqAguments
= urlparts
[1];
10 addOnloadHook( function(){
11 //only do rewrites if MV_EMBED / js2 is "off"
12 if( typeof MV_EMBED_VERSION
== 'undefined' ) {
13 doPageSpecificRewrite();
17 function doPageSpecificRewrite() {
19 if( wgAction
== 'edit' || wgAction
== 'submit' ) {
20 load_mv_embed( function() {
21 loadExternalJs( mwEmbedHostPath
+ '/editPage.js' + reqAguments
);
26 if(wgPageName
.indexOf("TimedText") === 0){
30 // Firefogg integration
31 if( wgPageName
== "Special:Upload" ){
32 load_mv_embed( function() {
33 loadExternalJs( mwEmbedHostPath
+ '/uploadPage.js' + reqAguments
);
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
);
46 // OggHandler rewrite for view pages:
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" ) );
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
);
63 // will be depreciated in favor of updates to OggHandler
64 function rewrite_for_OggHandler( vidIdList
){
65 function procVidId( vidId
){
66 js_log('vidIdList length: ' + vidIdList
.length
+ ' left in the set: ' + vidIdList
);
68 // Grab the thumbnail and src of the video
69 var pimg
= $j( '#' + vidId
+ ' img' );
70 var poster_attr
= 'poster = "' + pimg
.attr( 'src' ) + '" ';
71 var pwidth
= pimg
.attr( 'width' );
72 var pheight
= pimg
.attr( 'height' );
74 var tag_type
= 'video';
77 if( pwidth
== '22' && pheight
== '22' ) {
78 //set width to parent width:
79 pwidth
= $j( '#' + vidId
).width();
88 var wikiTitleKey
= $j( '#'+vidId
+ ' img').filter(':first').attr('alt').replace(/ /g
, '_');
89 var re
= new RegExp( /videoUrl(":?\s*)*([^&]*)/ );
90 src
= re
.exec( $j( '#'+vidId
).html() )[2];
92 var re
= new RegExp( /length(":?\s*)*([^&]*)/ );
93 duration
= re
.exec( $j( '#'+vidId
).html() )[2];
95 var re
= new RegExp( /offset(":?\s*)*([^&]*)/ );
96 offset
= re
.exec( $j( '#'+vidId
).html() )[2];
97 var offset_attr
= offset
? 'startOffset="' + offset
+ '"' : '';
102 var common_attr
= ' id="vid_' + i
+'" '+
103 'wikiTitleKey="' + wikiTitleKey
+ '" ' +
104 'src="' + src
+ '" ' +
105 'durationHint="' + duration
+ '" ' +
108 if( tag_type
== 'audio' ){
109 html_out
='<audio' + common_attr
+ '></audio>'
111 html_out
='<video' + common_attr
+
113 'style="width:' + pwidth
+ 'px;height:' + pheight
+ 'px;">' +
116 //set the video tag inner html and update the height
117 $j( '#' + vidId
).html( html_out
)
118 .css('height', pheight
+ 30);
121 rewrite_by_id( vidId
, function(){
122 if(vidIdList
.length
!= 0){
123 alert('did first rewite now doing another');
124 setTimeout( function(){
125 procVidId( vidIdList
.pop() )
130 //process each item in the vidIdList (with setTimeout to avoid locking)
131 setTimeout( function(){
132 procVidId( vidIdList
.pop() )
135 function getRemoteEmbedPath() {
136 for( var i
= 0; i
< document
.getElementsByTagName( 'script' ).length
; i
++ ) {
137 var s
= document
.getElementsByTagName( 'script' )[i
];
138 if( s
.src
.indexOf( '/remoteMwEmbed.js' ) != -1 ) {
141 if( s
.src
.indexOf( '?' ) != -1) {
142 reqStr
= s
.src
.substr( s
.src
.indexOf( '?' ) );
143 scriptPath
= s
.src
.substr( 0, s
.src
.indexOf( '?' ) ).replace( '/remoteMwEmbed.js', '' );
145 scriptPath
= s
.src
.replace( '/remoteMwEmbed.js', '' )
147 // Use the external_media_wizard path:
148 return [scriptPath
, reqStr
];
153 function load_mv_embed( callback
) {
154 // Inject mv_embed if needed
155 if( typeof $mw
== 'undefined' ) {
156 var mvurl
= mwEmbedHostPath
+ '/mwEmbed/mv_embed.js' + reqAguments
;
157 importScriptURI( mvurl
);
159 check_for_mv_embed( callback
);
162 function check_for_mv_embed( callback
) {
163 if( typeof $mw
== 'undefined' ) {
164 setTimeout( function(){
165 check_for_mv_embed( callback
);