r85675 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85674‎ | r85675 | r85676 >
Date:17:28, 8 April 2011
Author:dale
Status:deferred
Tags:
Comment:
renamed MediaWikiPlayerSupport to mw.MediaWikiPlayerSupport.js
Modified paths:
  • /trunk/extensions/MwEmbedSupport/MwEmbedModules/MediaWikiSupport/MediaWikiSupport.php (modified) (history)
  • /trunk/extensions/MwEmbedSupport/MwEmbedModules/MediaWikiSupport/resources/MediaWikiPlayerSupport.js (deleted) (history)
  • /trunk/extensions/MwEmbedSupport/MwEmbedModules/MediaWikiSupport/resources/mw.MediaWikiPlayerSupport.js (added) (history)
  • /trunk/extensions/MwEmbedSupport/MwEmbedModules/MwEmbedSupport/mwEmbedSupport.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MwEmbedSupport/MwEmbedModules/MediaWikiSupport/MediaWikiSupport.php
@@ -2,7 +2,7 @@
33
44 return array(
55 "MediaWikiPlayerSupport" => array(
6 - 'scripts' => 'resources/MediaWikiPlayerSupport.js',
 6+ 'scripts' => 'resources/mw.MediaWikiPlayerSupport.js',
77 'dependencies'=> array(
88 'mw.Api'
99 )
Index: trunk/extensions/MwEmbedSupport/MwEmbedModules/MediaWikiSupport/resources/MediaWikiPlayerSupport.js
@@ -1,265 +0,0 @@
2 -
3 -( function( mw, $ ) {
4 -
5 - /**
6 - * Merge in the default video attributes supported by embedPlayer:
7 - */
8 - mw.mergeConfig( 'EmbedPlayer.Attributes', {
9 - // A apiTitleKey for looking up subtitles, credits and related videos
10 - "data-mwtitle" : null,
11 -
12 - // The apiProvider where to lookup the title key
13 - "data-mwprovider" : null
14 - });
15 -
16 - // Add mediaWiki player support to target embedPlayer
17 - $( mw ).bind( 'EmbedPlayerNewPlayer', function( event, embedPlayer ){
18 - mw.addMediaWikiPlayerSupport( embedPlayer );
19 - });
20 -
21 - /**
22 - * Closure function wraps mediaWiki embedPlayer bindings
23 - */
24 - mw.addMediaWikiPlayerSupport = function( embedPlayer ){
25 -
26 - // Set some local variables:
27 - if( ! $( embedPlayer).attr( 'data-mwtitle' ) ){
28 - return false;
29 - } else {
30 - var apiTitleKey = $( embedPlayer).attr( 'data-mwtitle');
31 - // legacy support ( set as attribute )
32 - embedPlayer.apiTitleKey = apiTitleKey;
33 - }
34 - // Set local apiProvider via config if not defined
35 - var apiProvider = $( embedPlayer ).attr('data-mwprovider');
36 - if( !apiProvider ){
37 - apiProvider = mw.getConfig( 'EmbedPlayer.ApiProvider' );
38 - }
39 -
40 - /**
41 - * Loads mediaWiki sources for a given embedPlayer
42 - * @param {function} callback Function called once player sources have been added
43 - */
44 - function loadPlayerSources( callback ){
45 - // Setup the request
46 - var request = {
47 - 'prop': 'imageinfo',
48 - // In case the user added File: or Image: to the apiKey:
49 - 'titles': 'File:' + unescape( apiTitleKey ).replace( /^(File:|Image:)/ , '' ),
50 - 'iiprop': 'url|size|dimensions|metadata',
51 - 'iiurlwidth': embedPlayer.getWidth(),
52 - 'redirects' : true // automatically resolve redirects
53 - };
54 -
55 - // Run the request:
56 - mw.getJSON( mw.getApiProviderURL( apiProvider ), request, function( data ){
57 - if ( data.query.pages ) {
58 - for ( var i in data.query.pages ) {
59 - if( i == '-1' ) {
60 - callback( false );
61 - return ;
62 - }
63 - var page = data.query.pages[i];
64 - }
65 - } else {
66 - callback( false );
67 - return ;
68 - }
69 - // Make sure we have imageinfo:
70 - if( ! page.imageinfo || !page.imageinfo[0] ){
71 - callback( false );
72 - return ;
73 - }
74 - var imageinfo = page.imageinfo[0];
75 -
76 - // TODO these should call public methods rather than update internals:
77 -
78 - // Update the poster
79 - embedPlayer.poster = imageinfo.thumburl;
80 -
81 - // Add the media src
82 - embedPlayer.mediaElement.tryAddSource(
83 - $('<source />')
84 - .attr( 'src', imageinfo.url )
85 - .get( 0 )
86 - );
87 -
88 - // Set the duration
89 - if( imageinfo.metadata[2]['name'] == 'length' ) {
90 - embedPlayer.duration = imageinfo.metadata[2]['value'];
91 - }
92 -
93 - // Set the width height
94 - // Make sure we have an accurate aspect ratio
95 - if( imageinfo.height != 0 && imageinfo.width != 0 ) {
96 - embedPlayer.height = parseInt( embedPlayer.width * ( imageinfo.height / imageinfo.width ) );
97 - }
98 -
99 - // Update the css for the player interface
100 - $( embedPlayer ).css( 'height', embedPlayer.height);
101 -
102 - callback();
103 - });
104 - }
105 -
106 -
107 - /**
108 - * Build a clip credit from the resource wikiText page
109 - *
110 - * TODO parse the resource page template
111 - *
112 - * @parm {String} resourceHTML Resource wiki text page contents
113 - */
114 - function doCreditLine( resourceHTML, articleUrl ){
115 - // Get the title string ( again a "Title" like js object could help out here. )
116 - var titleStr = embedPlayer.apiTitleKey.replace(/_/g, ' ');
117 -
118 - // Setup the initial credits line:
119 - var $creditLine = $( '<div />');
120 -
121 - // Add the title:
122 - $creditLine.append(
123 - $('<span>').html(
124 - gM( 'mwe-embedplayer-credit-title' ,
125 - // We use a div container to easily get at the built out link
126 - $('<div>').append(
127 - $('<a/>').attr({
128 - 'href' : articleUrl,
129 - 'title' : titleStr
130 - }).text( titleStr )
131 - ).html()
132 - )
133 - )
134 - );
135 -
136 - // Parse some data from the page info template if possible:
137 - var $page = $( resourceHTML );
138 -
139 - // Look for author:
140 - var $author = $page.find('#fileinfotpl_aut');
141 - if( $author.length ){
142 - // Get the real author sibling of fileinfotpl_aut
143 - $author = $author.next().find('p');
144 - // Remove white space:
145 - $author.find('br').remove();
146 -
147 - // Update link to be absolute per page url context:
148 - var authUrl = $author.find('a').attr('href');
149 - authUrl = mw.absoluteUrl( authUrl, articleUrl );
150 - $author.find('a').attr('href',
151 - authUrl
152 - )
153 - $creditLine.append( $( '<br />' ),
154 - gM('mwe-embedplayer-credit-author', $author.html() )
155 - )
156 - }
157 -
158 - // Look for date:
159 - var $date =$page.find('#fileinfotpl_date');
160 - if( $date.length ){
161 - // Get the real date sibling of fileinfotpl_date
162 - $date = $date.next().find('p');
163 -
164 - // remove white space:
165 - $date.find('br').remove();
166 - $creditLine.append( $( '<br />' ),
167 - gM('mwe-embedplayer-credit-date', $date.html() )
168 - )
169 - }
170 -
171 -
172 - // Build out the image and credit line
173 - var imgWidth = ( embedPlayer.controlBuilder.getOverlayWidth() < 250 )? 45 : 120;
174 - return $( '<div/>' ).addClass( 'creditline' )
175 - .append(
176 - $('<a/>').attr({
177 - 'href' : articleUrl,
178 - 'title' : titleStr
179 - }).html(
180 - $('<img/>').attr( {
181 - 'border': 0,
182 - 'src' : embedPlayer.poster
183 - } ).css( {
184 - 'width' : imgWidth,
185 - 'height': parseInt( imgWidth * ( embedPlayer.height / embedPlayer.width ) )
186 - } )
187 - )
188 - )
189 - .append(
190 - $creditLine
191 - );
192 - };
193 -
194 - /**
195 - * Issues a request to populate the credits box
196 - */
197 - var $creditsCache = false;
198 - function showCredits( $target, callback ){
199 - if( $creditsCache ){
200 - $target.html( $creditsCache );
201 - callback( true );
202 - return;
203 - }
204 - // Setup shortcuts:
205 - var apiUrl = mw.getApiProviderURL( apiProvider );
206 - var fileTitle = 'File:' + unescape( apiTitleKey).replace(/^File:|^Image:/, '');
207 -
208 - // Get the image page ( cache for 1 hour )
209 - var request = {
210 - 'action': 'parse',
211 - 'page': fileTitle,
212 - 'smaxage' : 3600,
213 - 'maxage' : 3600
214 - };
215 - var articleUrl = '';
216 - mw.getJSON( apiUrl, request, function( data ){
217 - descUrl = apiUrl.replace( 'api.php', 'index.php');
218 - descUrl+= '?title=' + fileTitle;
219 - if ( data && data.parse && data.parse.text && data.parse.text['*'] ) {
220 - // TODO improve provider 'concept' to support page title link
221 - $creditsCache = doCreditLine( data.parse.text['*'], descUrl );
222 - } else {
223 - $creditsCache = doCreditLine( false, descUrl)
224 - }
225 - $target.html( $creditsCache );
226 - callback( true );
227 - } );
228 - };
229 -
230 - /**
231 - * Adds embedPlayer Bindings
232 - */
233 - // Show credits when requested
234 - $( embedPlayer ).bind('ShowCredits', function( event, $target, callback){
235 - // Only request the credits once:
236 - showCredits( $target, callback);
237 - });
238 -
239 - $( embedPlayer ).bind('CheckPlayerSourcesEvent', function(event, callback){
240 - // Only load source if none are available:
241 - if( embedPlayer.mediaElement.sources.length == 0 ){
242 - loadPlayerSources( callback );
243 - } else {
244 - // No source to load, issue callback directly
245 - callback();
246 - }
247 - });
248 -
249 - $( embedPlayer ).bind('GetShareIframeSrc', function(event, callback){
250 - // Check the embedPlayer title key:
251 - var title = $( embedPlayer).attr( 'data-mwtitle');
252 - // TODO Check the provider key and use that hosts title page entry point!
253 - var provider = $( embedPlayer).attr( 'data-mwprovider');
254 -
255 - var iframeUrl = false;
256 - if( mw.getConfig('wgServer') && mw.getConfig('wgArticlePath') ){
257 - iframeUrl = mw.getConfig('wgServer') +
258 - mw.getConfig('wgArticlePath').replace( /\$1/, 'File:' +
259 - unescape( embedPlayer.apiTitleKey ).replace( /^(File:|Image:)/ , '' ) ) +
260 - '?' + 'embedplayer=yes';
261 - }
262 - callback( iframeUrl );
263 - });
264 - };
265 -
266 -} )( window.mediaWiki, window.jQuery );
\ No newline at end of file
Index: trunk/extensions/MwEmbedSupport/MwEmbedModules/MediaWikiSupport/resources/mw.MediaWikiPlayerSupport.js
@@ -0,0 +1,266 @@
 2+
 3+( function( mw, $ ) {
 4+
 5+ /**
 6+ * Merge in the default video attributes supported by embedPlayer:
 7+ */
 8+ mw.mergeConfig( 'EmbedPlayer.Attributes', {
 9+ // A apiTitleKey for looking up subtitles, credits and related videos
 10+ "data-mwtitle" : null,
 11+
 12+ // The apiProvider where to lookup the title key
 13+ "data-mwprovider" : null
 14+ });
 15+
 16+ // Add mediaWiki player support to target embedPlayer
 17+ $( mw ).bind( 'EmbedPlayerNewPlayer', function( event, embedPlayer ){
 18+ mw.addMediaWikiPlayerSupport( embedPlayer );
 19+ });
 20+
 21+ /**
 22+ * Closure function wraps mediaWiki embedPlayer bindings
 23+ */
 24+ mw.addMediaWikiPlayerSupport = function( embedPlayer ){
 25+
 26+ // Set some local variables:
 27+ if( ! $( embedPlayer).attr( 'data-mwtitle' ) ){
 28+ return false;
 29+ } else {
 30+ var apiTitleKey = $( embedPlayer).attr( 'data-mwtitle');
 31+ // legacy support ( set as attribute )
 32+ embedPlayer.apiTitleKey = apiTitleKey;
 33+ }
 34+ // Set local apiProvider via config if not defined
 35+ var apiProvider = $( embedPlayer ).attr('data-mwprovider');
 36+ if( !apiProvider ){
 37+ apiProvider = mw.getConfig( 'EmbedPlayer.ApiProvider' );
 38+ }
 39+
 40+ /**
 41+ * Loads mediaWiki sources for a given embedPlayer
 42+ * @param {function} callback Function called once player sources have been added
 43+ */
 44+ function loadPlayerSources( callback ){
 45+ // Setup the request
 46+ var request = {
 47+ 'prop': 'imageinfo',
 48+ // In case the user added File: or Image: to the apiKey:
 49+ 'titles': 'File:' + unescape( apiTitleKey ).replace( /^(File:|Image:)/ , '' ),
 50+ 'iiprop': 'url|size|dimensions|metadata',
 51+ 'iiurlwidth': embedPlayer.getWidth(),
 52+ 'redirects' : true // automatically resolve redirects
 53+ };
 54+
 55+ // Run the request:
 56+ mw.getJSON( mw.getApiProviderURL( apiProvider ), request, function( data ){
 57+ if ( data.query.pages ) {
 58+ for ( var i in data.query.pages ) {
 59+ if( i == '-1' ) {
 60+ callback( false );
 61+ return ;
 62+ }
 63+ var page = data.query.pages[i];
 64+ }
 65+ } else {
 66+ callback( false );
 67+ return ;
 68+ }
 69+ // Make sure we have imageinfo:
 70+ if( ! page.imageinfo || !page.imageinfo[0] ){
 71+ callback( false );
 72+ return ;
 73+ }
 74+ var imageinfo = page.imageinfo[0];
 75+
 76+ // TODO these should call public methods rather than update internals:
 77+
 78+ // Update the poster
 79+ embedPlayer.poster = imageinfo.thumburl;
 80+
 81+ // Add the media src
 82+ embedPlayer.mediaElement.tryAddSource(
 83+ $('<source />')
 84+ .attr( 'src', imageinfo.url )
 85+ .get( 0 )
 86+ );
 87+
 88+ // Set the duration
 89+ if( imageinfo.metadata[2]['name'] == 'length' ) {
 90+ embedPlayer.duration = imageinfo.metadata[2]['value'];
 91+ }
 92+
 93+ // Set the width height
 94+ // Make sure we have an accurate aspect ratio
 95+ if( imageinfo.height != 0 && imageinfo.width != 0 ) {
 96+ embedPlayer.height = parseInt( embedPlayer.width * ( imageinfo.height / imageinfo.width ) );
 97+ }
 98+
 99+ // Update the css for the player interface
 100+ $( embedPlayer ).css( 'height', embedPlayer.height);
 101+
 102+ callback();
 103+ });
 104+ }
 105+
 106+
 107+ /**
 108+ * Build a clip credit from the resource wikiText page
 109+ *
 110+ * TODO parse the resource page template
 111+ *
 112+ * @parm {String} resourceHTML Resource wiki text page contents
 113+ */
 114+ function doCreditLine( resourceHTML, articleUrl ){
 115+ // Get the title string ( again a "Title" like js object could help out here. )
 116+ var titleStr = embedPlayer.apiTitleKey.replace(/_/g, ' ');
 117+
 118+ // Setup the initial credits line:
 119+ var $creditLine = $( '<div />');
 120+
 121+ // Add the title:
 122+ $creditLine.append(
 123+ $('<span>').html(
 124+ gM( 'mwe-embedplayer-credit-title' ,
 125+ // We use a div container to easily get at the built out link
 126+ $('<div>').append(
 127+ $('<a/>').attr({
 128+ 'href' : articleUrl,
 129+ 'title' : titleStr
 130+ })
 131+ .text( titleStr )
 132+ ).html()
 133+ )
 134+ )
 135+ );
 136+
 137+ // Parse some data from the page info template if possible:
 138+ var $page = $( resourceHTML );
 139+
 140+ // Look for author:
 141+ var $author = $page.find('#fileinfotpl_aut');
 142+ if( $author.length ){
 143+ // Get the real author sibling of fileinfotpl_aut
 144+ $author = $author.next().find('p');
 145+ // Remove white space:
 146+ $author.find('br').remove();
 147+
 148+ // Update link to be absolute per page url context:
 149+ var authUrl = $author.find('a').attr('href');
 150+ authUrl = mw.absoluteUrl( authUrl, articleUrl );
 151+ $author.find('a').attr('href',
 152+ authUrl
 153+ )
 154+ $creditLine.append( $( '<br />' ),
 155+ gM('mwe-embedplayer-credit-author', $author.html() )
 156+ )
 157+ }
 158+
 159+ // Look for date:
 160+ var $date =$page.find('#fileinfotpl_date');
 161+ if( $date.length ){
 162+ // Get the real date sibling of fileinfotpl_date
 163+ $date = $date.next().find('p');
 164+
 165+ // remove white space:
 166+ $date.find('br').remove();
 167+ $creditLine.append( $( '<br />' ),
 168+ gM('mwe-embedplayer-credit-date', $date.html() )
 169+ )
 170+ }
 171+
 172+
 173+ // Build out the image and credit line
 174+ var imgWidth = ( embedPlayer.controlBuilder.getOverlayWidth() < 250 )? 45 : 120;
 175+ return $( '<div/>' ).addClass( 'creditline' )
 176+ .append(
 177+ $('<a/>').attr({
 178+ 'href' : articleUrl,
 179+ 'title' : titleStr
 180+ }).html(
 181+ $('<img/>').attr( {
 182+ 'border': 0,
 183+ 'src' : embedPlayer.poster
 184+ } ).css( {
 185+ 'width' : imgWidth,
 186+ 'height': parseInt( imgWidth * ( embedPlayer.height / embedPlayer.width ) )
 187+ } )
 188+ )
 189+ )
 190+ .append(
 191+ $creditLine
 192+ );
 193+ };
 194+
 195+ /**
 196+ * Issues a request to populate the credits box
 197+ */
 198+ var $creditsCache = false;
 199+ function showCredits( $target, callback ){
 200+ if( $creditsCache ){
 201+ $target.html( $creditsCache );
 202+ callback( true );
 203+ return;
 204+ }
 205+ // Setup shortcuts:
 206+ var apiUrl = mw.getApiProviderURL( apiProvider );
 207+ var fileTitle = 'File:' + unescape( apiTitleKey).replace(/^File:|^Image:/, '');
 208+
 209+ // Get the image page ( cache for 1 hour )
 210+ var request = {
 211+ 'action': 'parse',
 212+ 'page': fileTitle,
 213+ 'smaxage' : 3600,
 214+ 'maxage' : 3600
 215+ };
 216+ var articleUrl = '';
 217+ mw.getJSON( apiUrl, request, function( data ){
 218+ descUrl = apiUrl.replace( 'api.php', 'index.php');
 219+ descUrl+= '?title=' + fileTitle;
 220+ if ( data && data.parse && data.parse.text && data.parse.text['*'] ) {
 221+ // TODO improve provider 'concept' to support page title link
 222+ $creditsCache = doCreditLine( data.parse.text['*'], descUrl );
 223+ } else {
 224+ $creditsCache = doCreditLine( false, descUrl)
 225+ }
 226+ $target.html( $creditsCache );
 227+ callback( true );
 228+ } );
 229+ };
 230+
 231+ /**
 232+ * Adds embedPlayer Bindings
 233+ */
 234+ // Show credits when requested
 235+ $( embedPlayer ).bind('ShowCredits', function( event, $target, callback){
 236+ // Only request the credits once:
 237+ showCredits( $target, callback);
 238+ });
 239+
 240+ $( embedPlayer ).bind('CheckPlayerSourcesEvent', function(event, callback){
 241+ // Only load source if none are available:
 242+ if( embedPlayer.mediaElement.sources.length == 0 ){
 243+ loadPlayerSources( callback );
 244+ } else {
 245+ // No source to load, issue callback directly
 246+ callback();
 247+ }
 248+ });
 249+
 250+ $( embedPlayer ).bind('GetShareIframeSrc', function(event, callback){
 251+ // Check the embedPlayer title key:
 252+ var title = $( embedPlayer).attr( 'data-mwtitle');
 253+ // TODO Check the provider key and use that hosts title page entry point!
 254+ var provider = $( embedPlayer).attr( 'data-mwprovider');
 255+
 256+ var iframeUrl = false;
 257+ if( mw.getConfig('wgServer') && mw.getConfig('wgArticlePath') ){
 258+ iframeUrl = mw.getConfig('wgServer') +
 259+ mw.getConfig('wgArticlePath').replace( /\$1/, 'File:' +
 260+ unescape( embedPlayer.apiTitleKey ).replace( /^(File:|Image:)/ , '' ) ) +
 261+ '?' + 'embedplayer=yes';
 262+ }
 263+ callback( iframeUrl );
 264+ });
 265+ };
 266+
 267+} )( window.mediaWiki, window.jQuery );
\ No newline at end of file
Property changes on: trunk/extensions/MwEmbedSupport/MwEmbedModules/MediaWikiSupport/resources/mw.MediaWikiPlayerSupport.js
___________________________________________________________________
Added: svn:eol-style
1268 + native
Index: trunk/extensions/MwEmbedSupport/MwEmbedModules/MwEmbedSupport/mwEmbedSupport.js
@@ -263,7 +263,7 @@
264264 // Get the html representation of wikitext ( all that messages deal with right now )
265265 text = parsedText.getHTML();
266266
267 - // If the paramaters are jQuery objects or functions, we should now "swap" those objects in.
 267+ // If the parameters are jQuery objects or functions, we should now "swap" those objects in.
268268 if( doSpecialSwap ) {
269269 // Add bindings to swap index and return binded html jQuery objects
270270 for( var index=0; index < paramaters.length; index++ ) {

Status & tagging log