r59867 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59866‎ | r59867 | r59868 >
Date:01:09, 9 December 2009
Author:dale
Status:deferred
Tags:
Comment:
* minor comment updates and refactor
Modified paths:
  • /branches/js2-work/phase3/js2/mwEmbed/example_usage/Add_Media_Wizard.html (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libAddMedia/mvAdvFirefogg.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libAddMedia/searchLibs/archiveOrgSearch.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libAddMedia/searchLibs/flickrSearch.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libAddMedia/searchLibs/metavidSearch.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/libEmbedPlayer/embedPlayer.js (modified) (history)
  • /branches/js2-work/phase3/js2/mwEmbed/mwEmbed.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js2/mwEmbed/mwEmbed.js
@@ -1460,24 +1460,58 @@
14611461 * @return {String} absolute url
14621462 */
14631463 $.absoluteUrl = function( src, contextUrl ){
1464 - var pSrc = mw.parseUri( src );
1465 - if( pSrc.protocol != '')
 1464+ var parsedSrc = mw.parseUri( src );
 1465+ // Source is already absolute return:
 1466+ if( parsedSrc.protocol != '')
14661467 return src;
14671468
14681469 // Get parent Url location the context URL
14691470 if( contextUrl){
1470 - var pUrl = mw.parseUri( contextUrl );
 1471+ var parsedUrl = mw.parseUri( contextUrl );
14711472 } else {
1472 - var pUrl = mw.parseUri( document.URL );
 1473+ var parsedUrl = mw.parseUri( document.URL );
14731474 }
1474 - // If a leading slash:
 1475+
 1476+ // Check for leading slash:
14751477 if( src.indexOf( '/' ) == 1 ){
1476 - return pUrl.protocol + '://' + pUrl.authority + src;
 1478+ return parsedUrl.protocol + '://' + parsedUrl.authority + src;
14771479 }else{
1478 - return pUrl.protocol + '://' + pUrl.authority + pUrl.directory + src;
 1480+ return parsedUrl.protocol + '://' + parsedUrl.authority + parsedUrl.directory + src;
14791481 }
14801482 };
14811483
 1484+ /**
 1485+ * Replace url parammaters via newParams key value pairs
 1486+ *
 1487+ * @param {String} url Source url to be updated
 1488+ * @param {Object} newParams key, value paris to swap in
 1489+ * @return {String}
 1490+ * the updated url
 1491+ */
 1492+ $.replaceUrlParams = function( url, newParams ) {
 1493+ var parsedUrl = mw.parseUri( url );
 1494+
 1495+
 1496+ if ( parsedUrl.protocol != '' ) {
 1497+ var new_url = parsedUrl.protocol + '://' + parsedUrl.authority + parsedUrl.path + '?';
 1498+ } else {
 1499+ var new_url = parsedUrl.path + '?';
 1500+ }
 1501+
 1502+ // Merge new params:
 1503+ $j.merge( parsedUrl.queryKey, newParams );
 1504+
 1505+ // Output to new_url
 1506+ var amp = '';
 1507+ for ( var key in parsedUrl.queryKey ) {
 1508+ var val = parsedUrl.queryKey[ val ];
 1509+ new_url += amp + key + '=' + val;
 1510+ amp = '&';
 1511+ }
 1512+ return new_url;
 1513+ }
 1514+
 1515+
14821516 /**
14831517 * Takes in a string returns an xml dom object
14841518 *
@@ -2418,32 +2452,6 @@
24192453 /*
24202454 * Utility functions:
24212455 */
2422 -// Simple URL rewriter (could probably be refactored into an inline regular exp)
2423 -function getURLParamReplace( url, opt ) {
2424 - var pSrc = mw.parseUri( url );
2425 - if ( pSrc.protocol != '' ) {
2426 - var new_url = pSrc.protocol + '://' + pSrc.authority + pSrc.path + '?';
2427 - } else {
2428 - var new_url = pSrc.path + '?';
2429 - }
2430 - var amp = '';
2431 - for ( var key in pSrc.queryKey ) {
2432 - var val = pSrc.queryKey[ key ];
2433 - // Do override if requested
2434 - if ( opt[ key ] )
2435 - val = opt[ key ];
2436 - new_url += amp + key + '=' + val;
2437 - amp = '&';
2438 - };
2439 - // Add any vars that were not already there:
2440 - for ( var i in opt ) {
2441 - if ( !pSrc.queryKey[i] ) {
2442 - new_url += amp + i + '=' + opt[i];
2443 - amp = '&';
2444 - }
2445 - }
2446 - return new_url;
2447 -}
24482456
24492457 /**
24502458 * Given a float number of seconds, returns npt format response.
Index: branches/js2-work/phase3/js2/mwEmbed/example_usage/Add_Media_Wizard.html
@@ -28,7 +28,7 @@
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' : ['wiki_commons'],
 32+ 'enabled_providers' : ['all'],
3333
3434 //the local wiki api url:
3535 'local_wiki_api_url': 'none'
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js
@@ -1,22 +1,37 @@
2 -var mediaWikiSearch = function( iObj ) {
3 - return this.init( iObj );
 2+/**
 3+* mediaWiki search implementation
 4+*/
 5+var mediaWikiSearch = function( options ) {
 6+ return this.init( options );
47 };
58 mediaWikiSearch.prototype = {
6 - init:function( iObj ) {
 9+
 10+ /**
 11+ * Inherits the base search object and passes along options
 12+ * @constructor
 13+ */
 14+ init:function( options ) {
715 // init base class and inherit:
8 - var baseSearch = new baseRemoteSearch( iObj );
 16+ var baseSearch = new baseRemoteSearch( options );
917 for ( var i in baseSearch ) {
1018 if ( typeof this[i] == 'undefined' ) {
1119 this[i] = baseSearch[i];
1220 } else {
1321 this['parent_' + i] = baseSearch[i];
1422 }
15 - }
16 - // inherit the cp settings for
 23+ }
1724 },
18 - // returns a rObj by title
 25+
 26+ /**
 27+ * Adds a resource by its Title
 28+ *
 29+ * @param {String} title Title of the resource to be added
 30+ * @param {Function} callback Function called once title resource aquired
 31+ */
1932 addByTitle:function( title , callback, redirect_count ) {
 33+
2034 js_log( "AddByTitle::" + title );
 35+
2136 var _this = this;
2237 if ( !redirect_count )
2338 redirect_count = 0;
@@ -25,7 +40,7 @@
2641 callback( false );
2742 return false;
2843 }
29 - var reqObj = {
 44+ var request = {
3045 'action':'query',
3146 'titles':'File:' + title,
3247 'prop':'imageinfo|revisions|categories',
@@ -34,7 +49,7 @@
3550 'rvprop':'content'
3651 }
3752 do_api_req( {
38 - 'data':reqObj,
 53+ 'data':request,
3954 'url':this.provider.api_url
4055 }, function( data ) {
4156 // check for redirect
@@ -58,12 +73,14 @@
5974 }
6075 );
6176 },
62 - clearResults:function() {
63 - this.resultsObj = { };
64 - this.last_query = '';
65 - },
66 - // update the resultObj with recently uploaded items by current User:
67 - getUserRecentUploads:function( wgUser, callback ) {
 77+
 78+ /**
 79+ * Get recent upload by user and add them as results
 80+ *
 81+ * @param {String} user Name of the user
 82+ * @param {Function} callback Function to call once user upload list has been populated
 83+ */
 84+ getUserRecentUploads: function( user, callback ) {
6885 var _this = this;
6986 do_api_req( {
7087 'url':this.provider.api_url,
@@ -71,7 +88,7 @@
7289 'action':'query',
7390 'list':'recentchanges',
7491 'rcnamespace':6, // only files
75 - 'rcuser': wgUser,
 92+ 'rcuser': user,
7693 'rclimit':15 // get last 15 uploaded files
7794 }
7895 }, function( data ) {
@@ -89,7 +106,7 @@
90107 }
91108 }
92109 }
93 - // now run the actual query ( too bad we can't use recentchanges as a generator )
 110+ // Run the actual query ( too bad we can't use recentchanges as a generator )
94111 // bug 20563
95112 do_api_req( {
96113 'data' : {
@@ -100,7 +117,7 @@
101118 'iiurlwidth': parseInt( _this.rsd.thumb_width ),
102119 'rvprop':'content'
103120 },
104 - 'url':_this.provider.api_url
 121+ 'url': _this.provider.api_url
105122 }, function( data ) {
106123 _this.clearResults();
107124 _this.addResults( data );
@@ -109,22 +126,27 @@
110127 } );
111128 } );
112129 },
113 - getSearchResults:function() {
114 - // Call parent:
 130+
 131+ /**
 132+ * Get search results
 133+ *
 134+ * @param {String} search_query Text search string
 135+ */
 136+ getSearchResults: function( search_query ) {
 137+ // call parent for common initialisation:
115138 this.parent_getSearchResults();
116139 // Set local ref:
117140 var _this = this;
118141
119 - js_log( 'f:getSearchResults for:' + $j( '#rsd_q' ).val() );
120 - // Do two queries against the Image / File / MVD namespace:
 142+ js_log( 'f:getSearchResults for:' + search_query );
121143
122 - // Build the image request object:
123 - var reqObj = {
 144+ // Build the image request
 145+ var request = {
124146 'action':'query',
125147 'generator':'search',
126 - 'gsrsearch': $j( '#rsd_q' ).val(),
 148+ 'gsrsearch': search_query ,
127149 'gsrnamespace':6, // (only search the "file" namespace (audio, video, images)
128 - 'gsrwhat':'title',
 150+ 'gsrwhat': 'text',
129151 'gsrlimit': this.provider.limit,
130152 'gsroffset': this.provider.offset,
131153 'prop':'imageinfo|revisions|categories',
@@ -132,27 +154,33 @@
133155 'iiurlwidth': parseInt( this.rsd.thumb_width ),
134156 'rvprop':'content'
135157 };
136 - // Set up the number of request:
137 - this.completed_req = 0;
138 - this.num_req = 1;
139 - // Setup the number of requests result flag:
140 - // Also do a request for page titles (would be nice if api could query both at the same time)
141 - reqObj['gsrwhat'] = 'text';
 158+
 159+ // Do the api request:
142160 do_api_req( {
143 - 'data':reqObj,
144 - 'url':this.provider.api_url
145 - }, function( data ) {
146 - js_log( 'mediaWikiSearch: got data response' );
147 - // parse the return data
148 - _this.addResults( data );
149 - // _this.checkRequestDone(); //only need if we do two queries one for title one for text
 161+ 'data':request,
 162+ 'url': this.provider.api_url
 163+ }, function( data ) {
 164+ // Add result data:
 165+ _this.addResults( data );
150166 _this.loading = false;
151167 } );
152168 },
153 - // same as below but returns your rObj for convenience
154 - addSingleResult:function( data ) {
 169+
 170+ /**
 171+ * Adds a single result to resultsObj and returns the resource
 172+ *
 173+ * @param {Object} data Api resource result data to be transformed into a "resource"
 174+ */
 175+ addSingleResult: function( data ) {
155176 return this.addResults( data, true );
156177 },
 178+
 179+ /**
 180+ * Covert api data results into common search resources and insert into the resultsObj
 181+ *
 182+ * @param {Object} data Api resource result data to be transformed into a resources
 183+ * @param {Boolean} returnFirst Flag to return the first added resource
 184+ */
157185 addResults:function( data, returnFirst ) {
158186 js_log( "f:addResults" );
159187 var _this = this
@@ -178,10 +206,11 @@
179207 // skip page is redirect
180208 continue;
181209 }
 210+
182211 // Skip if its an empty or missing imageinfo:
183212 if ( !page.imageinfo )
184213 continue;
185 - var rObj = {
 214+ var resource = {
186215 'id' : page_id,
187216 'titleKey' : page.title,
188217 'link' : page.imageinfo[0].descriptionurl,
@@ -200,33 +229,34 @@
201230 'categories':page.categories
202231 }
203232 };
 233+
204234 /*
205235 //to use once we get the wiki-text parser in shape
206 - var pObj = mw.parser.pNew( rObj.desc );
 236+ var pObj = mw.parser.pNew( resource.desc );
207237 //structured data on commons is based on the "information" template:
208238 var tmplInfo = pObj.templates( 'information' );
209 - rObj.desc = tmplInfo.description
 239+ resource.desc = tmplInfo.description
210240 */
211241
212242 // Attempt to parse out the description current user desc from the commons template:
213243 // @@todo these could be combined to a single regEx
214244 // or better improve the wiki-text parsing and use above
215 - var desc = rObj.desc.match( /\|\s*description\s*=\s*(([^\n]*\n)*)\|\s*source=/i );
 245+ var desc = resource.desc.match( /\|\s*description\s*=\s*(([^\n]*\n)*)\|\s*source=/i );
216246 if ( desc && desc[1] ) {
217 - rObj.desc = $j.trim( desc[1] );
 247+ resource.desc = $j.trim( desc[1] );
218248 // attempt to get the user language if set:
219249 if ( typeof wgUserLanguage != 'undefined' && wgUserLanguage ) {
220250 // for some reason the RegExp object is not happy:
221251 var reg = new RegExp( '\{\{\s*' + wgUserLanguage + '([^=]*)=([^\}]*)\}\}', 'gim' );
222 - var langMatch = reg.exec( rObj.desc );
 252+ var langMatch = reg.exec( resource.desc );
223253 if ( langMatch && langMatch[2] ) {
224 - rObj.desc = langMatch[2];
 254+ resource.desc = langMatch[2];
225255 } else {
226 - // try simple lang template form:
 256+ // Try simple lang template form:
227257 var reg = new RegExp( '\{\{\s*' + wgUserLanguage + '\\|([^\}]*)\}\}', 'gim' );
228 - var langMatch = reg.exec( rObj.desc );
 258+ var langMatch = reg.exec( resource.desc );
229259 if ( langMatch && langMatch[1] ) {
230 - rObj.desc = langMatch[1];
 260+ resource.desc = langMatch[1];
231261 }
232262 }
233263 }
@@ -234,11 +264,11 @@
235265
236266 // Likely a audio clip if no poster and type application/ogg
237267 // @@todo we should return audio/ogg for the mime type or some other way to specify its "audio"
238 - if ( ! rObj.poster && rObj.mime == 'application/ogg' ) {
239 - rObj.mime = 'audio/ogg';
 268+ if ( ! resource.poster && resource.mime == 'application/ogg' ) {
 269+ resource.mime = 'audio/ogg';
240270 }
241271 // Add to the resultObj
242 - this.resultsObj[page_id] = rObj;
 272+ this.resultsObj[page_id] = resource;
243273
244274 // If returnFirst flag:
245275 if ( returnFirst )
@@ -254,7 +284,11 @@
255285 js_log( 'no results:' + data );
256286 }
257287 },
258 - // Check request done used for when we have multiple requests to check before formating results.
 288+
 289+ /*
 290+ * Check request done
 291+ * Used when we have multiple requests to check before formating results.
 292+ */
259293 checkRequestDone:function() {
260294 // Display output if done:
261295 this.completed_req++;
@@ -262,24 +296,32 @@
263297 this.loading = 0;
264298 }
265299 },
266 - getImageObj:function( rObj, size, callback ) {
267 - if ( rObj.mime == 'application/ogg' )
268 - return callback( { 'url':rObj.src, 'poster' : rObj.url } );
 300+
 301+ /**
 302+ * Get an Image object of requested size from a resource
 303+ *
 304+ * @param {Object} resource Source resource
 305+ * @param {Object} size Requested size: .width and .height
 306+ * @param {Function} callbcak Function to be called once image has been reqeusted
 307+ */
 308+ getImageObj:function( resource, size, callback ) {
 309+ if ( resource.mime == 'application/ogg' )
 310+ return callback( { 'url':resource.src, 'poster' : resource.url } );
269311
270312 // This could be depreciated if thumb.php support is standard
271 - var reqObj = {
 313+ var request = {
272314 'action':'query',
273315 'format':'json',
274 - 'titles':rObj.titleKey,
 316+ 'titles':resource.titleKey,
275317 'prop':'imageinfo',
276318 'iiprop':'url|size|mime'
277319 }
278320 // Set the width:
279321 if ( size.width )
280 - reqObj['iiurlwidth'] = size.width;
281 - js_log( 'going to do req: ' + this.provider.api_url + ' ' + reqObj );
 322+ request['iiurlwidth'] = size.width;
 323+ js_log( 'going to do req: ' + this.provider.api_url + ' ' + request );
282324 do_api_req( {
283 - 'data':reqObj,
 325+ 'data':request,
284326 'url' : this.provider.api_url
285327 }, function( data ) {
286328 var imObj = { };
@@ -303,13 +345,14 @@
304346 callback( imObj );
305347 } );
306348 },
307 - // the insert image function
308 - insertImage:function( cEdit ) {
309 - if ( !cEdit )
310 - var cEdit = _this.cEdit;
311 - },
312 - getInlineDescWiki:function( rObj ) {
313 - var desc = this.parent_getInlineDescWiki( rObj );
 349+
 350+ /*
 351+ * Gets an inline description of the resource
 352+ *
 353+ * @param {Object} resource Resource to get description of.
 354+ */
 355+ getInlineDescWiki:function( resource ) {
 356+ var desc = this.parent_getInlineDescWiki( resource );
314357
315358 // Strip categories for inline Desc: (should strip license tags too but not as easy)
316359 desc = desc.replace( /\[\[Category\:[^\]]*\]\]/gi, '' );
@@ -334,24 +377,29 @@
335378 js_log( 'Error: No Description Tag, Using::' + desc );
336379 return desc;
337380 },
338 - // Returns the inline wikitext for insertion (template based crops for now)
339 - getEmbedWikiCode: function( rObj ) {
 381+
 382+ /**
 383+ * Returns the wikitext for embeding the resource in a wiki article
 384+ *
 385+ * @param {Object} resource Resource to get wiki text embed code
 386+ */
 387+ getEmbedWikiCode: function( resource ) {
340388 // Set default layout to right justified
341 - var layout = ( rObj.layout ) ? rObj.layout:"right"
 389+ var layout = ( resource.layout ) ? resource.layout:"right"
342390 // if crop is null do base output:
343 - if ( rObj.crop == null )
344 - return this.parent_getEmbedWikiCode( rObj );
 391+ if ( resource.crop == null )
 392+ return this.parent_getEmbedWikiCode( resource );
345393 // Using the preview crop template: http://en.wikipedia.org/wiki/Template:Preview_Crop
346394 // @@todo should be replaced with server side cropping
347395 return '{{Preview Crop ' + "\n" +
348 - '|Image = ' + rObj.target_resource_title + "\n" +
349 - '|bSize = ' + rObj.width + "\n" +
350 - '|cWidth = ' + rObj.crop.w + "\n" +
351 - '|cHeight = ' + rObj.crop.h + "\n" +
352 - '|oTop = ' + rObj.crop.y + "\n" +
353 - '|oLeft = ' + rObj.crop.x + "\n" +
 396+ '|Image = ' + resource.target_resource_title + "\n" +
 397+ '|bSize = ' + resource.width + "\n" +
 398+ '|cWidth = ' + resource.crop.w + "\n" +
 399+ '|cHeight = ' + resource.crop.h + "\n" +
 400+ '|oTop = ' + resource.crop.y + "\n" +
 401+ '|oLeft = ' + resource.crop.x + "\n" +
354402 '|Location =' + layout + "\n" +
355 - '|Description =' + rObj.inlineDesc + "\n" +
 403+ '|Description =' + resource.inlineDesc + "\n" +
356404 '}}';
357405 }
358406 }
\ No newline at end of file
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js
@@ -1,4 +1,4 @@
2 -/*
 2+/**
33 * Base remote search Object.
44 * provides the base class for the other search system to extend.
55 */
@@ -66,23 +66,35 @@
6767 }
6868 return this;
6969 },
 70+
7071 /**
7172 * Base search results
72 - * Does some common initialisation for search results
 73+ * Does some common initialisation for search results
 74+ * @param {String} search_query Text search string
7375 */
74 - getSearchResults:function() {
 76+ getSearchResults: function( search_query ) {
7577 // Empty out the current results before issuing a request
7678 this.resultsObj = { };
7779
7880 // Do global getSearchResults bindings
79 - this.last_query = $j( '#rsd_q' ).val();
 81+ this.last_query = search_query;
8082 this.last_offset = this.provider.offset;
8183
8284 // Set the loading flag:
8385 this.loading = true;
8486 },
 87+
 88+ /**
 89+ * Clears Results
 90+ */
 91+ clearResults:function() {
 92+ this.resultsObj = { };
 93+ this.last_query = '';
 94+ },
 95+
8596 /*
8697 * Parses and adds video rss based input format
 98+ *
8799 * @param {XML Nodes} data the data to be parsed
88100 * @param {String} provider_url the source url (used to generate absolute links)
89101 */
@@ -258,7 +270,10 @@
259271 '</div>';
260272 },
261273 /**
262 - * Get the embed html specifically for an image type resource Object.
 274+ * Get the embed html specifically for an image type resource Object.
 275+ *
 276+ * @param {Object} resource Resource to get embed html from
 277+ * @param {Object} options Embeding options
263278 */
264279 getImageEmbedHTML:function( resource, options ) {
265280 // if crop is null do base output:
@@ -275,18 +290,24 @@
276291 '</div>' +
277292 '</div>';
278293 },
 294+
279295 /**
280296 * Get an image object from a requested transformation via callback
281297 * ( letting api search implementations query the remote server for a
282298 * given transformation )
283299 *
284300 * By default just return the existing image.
 301+ *
 302+ * @param {Object} resource Not used in base method
 303+ * @param {Object} size Not used in base method
 304+ * @param {Function} callbcak Function called with returned image Object
285305 */
286306 getImageObj:function( resource, size, callback ) {
287307 callback( {
288308 'url' : resource.poster
289309 } );
290310 },
 311+
291312 /**
292313 * Get the inline wikiText description of the resource Object
293314 */
@@ -357,7 +378,7 @@
358379 * @param {Object} resource Resource to add embeded info to
359380 * @param {String} embed_id Id of embed object
360381 */
361 - addResourceInfoFromEmbedInstance : function( resource, embed_id ) {
 382+ addEmbedInfo : function( resource, embed_id ) {
362383 return resource;
363384 },
364385
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/searchLibs/archiveOrgSearch.js
@@ -27,25 +27,28 @@
2828 }
2929 }
3030 },
 31+
3132 /**
32 - * Get search results from the api query
 33+ * Get search results from the api query.
 34+ *
 35+ * @param {String} search_query Text search string
3336 */
34 - getSearchResults:function() {
35 - // call parent:
 37+ getSearchResults: function( search_query ) {
 38+
 39+ // call parent for common initialisation:
3640 this.parent_getSearchResults();
 41+
3742 var _this = this;
38 - js_log( 'f:getSearchResults for:' + $j( '#rsd_q' ).val() );
 43+ js_log( 'f:getSearchResults for:' + search_query );
3944
40 - // Build the query var
41 - var q = $j( '#rsd_q' ).val();
4245
4346 // For now force (Ogg video) & url based license
44 - q += ' format:(Ogg video)';
45 - q += ' licenseurl:(http\\:\\/\\/*)';
 47+ search_query += ' format:(Ogg video)';
 48+ search_query += ' licenseurl:(http\\:\\/\\/*)';
4649
4750 // Build the request Object
4851 var reqObj = {
49 - 'q': q, // just search for video atm
 52+ 'q': search_query, // just search for video atm
5053 'fl':"description,title,identifier,licenseurl,format,license,thumbnail",
5154 'wt':'json',
5255 'rows' : this.provider.limit,
@@ -63,6 +66,8 @@
6467 },
6568 /**
6669 * Adds the search results to the local resultsObj
 70+ *
 71+ * @param {Object} data Api result data
6772 */
6873 addResults:function( data ) {
6974 var _this = this;
@@ -96,6 +101,9 @@
97102 },
98103 /**
99104 * Get media metadata via a archive.org special entry point "avinfo"
 105+ *
 106+ * @param {Object} resource Resrouce to add metadata to.
 107+ * @param {Function} callbcak Function called once extra metadata is added.
100108 */
101109 addResourceInfoCallback:function( resource, callback ) {
102110 var _this = this;
@@ -116,6 +124,8 @@
117125
118126 /**
119127 * Returns html to embed a given result Object ( resource )
 128+ * @param {Object} resrouce Resource to get embed HTML from.
 129+ * @parma {Object} options Options for the embeding.
120130 */
121131 getEmbedHTML: function( resource , options ) {
122132 js_log( 'getEmbedHTML:: ' + resource.poster );
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/searchLibs/metavidSearch.js
@@ -8,12 +8,12 @@
99 return this.init( iObj );
1010 };
1111 metavidSearch.prototype = {
12 - defaultReq: { // set up the default request paramaters
13 - 'order':'recent',
14 - 'feed_format':'json_rss',
15 - 'cb_inx': 1 // Not really used (we should update the metavid json retrun system)
 12+ // Default request parameters
 13+ defaultReq: {
 14+ 'order': 'recent',
 15+ 'feed_format': 'json_rss'
1616 },
17 - init:function( iObj ) {
 17+ init: function( iObj ) {
1818 // init base class and inherit:
1919 var baseSearch = new baseRemoteSearch( iObj );
2020 for ( var i in baseSearch ) {
@@ -24,17 +24,27 @@
2525 }
2626 }
2727 },
28 - getSearchResults:function() {
29 - // call parent:
 28+
 29+ /**
 30+ * getSearchResults
 31+ *
 32+ * @param {String} search_query Text search string
 33+ */
 34+ getSearchResults: function( search_query ) {
 35+
 36+ // Call parent for common initialisation:
3037 this.parent_getSearchResults();
31 - // set local ref:
 38+
 39+ // Set local ref:
3240 var _this = this;
 41+
3342 js_log( 'metavidSearch::getSearchResults()' );
34 - // Proccess all options
 43+
 44+ // Process all options
3545 var url = this.provider.api_url;
3646 var reqObj = $j.extend({}, this.defaultReq);
3747 reqObj[ 'f[0][t]' ] = 'match';
38 - reqObj[ 'f[0][v]' ] = $j( '#rsd_q' ).val();
 48+ reqObj[ 'f[0][v]' ] = search_query;
3949
4050 // add offset limit:
4151 reqObj[ 'limit' ] = this.provider.limit;
@@ -87,17 +97,32 @@
8898 _this.loading = 0;
8999 } );
90100 },
 101+
91102 /**
92 - * Get a Title key for the assset name inside the mediaWiki system
 103+ * Get a Title key for the asset name inside the mediaWiki system
 104+ *
 105+ * @param {Object} resource Resource to get title key from
93106 */
94107 getTitleKey:function( resource ) {
95108 return resource['stream_name'] + '_part_' + resource['start_time'].replace(/:/g, '.' ) + '_to_' + resource['end_time'].replace(/:/g, '.' ) + '.ogv';
96109 },
 110+
 111+ /**
 112+ * Get a Title from a resource
 113+ *
 114+ * @parma {Object} resoruce Resource to get title from
 115+ */
97116 getTitle:function( resource ) {
98117 var sn = resource['stream_name'].replace( /_/g, ' ' );
99118 sn = sn.charAt( 0 ).toUpperCase() + sn.substr( 1 );
100119 return gM( 'mwe-stream_title', [ sn, resource.start_time, resource.end_time ] );
101120 },
 121+
 122+ /**
 123+ * Get additional wiki text description
 124+ *
 125+ * @param {Object} resource Resource to get addtional wikitext for.
 126+ */
102127 getExtraResourceDescWiki:function( resource ) {
103128 var o = "\n";
104129 // check for person
@@ -115,7 +140,12 @@
116141 o += '* related to bill: [[' + resource.bill['label'] + ']] more bill [' + resource.bill['url'] + ' video clips]' + "\n";
117142 return o;
118143 },
119 - // format is "quote" followed by [[name of person]]
 144+
 145+ /**
 146+ * Get inline description
 147+ * format is "quote" followed by [[name of person]]
 148+ * @param {Object} resource Resource to get inline description of.
 149+ */
120150 getInlineDescWiki:function( resource ) {
121151 var o = this.parent_getInlineDescWiki( resource );
122152 // add in person if found
@@ -135,13 +165,19 @@
136166 // '<ref>[' + resource.link + ' Metavid Source Page] for ' + resource.title +'</ref>';
137167 return o;
138168 },
139 - // give an updated start and end time updates the title and url
 169+
 170+ /**
 171+ * Apply an updated start and end time to the resource ( for use with the #embed_vid clip )
 172+ *
 173+ * @param {Object} resource Resource to be updated
 174+ */
140175 applyVideoAdj: function( resource ) {
141176 js_log( 'mv ApplyVideoAdj::' );
142 - // update the titleKey:
 177+
 178+ // Update the titleKey:
143179 resource['titleKey'] = this.getTitleKey( resource );
144180
145 - // update the title:
 181+ // Update the title:
146182 resource['title'] = this.getTitle( resource );
147183
148184 // update the interface:
@@ -160,18 +196,30 @@
161197 }
162198 }
163199 },
 200+
 201+ /**
 202+ * Get html to embed the resource into a page:
 203+ *
 204+ * @param {Object} resource Resource to be embed
 205+ * @param {Object} options Resource Optiosn for embeind ( like max_width )
 206+ */
164207 getEmbedHTML:function( resource , options ) {
165208 if ( !options )
166209 options = { };
167210 var id_attr = ( options['id'] ) ? ' id = "' + options['id'] + '" ': '';
168 - var style_attr = ( options['max_width'] ) ? ' style="width:' + options['max_width'] + 'px;"':'';
169 - // @@maybe check type here ?
 211+ var style_attr = ( options['max_width'] ) ? ' style="width:' + options['max_width'] + 'px;"':'';
170212 if ( options['only_poster'] ) {
171213 return '<img ' + id_attr + ' src="' + resource['poster'] + '" ' + style_attr + '>';
172214 } else {
173215 return '<video ' + id_attr + ' roe="' + resource['roe_url'] + '"></video>';
174216 }
175217 },
 218+
 219+ /**
 220+ * Get Image Transform
 221+ *
 222+ * @param {Object} resource Resource to transform
 223+ */
176224 getImageTransform:function( resource, opt ) {
177225 if ( opt.width <= 80 ) {
178226 return getURLParamReplace( resource.poster, { 'size' : "icon" } )
@@ -185,7 +233,13 @@
186234 return getURLParamReplace( resource.poster, { 'size' : 'full' } )
187235 }
188236 },
189 - addResourceInfoFromEmbedInstance : function( resource, embed_id ) {
 237+
 238+ /**
 239+ * Add information from the embed instance to the resource
 240+ *
 241+ * @param {Object} resource Resource to transform
 242+ */
 243+ addEmbedInfo : function( resource, embed_id ) {
190244 var sources = $j( '#' + embed_id ).get( 0 ).media_element.getSources();
191245 resource.other_versions = '*[' + resource['roe_url'] + ' XML of all Video Formats and Timed Text]' + "\n";
192246 for ( var i in sources ) {
@@ -197,6 +251,13 @@
198252 // js_log('set url to: ' + resource['url']);
199253 return resource;
200254 },
 255+
 256+ /**
 257+ * Get a date from a media link
 258+ *
 259+ * @param {String} link Link url to be parsed
 260+ * @return {Date Object}
 261+ */
201262 getDateFromLink:function( link ) {
202263 var dateExp = new RegExp( /_([0-9]+)\-([0-9]+)\-([0-9]+)/ );
203264 var dParts = link.match ( dateExp );
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/searchLibs/flickrSearch.js
@@ -49,12 +49,15 @@
5050 * Get the Search results setting _loading flag to false once results have been added
5151 *
5252 * Runs an api call then calls addResults with the resulting data
 53+ * @param {String} search_query Text search string
5354 */
54 - getSearchResults:function() {
 55+ getSearchResults:function( search_query ) {
5556 var _this = this;
5657 js_log( "flickr::getSearchResults" );
57 - // call parent (sets loading sate and other setup stuff)
 58+
 59+ // call parent for common initialisation:
5860 this.parent_getSearchResults();
 61+
5962 // setup the flickr request:
6063 var reqObj = {
6164 'method':'flickr.photos.search',
@@ -63,12 +66,12 @@
6467 'api_key':this.apikey,
6568 'per_page': this.provider.limit,
6669 'page' : this.provider.offset,
67 - 'text': $j( '#rsd_q' ).val(),
 70+ 'text': search_query,
6871 'extras' : 'license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_m, url_o'
6972 }
7073 do_api_req( {
7174 'data': reqObj,
72 - 'url':this.provider.api_url,
 75+ 'url': this.provider.api_url,
7376 'jsonCB':'jsoncallback',
7477 }, function( data ) {
7578 _this.addResults( data );
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/mvAdvFirefogg.js
@@ -951,7 +951,7 @@
952952 /**
953953 * Restore settings from a cookie (if available)
954954 */
955 - loadEncSettings: function( force ) {
 955+ loadEncSettings: function( ) {
956956 if ( $j.cookie( 'fogg_encoder_config' ) ) {
957957 js_log( "load:fogg_encoder_config from cookie " );
958958 this.local_settings = JSON.parse( $j.cookie( 'fogg_settings' ) );
Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js
@@ -384,7 +384,7 @@
385385 // Merge in the options
386386 $j.extend( _this, default_remote_search_options, options );
387387
388 - // Quick fix for cases where people put ['all'] instead of 'all' for enabled_providers
 388+ // Quick fix for cases where {object} ['all'] is used instead of {string} 'all' for enabled_providers:
389389 if ( _this.enabled_providers.length == 1 && _this.enabled_providers[0] == 'all' )
390390 _this.enabled_providers = 'all';
391391
@@ -836,7 +836,8 @@
837837 },
838838
839839 /**
840 - * Once the uploadForm is ready display it for the upload provider
 840+ * Once the uploadForm is ready display it for the upload provider
 841+ *
841842 * @param {Object} provider Provider object for Upload From
842843 */
843844 showUploadForm_internal: function( provider ) {
@@ -867,7 +868,7 @@
868869 // Fill in the user uploads:
869870 if ( typeof wgUserName != 'undefined' && wgUserName ) {
870871 // Load the upload bin with anything the current user has uploaded
871 - provider.sObj.getUserRecentUploads( wgUserName, function() {
 872+ provider.sObj.getUserRecentUploads( wgUserName, function( ) {
872873 _this.showResults();
873874 } );
874875 } else {
@@ -908,6 +909,7 @@
909910
910911 /**
911912 * Show the search tab for a given providerName
 913+ *
912914 * @param {String} providerName name of the content provider
913915 * @param {Bollean} resetPaging if the pagging should be reset
914916 */
@@ -917,7 +919,7 @@
918920 var draw_direct_flag = true;
919921
920922 // Else do showSearchTab
921 - var provider = this.content_providers[providerName];
 923+ var provider = this.content_providers[ providerName ];
922924
923925 // Check if we need to update:
924926 if ( typeof provider.sObj != 'undefined' ) {
@@ -934,6 +936,7 @@
935937 } else {
936938 draw_direct_flag = false;
937939 }
 940+
938941 if ( !draw_direct_flag ) {
939942 // See if we should reset the paging
940943 if ( resetPaging ) {
@@ -983,6 +986,13 @@
984987 );
985988 }
986989 },
 990+
 991+ /**
 992+ * Evaluate the result of an api copyURL permision request
 993+ *
 994+ * @param {Object} data Result data to be checked
 995+ * @param {Function} callback Function to call once api returns value
 996+ */
987997 checkCopyURLApiResult: function( data, callback ) {
988998 var _this = this;
989999 // Api checks:
@@ -1013,6 +1023,10 @@
10141024 * not really necessary the api request to upload will return appropriate error
10151025 * if the user lacks permission. or $wgAllowCopyUploads is set to false
10161026 * (use this function if we want to issue a warning up front)
 1027+ *
 1028+ * @param {Function} callback Function to call with URL permision
 1029+ * @return
 1030+ * false callback user does not have permision
10171031 */
10181032 checkForCopyURLPermission: function( callback ) {
10191033 var _this = this;
@@ -1065,10 +1079,10 @@
10661080 '</div>' );
10671081 }
10681082 return false;
1069 - }
1070 - _this.loadSearchLib( provider, function() {
1071 - // Do the search
1072 - provider.sObj.getSearchResults();
 1083+ }
 1084+ _this.loadSearchLib( provider, function( provider ) {
 1085+ // Do the search:
 1086+ provider.sObj.getSearchResults( $j( '#rsd_q' ).val() );
10731087 _this.waitForResults( function() {
10741088 _this.showResults();
10751089 } );
@@ -1079,7 +1093,8 @@
10801094 * Loads a providers search library
10811095 *
10821096 * @param {Object} provider content provider to be loaded
1083 - * @param {Function} callback function to be called once provider is loaded
 1097+ * @param {Function} callback Function to call once provider is loaded
 1098+ * ( provider is passed back in callback to avoid possible concurancy issues in multiple load calls)
10841099 */
10851100 loadSearchLib: function( provider, callback ) {
10861101 var _this = this;
@@ -1103,7 +1118,7 @@
11041119 // inherit defaults if not set:
11051120 provider.limit = provider.limit ? provider.limit : provider.sObj.limit;
11061121 provider.offset = provider.offset ? provider.offset : provider.sObj.offset;
1107 - callback();
 1122+ callback( provider );
11081123 } );
11091124 },
11101125
@@ -1720,7 +1735,7 @@
17211736 $j( '#embed_vid').embedPlayer ( function() {
17221737
17231738 // Grab information available from the embed instance
1724 - resource.pSobj.addResourceInfoFromEmbedInstance( resource, 'embed_vid' );
 1739+ resource.pSobj.addEmbedInfo( resource, 'embed_vid' );
17251740
17261741 // Add libraries resizable and hoverIntent to support video edit tools
17271742 var librarySet = [
Index: branches/js2-work/phase3/js2/mwEmbed/libEmbedPlayer/embedPlayer.js
@@ -566,7 +566,7 @@
567567 if ( !npt2seconds( end_npt ) )
568568 end_npt = this.end_npt;
569569
570 - this.src = getURLParamReplace( this.src, {
 570+ this.src = mw.replaceUrlParams( this.src, {
571571 't': start_npt + '/' + end_npt
572572 });
573573
@@ -607,7 +607,7 @@
608608 } else {
609609 var endvar = '/' + this.end_npt;
610610 }
611 - return getURLParamReplace( this.src,
 611+ return mw.replaceUrlParams( this.src,
612612 {
613613 't': seconds2npt( seek_time_sec ) + endvar
614614 }
@@ -1967,7 +1967,7 @@
19681968 // check if our thumbnail has a time attribute:
19691969 if ( my_thumb_src.indexOf( 't=' ) !== -1 ) {
19701970 var time_ntp = seconds2npt ( options.time + parseInt( this.start_offset ) );
1971 - my_thumb_src = getURLParamReplace( my_thumb_src, {
 1971+ my_thumb_src = mw.replaceUrlParams( my_thumb_src, {
19721972 't' : time_ntp,
19731973 'size' : options.size
19741974 });
@@ -1991,7 +1991,7 @@
19921992 this.org_thum_src = this.media_element.getThumbnailURL();
19931993 }
19941994 if ( this.org_thum_src.indexOf( 't=' ) !== -1 ) {
1995 - this.last_thumb_url = getURLParamReplace( this.org_thum_src,
 1995+ this.last_thumb_url = mw.replaceUrlParams( this.org_thum_src,
19961996 {
19971997 't' : seconds2npt( float_sec + parseInt( this.start_offset ) )
19981998 }

Status & tagging log