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 //don't proccess empty vids
69 js_log('vidIdList on: ' + vidId
+' length: ' + vidIdList
.length
+ ' left in the set: ' + vidIdList
);
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' );
77 var tag_type
= 'video';
80 if( pwidth
== '22' && pheight
== '22' ) {
81 //set width to parent width:
82 pwidth
= $j( '#' + vidId
).width();
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(":?\s*)*([^&]*)/ );
94 src
= re
.exec( $j( '#'+vidId
).html() )[2];
96 var re
= new RegExp( /length(":?\s*)*([^,]*)/ );
97 var dv
= re
.exec( $j( '#'+vidId
).html() )[2];
99 duration_attr
= 'durationHint="'+ dv
+'" ';
102 var re
= new RegExp( /offset(":?\s*)*([^&]*)/ );
103 offset
= re
.exec( $j( '#'+vidId
).html() )[2];
104 var offset_attr
= offset
? 'startOffset="' + offset
+ '"' : '';
109 var common_attr
= ' id="mwe_' + vidId
+'" '+
110 'wikiTitleKey="' + wikiTitleKey
+ '" ' +
111 'src="' + src
+ '" ' +
115 if( tag_type
== 'audio' ){
116 html_out
='<audio' + common_attr
+ '></audio>'
118 html_out
='<video' + common_attr
+
120 'style="width:' + pwidth
+ 'px;height:' + pheight
+ 'px;">' +
123 //set the video tag inner html and update the height
124 $j( '#' + vidId
).html( html_out
)
125 .css('height', pheight
+ 30);
128 rewrite_by_id( 'mwe_' + vidId
, function(){
129 if( vidIdList
.length
!= 0 ){
130 setTimeout( function(){
131 procVidId( vidIdList
.pop() )
136 //process each item in the vidIdList (with setTimeout to avoid locking)
137 procVidId( vidIdList
.pop() );
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 ) {
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', '' );
149 scriptPath
= s
.src
.replace( '/remoteMwEmbed.js', '' )
151 // Use the external_media_wizard path:
152 return [scriptPath
, reqStr
];
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
);
163 check_for_mv_embed( callback
);
166 function check_for_mv_embed( callback
) {
167 if( typeof $mw
== 'undefined' ) {
168 setTimeout( function(){
169 check_for_mv_embed( callback
);