2 * this file exposes some of the functionality of mwEmbed to wikis
3 * that do not yet have js2 enabled
5 var urlparts
= getRemoteEmbedPath();
6 var mwEmbedHostPath
= urlparts
[0];
7 var reqAguments
= urlparts
[1];
9 addOnloadHook( function(){
10 //only do rewrites if MV_EMBED / js2 is "off"
11 if( typeof MV_EMBED_VERSION
== 'undefined' ) {
12 doPageSpecificRewrite();
16 function doPageSpecificRewrite() {
18 if( wgAction
== 'edit' || wgAction
== 'submit' ) {
19 load_mv_embed( function() {
20 loadExternalJs( mwEmbedHostPath
+ '/editPage.js' + reqAguments
);
25 if(wgPageName
.indexOf("TimedText") === 0){
26 load_mv_embed( function() {
27 loadExternalJs( mwEmbedHostPath
+ '/mwEmbed/libTimedText/mvTimeTextEdit.js' + reqAguments
);
31 // Firefogg integration
32 if( wgPageName
== "Special:Upload" ){
33 load_mv_embed( function() {
34 loadExternalJs( mwEmbedHostPath
+ '/uploadPage.js' + reqAguments
);
38 // Special api proxy page
39 if( wgPageName
== 'MediaWiki:ApiProxy' ){
40 var wgEnableIframeApiProxy
= true;
41 load_mv_embed( function() {
42 js_log("Wiki:ApiProxy::");
43 loadExternalJs( mwEmbedHostPath
+ '/apiProxyPage.js' + reqAguments
);
47 // OggHandler rewrite for view pages:
49 var divs
= document
.getElementsByTagName( 'div' );
50 for( var i
= 0; i
< divs
.length
; i
++ ) {
51 if( divs
[i
].id
&& divs
[i
].id
.substring( 0, 11 ) == 'ogg_player_' ) {
52 vidIdList
.push( divs
[i
].getAttribute( "id" ) );
55 if( vidIdList
.length
> 0 ) {
56 load_mv_embed( function() {
57 mvJsLoader
.embedVideoCheck( function() {
58 // Do utility rewrite of OggHandler content:
59 rewrite_for_OggHandler( vidIdList
);
64 // will be depreciated in favor of updates to OggHandler
65 function rewrite_for_OggHandler( vidIdList
){
66 function procVidId( vidId
){
67 //don't process empty vids
70 js_log('vidIdList on: ' + vidId
+' length: ' + vidIdList
.length
+ ' left in the set: ' + vidIdList
);
72 // Grab the thumbnail and src of the video
73 var pimg
= $j( '#' + vidId
+ ' img' );
74 var poster_attr
= 'poster = "' + pimg
.attr( 'src' ) + '" ';
75 var pwidth
= $j( '#' + vidId
).width();
76 var pheight
= $j( '#' + vidId
).height();
78 var tag_type
= 'video';
81 if( pheight
== '22' || pheight
== '52') {
82 //set width to parent width:
89 var duration_attr
= '';
90 var wikiTitleKey
= $j( '#'+vidId
+ ' img').filter(':first').attr('src').split('/');
91 wikiTitleKey
= unescape( wikiTitleKey
[ wikiTitleKey
.length
- 2 ] );
92 var re
= new RegExp( /videoUrl(":?\s*)*([^&]*)/ );
93 src
= re
.exec( $j( '#'+vidId
).html() )[2];
95 var re
= new RegExp( /length(":?\s*)*([^,]*)/ );
96 var dv
= re
.exec( $j( '#'+vidId
).html() )[2];
98 duration_attr
= 'durationHint="'+ dv
+'" ';
101 var re
= new RegExp( /offset(":?\s*)*([^&]*)/ );
102 offset
= re
.exec( $j( '#'+vidId
).html() )[2];
103 var offset_attr
= offset
? 'startOffset="' + offset
+ '"' : '';
108 var common_attr
= ' id="mwe_' + vidId
+'" '+
109 'wikiTitleKey="' + wikiTitleKey
+ '" ' +
110 'src="' + src
+ '" ' +
114 if( tag_type
== 'audio' ){
115 html_out
='<audio' + common_attr
+ ' style="width:' + pwidth
+ 'px;"></audio>';
117 html_out
='<video' + common_attr
+
119 'style="width:' + pwidth
+ 'px;height:' + pheight
+ 'px;">' +
122 //set the video tag inner html and update the height
123 $j( '#' + vidId
).html( html_out
)
124 .css('height', pheight
+ 30);
127 rewrite_by_id( 'mwe_' + vidId
, function(){
128 if( vidIdList
.length
!= 0 ){
129 setTimeout( function(){
130 procVidId( vidIdList
.pop() )
135 //process each item in the vidIdList (with setTimeout to avoid locking)
136 procVidId( vidIdList
.pop() );
138 function getRemoteEmbedPath() {
139 for( var i
= 0; i
< document
.getElementsByTagName( 'script' ).length
; i
++ ) {
140 var s
= document
.getElementsByTagName( 'script' )[i
];
141 if( s
.src
.indexOf( '/remoteMwEmbed.js' ) != -1 ) {
144 if( s
.src
.indexOf( '?' ) != -1) {
145 reqStr
= s
.src
.substr( s
.src
.indexOf( '?' ) );
146 scriptPath
= s
.src
.substr( 0, s
.src
.indexOf( '?' ) ).replace( '/remoteMwEmbed.js', '' );
148 scriptPath
= s
.src
.replace( '/remoteMwEmbed.js', '' )
150 // Use the external_media_wizard path:
151 return [scriptPath
, reqStr
];
156 function load_mv_embed( callback
) {
157 // Inject mv_embed if needed
158 if( typeof $mw
== 'undefined' ) {
159 var mvurl
= mwEmbedHostPath
+ '/mwEmbed/mv_embed.js' + reqAguments
;
160 importScriptURI( mvurl
);
162 check_for_mv_embed( callback
);
165 function check_for_mv_embed( callback
) {
166 if( typeof $mw
== 'undefined' ) {
167 setTimeout( function(){
168 check_for_mv_embed( callback
);