r60696 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60695‎ | r60696 | r60697 >
Date:22:27, 5 January 2010
Author:dale
Status:deferred
Tags:
Comment:
* fixed archive.org with new search provider entry point, proper media layout & stooped using oggz-chop
* refactored domain check code to use mw.isLocalDomain() function
* depreciated DOMParser ( in favor of jquery xml string parsing )
* updated enabled_providers in stand alone add-media-wizard to stand-alone compatible list
* fixed kaltura item description page linkback
* some add-media-wizard layout tweeks
Modified paths:
  • /branches/js2-work/phase3/js/editPage.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/archiveOrgSearch.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/kalturaSearch.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.proxy.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/javaEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/Sequencer/mw.Sequencer.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mw.TimedText.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/tests/Add_Media_Wizard.html (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/tests/Add_Media_Wizard.html
@@ -23,26 +23,24 @@
2424 'import_url_mode' : 'remote_link',
2525 'remote_insert_description' : true,
2626 //note selections in the textbox will take over the default query
27 - 'default_query': 'fish',
 27+ 'default_query' : 'fish',
2828
2929 //we only enabled commons
3030 //(since javascript includes from other servers would be problamatic ) in a default install
3131 //** but you can set this to 'all' to pull from multiple repositories
32 - 'enabled_providers' : 'all',
 32+ 'enabled_providers' : [ 'wiki_commons', 'kaltura', 'archive_org', 'flickr', 'metavid' ],
3333
3434 //the local wiki api url:
3535 'local_wiki_api_url': 'none'
3636 } );
3737 } );
3838 });
39 -
4039 </script>
4140 </head>
4241 <body>
4342 <h3> Sample Add Media Wizard </h3>
4443
45 -<a id="add_media_link" href="#">Add Media</a><br>
46 -<b>note</b> only commons is enabled by default. For more options see source code.<br><br>
 44+<a id="add_media_link" href="#">Add Media</a><br><br>
4745 <table border="1" width="800">
4846 <tr>
4947 <td valign="top" width="50%" id="inline_append">Asset Output</td>
Index: branches/js2-work/phase3/js/mwEmbed/modules/TimedText/mw.TimedText.js
@@ -930,8 +930,8 @@
931931 // Try to load src via src attr:
932932 if( this.getSrc() ){
933933 // Issue the direct load request ( if we can )
934 - if ( mw.parseUri( document.URL ).host != mw.parseUri( this.getSrc() ).host ){
935 - mw.log("Error: host mis-match: " + mw.parseUri( document.URL ).host != mw.parseUri( this.getSrc() ).host )
 934+ if ( !mw.isLocalDomain( this.getSrc() ) ){
 935+ mw.log("Error: cant load crossDomain src:" + this.getSrc() )
936936 return ;
937937 }
938938 $j.get( this.getSrc(), function( data ){
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/kalturaSearch.js
@@ -1,5 +1,5 @@
22 /*
3 - * Kaltura agragated search:
 3+ * Kaltura aggregated search:
44 */
55
66 var kalturaSearch = function ( options ) {
@@ -71,6 +71,7 @@
7272 // Update mapings:
7373 result['poster'] = result['thumbnail'];
7474 result['pSobj'] = _this;
 75+ result['link'] = result[ 'item_details_page' ];
7576
7677 if( !result['titleKey'] && result['src'] ){
7778 result['titleKey'] = 'File:' + result['src'].split('/').pop();
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/archiveOrgSearch.js
@@ -10,11 +10,13 @@
1111 return this.init( iObj );
1212 }
1313 archiveOrgSearch.prototype = {
 14+
1415 // Archive.org constants:
1516 downloadUrl : 'http://www.archive.org/download/',
1617 detailsUrl : 'http://www.archive.org/details/',
17 - /*
18 - * Inititalize the archiveOrgSearch class.
 18+
 19+ /**
 20+ * Initialize the archiveOrgSearch class.
1921 * archiveOrgSearch inherits the baseSearch class
2022 */
2123 init:function( options ) {
@@ -35,26 +37,28 @@
3638 */
3739 getSearchResults: function( search_query ) {
3840
39 - // call parent for common initialisation:
 41+ // call parent for common initialization:
4042 this.parent_getSearchResults();
4143
4244 var _this = this;
43 - mw.log( 'archive_org:getSearchResults for:' + search_query );
 45+ mw.log( 'archive_org:getSearchResults for:' + search_query + ' from: ' + this.provider.api_url );
4446
4547
4648 // For now force (Ogg video) & url based license
4749 search_query += ' format:(Ogg video)';
4850 search_query += ' licenseurl:(http\\:\\/\\/*)';
49 -
 51+ // Set the page number:
 52+ var page_number = parseInt( this.provider.limit / this.provider.offset ) + 1;
5053 // Build the request Object
5154 var request = {
5255 'q': search_query, // just search for video atm
53 - 'fl':"description,title,identifier,licenseurl,format,license,thumbnail",
54 - 'wt':'json',
 56+ 'fl[]':"description,title,identifier,licenseurl,format,license,thumbnail",
 57+ 'fmt':'json',
5558 'rows' : this.provider.limit,
56 - 'start' : this.provider.offset
 59+ 'page' : page_number,
 60+ 'xmlsearch' : 'Search'
5761 }
58 - $j.getJSON( this.provider.api_url + '?json.wrf=?', request, function( data ) {
 62+ mw.getJSON( this.provider.api_url + '?json.wrf=?', request, function( data ) {
5963 _this.addResults( data );
6064 _this.loading = false;
6165 } );
@@ -97,43 +101,63 @@
98102 /**
99103 * Get media metadata via a archive.org special entry point "avinfo"
100104 *
101 - * @param {Object} resource Resrouce to add metadata to.
 105+ * @param {Object} resource Resource to add metadata to.
102106 * @param {Function} callbcak Function called once extra metadata is added.
103107 */
104 - addResourceInfoCallback:function( resource, callback ) {
 108+ addResourceInfoCallback: function( resource, callback ) {
105109 var _this = this;
106 - $j.getJSON(
107 - _this.downloadUrl + resource.resourceKey + '/format=Ogg+video&callback=?',
 110+ mw.log( 'addResourceInfoCallback' );
 111+ mw.getJSON(
 112+ _this.downloadUrl + resource.resourceKey + '/format=Ogg+video?callback=?',
108113 { 'avinfo' : 1 },
109 - function( data ) {
 114+ function( data ) {
110115 if ( data['length'] )
111116 resource.duration = data['length'];
112117 if ( data['width'] )
113118 resource.width = data['width'];
114119 if ( data['height'] )
115 - resource.height = data['height'];
116 -
 120+ resource.height = data['height'];
117121 callback();
118122 } );
119123 },
120124
121125 /**
122126 * Returns html to embed a given result Object ( resource )
123 - * @param {Object} resrouce Resource to get embed HTML from.
124 - * @parma {Object} options Options for the embeding.
 127+ * @param {Object} resource Resource to get embed HTML from.
 128+ * @parma {Object} options Options for the embedding.
125129 */
126130 getEmbedHTML: function( resource , options ) {
127131 mw.log( 'getEmbedHTML:: ' + resource.poster );
128132 if ( !options )
129133 options = { };
130 - var id_attr = ( options['id'] ) ? ' id = "' + options['id'] + '" ': '';
131 - if ( resource.duration ) {
132 - var src = resource.src + '?t=0:0:0/' + mw.seconds2npt( resource.duration );
133 - } else {
134 - var src = resource.src;
 134+
 135+ var attributes = ( options['id'] ) ? ' id = "' + options['id'] + '" ': '';
 136+
 137+ // Add height width if we have it:
 138+ if( resource.width ){
 139+ attributes += ' width="'+ parseInt( resource.width ) + '"';
135140 }
136 - if ( resource.mime == 'application/ogg' || resource.mime == 'audio/ogg' || resource.mime == 'video/ogg' ) {
137 - return '<video ' + id_attr + ' src="' + src + '" poster="' + resource.poster + '" type="video/ogg"></video>';
 141+ if( resource.height ){
 142+ attributes += ' height="' + parseInt( resource.height ) + '"';
138143 }
 144+ // Add the src
 145+ if( !resource.src ){
 146+ mw.log("Error: resource missing src");
 147+ }else{
 148+ attributes += ' src="' + resource.src + '"';
 149+ }
 150+ // For now no resource.duration ( oggzchop is not very stable )
 151+ //if ( resource.duration ) {
 152+ // var src = resource.src + '?t=0:0:0/' + mw.seconds2npt( resource.duration );
 153+ //} else {
 154+ //var src = resource.src;
 155+ //}
 156+ var o ='';
 157+ if ( resource.mime == 'application/ogg' || resource.mime == 'video/ogg' ) {
 158+ return '<video poster="' + resource.poster + '" ' + attributes +
 159+ ' type="video/ogg"></video>';
 160+ }else if( resource.mime == 'audio/ogg' ){
 161+ return '<audio ' + attributes + ' type="audio/ogg" ></audio>';
 162+ }
139163 }
140164 }
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js
@@ -186,10 +186,10 @@
187187 // Result cleared flag
188188 results_cleared: false,
189189
190 - // Caret position of target text area ( lazy initialised )
 190+ // Caret position of target text area ( lazy initialized )
191191 caretPos: null,
192192
193 - // Text area value ( lazy initialised )
 193+ // Text area value ( lazy initialized )
194194 textboxValue: null,
195195
196196 /** the default content providers list.
@@ -274,7 +274,7 @@
275275
276276 },
277277
278 - /*
 278+ /**
279279 * Kaltura aggregated search
280280 */
281281 'kaltura': {
@@ -294,7 +294,7 @@
295295 'checked': 1,
296296 'homepage': 'http://www.archive.org/about/about.php',
297297
298 - 'api_url': 'http://homeserver7.us.archive.org:8983/solr/select',
 298+ 'api_url': 'http://www.archive.org/advancedsearch.php',
299299 'lib': 'archiveOrg',
300300 'local': false,
301301 'resource_prefix': 'AO_',
@@ -471,9 +471,9 @@
472472 // Set the upload target name if unset
473473 if ( _this.upload_api_target == 'local'
474474 && ! _this.upload_api_name
475 - && typeof wgSiteName != 'undefined' )
 475+ && typeof wgServer != 'undefined' )
476476 {
477 - _this.upload_api_name = wgSiteName;
 477+ _this.upload_api_name = mw.parseUri( wgServer ).host;
478478 } else {
479479 // Disable upload tab if no target is avaliable
480480 this.content_providers[ 'upload' ].enabled = false;
@@ -2036,7 +2036,7 @@
20372037 gM( 'mwe-resource-needs-import', [resource.title, _this.upload_api_name] ) +
20382038 '</h3>' +
20392039 '<div id="rsd_preview_import_container" ' +
2040 - 'style="position:absolute;width:50%;bottom:0px;left:5px;' +
 2040+ 'style="position:absolute;width:49%;bottom:0px;left:5px;' +
20412041 'overflow:auto;top:30px;">' +
20422042
20432043 // Get embedHTML with small thumb:
Index: branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js
@@ -1786,7 +1786,7 @@
17871787 mw.log( 'f:getNextPrevLinks' );
17881788 var anno_track_url = null;
17891789 var _this = this;
1790 - // check for annoative track
 1790+ // Check for annotative track
17911791 $j.each( this.mediaElement.sources, function( inx, n ) {
17921792 if ( n.mime_type == 'text/cmml' ) {
17931793 if ( n.id == 'Anno_en' ) {
@@ -1830,16 +1830,11 @@
18311831 } else {
18321832 mw.getMvJsonUrl( new_anno_track_url, function( cmml_data ) {
18331833 mw.log( 'raw response: ' + cmml_data );
1834 - if ( typeof cmml_data == 'string' ) {
1835 - var parser = new DOMParser();
1836 - mw.log( 'Parse CMML data:' + cmml_data );
1837 - cmml_data = parser.parseFromString( cmml_data, "text/xml" );
1838 - }
18391834 // init cmmlData
18401835 if ( !_this.cmmlData )
18411836 _this.cmmlData = { };
1842 - // grab all metadata and put it into the cmmlData:
1843 - $j.each( cmml_data.getElementsByTagName( 'clip' ), function( inx, clip ) {
 1837+ // Grab all metadata and put it into the cmmlData:
 1838+ $j(cmml_data).find( 'clip' ).each( function( inx, clip ) {
18441839 _this.cmmlData[ $j( clip ).attr( "id" ) ] = {
18451840 'start_time_sec':mw.npt2seconds( $j( clip ).attr( "start" ).replace( 'npt:', '' ) ),
18461841 'end_time_sec':mw.npt2seconds( $j( clip ).attr( "end" ).replace( 'npt:', '' ) ),
Index: branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/javaEmbed.js
@@ -49,8 +49,8 @@
5050 // @@todo we should have src property in our base embed object
5151 var mediaSrc = this.getSrc();
5252
53 - if ( mediaSrc.indexOf( '://' ) != -1 & mw.parseUri( document.URL ).host != mw.parseUri( mediaSrc ).host ) {
54 - if ( window.cortadoDomainLocations[mw.parseUri( mediaSrc ).host] ) {
 53+ if ( mediaSrc.indexOf( '://' ) != -1 & !mw.isLocalDomain( mediaSrc ) ) {
 54+ if ( window.cortadoDomainLocations[ mw.parseUri( mediaSrc ).host ] ) {
5555 applet_loc = window.cortadoDomainLocations[mw.parseUri( mediaSrc ).host];
5656 } else {
5757 applet_loc = 'http://theora.org/cortado.jar';
Index: branches/js2-work/phase3/js/mwEmbed/modules/Sequencer/mw.Sequencer.js
@@ -885,7 +885,7 @@
886886 } );
887887
888888 // Upload clipboard to the server (if possible)
889 - if ( mw.parseUri( document.URL ).host != mw.parseUri( _this.plObj.interface_url ).host ) {
 889+ if ( ! mw.isLocalDomain( _this.plObj.interface_url )) {
890890 mw.log( 'error: presently we can\'t copy clips across domains' );
891891 } else {
892892 // FIXME we need to add an api entry point to store a "clipboard"
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.proxy.js
@@ -96,7 +96,7 @@
9797 $.proxy.client_frame_path = wgServer + wgScriptPath + '/js/mwEmbed/libMwApi/NestedCallbackIframe.html';
9898 }
9999
100 - if ( mw.parseUri( $.proxy.server_frame ).host == mw.parseUri( document.URL ).host ) {
 100+ if ( mw.isLocalDomain( $.proxy.server_frame ) ) {
101101 mw.log( "Error: trying to proxy local domain? " );
102102 return false;
103103 }
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -1271,20 +1271,21 @@
12721272 * API Helper functions
12731273 */
12741274
1275 - /*
1276 - * Get mediaWiki JSON a wrapper for jQuery getJSON:
 1275+ /**
 1276+ * mediaWiki JSON a wrapper for jQuery getJSON:
12771277 * $j.getJSON( url, [data], [callback] )
12781278 *
12791279 * The mediaWiki version lets you skip the url part
12801280 * mw.getJSON( [url], data, callback );
12811281 *
1282 - * Lets you assume a few options:
 1282+ * Lets you assume a few things:
12831283 * url is optional
12841284 * ( If the first argument is not a string we assume a local mediaWiki api request )
12851285 * callback parameter is not needed we setup the callback automatically
12861286 * url param 'action'=>'query' is assumed ( if not set to something else in the "data" param
12871287 * format is set to "json" automatically
12881288 * automatically issues request over "POST" if action={postActions}
 1289+ * ~soon~ will setup apiProxy where needed.
12891290 *
12901291 * @param {Mixed} url or data request
12911292 * @param {Mixed} data or callback
@@ -1327,22 +1328,25 @@
13281329
13291330 mw.log("run getJSON: " + url + ' data: ' + data['action'] );
13301331
 1332+ // Check if we need to setup proxy or do the request as a "post"
13311333 if( $j.inArray( data['action'], mw.getConfig( 'apiPostActions' ) ) != -1 ){
13321334 if( ! mw.isLocalDomain( url ) ){
1333 - mw.log( "Error:: should setup proxy here" );
 1335+ mw.log( "Error:: Do setup proxy here" );
 1336+ return ;
 1337+ }else{
 1338+ $j.post( url, data, callback, 'json');
 1339+ return ;
13341340 }
1335 - $j.post( url, data, callback, 'json');
1336 - }else{
1337 - //If cross domain setup a callback:
1338 - if( ! mw.isLocalDomain( url ) ){
1339 - if( url.indexOf( 'callback=' ) == -1 || data[ 'callback' ] == -1 ){
1340 - // jQuery specific: ( second ? is replaced with the callback )
1341 - url += ( url.indexOf('?') == -1 ) ? '?callback=?' : '&callback=?';
1342 - }
1343 - }
1344 - // Pass off the jQuery getJSON request:
1345 - $j.getJSON( url, data, callback );
1346 - }
 1341+ }
 1342+ //If cross domain setup a callback:
 1343+ if( ! mw.isLocalDomain( url ) ){
 1344+ if( url.indexOf( 'callback=' ) == -1 || data[ 'callback' ] == -1 ){
 1345+ // jQuery specific: ( second ? is replaced with the callback )
 1346+ url += ( url.indexOf('?') == -1 ) ? '?callback=?' : '&callback=?';
 1347+ }
 1348+ }
 1349+ // Pass off the jQuery getJSON request:
 1350+ $j.getJSON( url, data, callback );
13471351 }
13481352
13491353 /**
@@ -1366,9 +1370,13 @@
13671371 }
13681372
13691373 /**
1370 - * Checks if the url is a request for the local domain
 1374+ * Check if the url is a request for the local domain
13711375 * relative paths are "local" domain
13721376 * @param {String} url Url for local domain
 1377+ * @return
 1378+ * true if url domain is local or relative
 1379+ * false if the domain is
 1380+ * @type {Boolean}
13731381 */
13741382 mw.isLocalDomain = function( url ) {
13751383 if( mw.parseUri( document.URL ).host == mw.parseUri( url ).host ||
@@ -2270,8 +2278,8 @@
22712279 else if (document.styleSheets[0].rules)
22722280 rules = document.styleSheets[i].rules
22732281 for(var j=0 ; j < rules.length ; j++ ){
2274 - var rule = rules[j].selectorText;
2275 - if( rule.indexOf( styleRule ) != -1 ){
 2282+ var rule = rules[j].selectorText;
 2283+ if( rule && rule.indexOf( styleRule ) != -1 ){
22762284 return true;
22772285 }
22782286 }
@@ -2316,13 +2324,13 @@
23172325
23182326
23192327
2320 -// Load in js2 stopgap into proper location:
 2328+// Load in js2 stopgap global msgs into proper location:
23212329 if ( typeof gMsg != 'undefined' ) {
23222330 mw.addMessages( gMsg )
23232331 }
23242332
2325 -// Set gM shortcut:
2326 -var gM = mw.getMsg;
 2333+// Set global gM shortcut:
 2334+window['gM'] = mw.getMsg;
23272335
23282336 // Setup legacy global shortcuts:
23292337 var loadRS = mw.lang.loadRS;
@@ -2445,6 +2453,7 @@
24462454 }
24472455 })(domReadyCheck);
24482456 // As a backup check if "body" is not null ( for dynamic inserts )
 2457+// ( mw.domReady ignores multiple ready calls )
24492458 var mwCheckBody = function(){
24502459 if( document.getElementsByTagName('body')[0] ){
24512460 mw.domReady();
@@ -2574,29 +2583,3 @@
25752584 } )( jQuery );
25762585 }
25772586
2578 -/**
2579 -* Utility functions that override globals
2580 -*
2581 -* Will be depreciated once we move all XML parsing to jQuery calls
2582 -*/
2583 -
2584 -if ( typeof DOMParser == "undefined" ) {
2585 - DOMParser = function () { }
2586 - DOMParser.prototype.parseFromString = function ( str, contentType ) {
2587 - if ( typeof ActiveXObject != "undefined" ) {
2588 - var d = new ActiveXObject( "MSXML.DomDocument" );
2589 - d.loadXML( str );
2590 - return d;
2591 - } else if ( typeof XMLHttpRequest != "undefined" ) {
2592 - var req = new XMLHttpRequest;
2593 - req.open( "GET", "data:" + ( contentType || "application/xml" ) +
2594 - ";charset=utf-8," + encodeURIComponent( str ), false );
2595 - if ( req.overrideMimeType ) {
2596 - req.overrideMimeType( contentType );
2597 - }
2598 - req.send( null );
2599 - return req.responseXML;
2600 - }
2601 - }
2602 -}
2603 -
Index: branches/js2-work/phase3/js/editPage.js
@@ -15,7 +15,7 @@
1616 'default_query': wgTitle,
1717 'target_title': wgPageName,
1818 // Here we can setup the content provider overrides
19 - 'enabled_providers':['wiki_commons'],
 19+ 'enabled_providers': ['wiki_commons'],
2020 // The local wiki API URL:
2121 'local_wiki_api_url': wgServer + wgScriptPath + '/api.php'
2222 };

Status & tagging log