Bug 20489 Configure illegal file characters https://bugzilla.wikimedia.org/show_bug...
[mediawiki.git] / js2 / mwEmbed / libAddMedia / searchLibs / metavidSearch.js
bloba8c8d3986ea096aa5f1d04af724051ebbb3bdf58
1 /*
2 * API modes (implementations should call these objects which inherit the mvBaseRemoteSearch
3 */
4 loadGM({
5         "mwe-stream_title" : "$1 $2 to $3"
6 });
7 var metavidSearch = function(iObj) {
8         return this.init(iObj);
9 };
10 metavidSearch.prototype = {
11         reqObj:{  //set up the default request paramaters
12                 'order':'recent',
13                 'feed_format':'rss'
14         },
15         init:function( iObj ){
16                 //init base class and inherit:
17                 var baseSearch = new baseRemoteSearch( iObj );
18                 for(var i in baseSearch){
19                         if(typeof this[i] =='undefined'){
20                                 this[i] = baseSearch[i];
21                         }else{
22                                 this['parent_'+i] =  baseSearch[i];
23                         }
24                 }
25         },
26         getSearchResults:function(){
27                 //call parent:
28                 this.parent_getSearchResults();
30                 var _this = this;
31                 //start loading:
32                 _this.loading= 1;
33                 js_log('metavidSearch::getSearchResults()');
34                 //proccess all options
35                 var url = this.cp.api_url;
36                 //add on the req_param
37                 for(var i in this.reqObj){
38                         url += '&' + i + '=' + this.reqObj[i];
39                 }
40                 url += '&f[0][t]=match&f[0][v]=' + $j('#rsd_q').val();
41                 //add offset limit:
42                 url+='&limit=' + this.cp.limit;
43                 url+='&offset=' + this.cp.offset;
45                 do_request(url, function(data){
47                         js_log('mvSearch: got data response');
48                         //should have an xml rss data object:
49                         _this.addRSSData( data , url );
51                         //do some metavid specific pos processing on the rObj data:
52                         for(var i in _this.resultsObj){
53                                 var rObj = _this.resultsObj[i];
54                                 var proe = parseUri( rObj['roe_url'] );
55                                 rObj['start_time'] = proe.queryKey['t'].split('/')[0];
56                                 rObj['end_time'] = proe.queryKey['t'].split('/')[1];
57                                 rObj['stream_name'] = proe.queryKey['stream_name'];
59                                 //all metavid content is public domain:
60                                 rObj['license'] = _this.rsd.getLicenceFromKey( 'pd' );
62                                 //transform the title into a wiki_safe title:
63                                 //rObj['titleKey'] = proe.queryKey['stream_name'] + '_' + rObj['start_time'].replace(/:/g,'.') + '_' + rObj['end_time'].replace(/:/g,'.') + '.ogg';
64                                 rObj['titleKey'] =       _this.getTitleKey( rObj );
66                                 //default width of metavid clips:
67                                 rObj['target_width'] = 400;
68                         }
69                         //done loading:
70                         _this.loading=0;
71                 });
72         },
73         getTitleKey:function( rObj ){
74                 return rObj['stream_name'] + '_start-' + rObj['start_time'].replace(/:/g,'.') + '_end-' + rObj['end_time'].replace(/:/g,'.') + '.ogg';
75         },
76         getTitle:function( rObj ){
77                 var sn = rObj['stream_name'].replace(/_/g, ' ');
78                 sn = sn.charAt(0).toUpperCase() + sn.substr(1);
79                 return gM('mwe-stream_title', [ sn, rObj.start_time, rObj.end_time ]);
80         },
81         //metavid descption tied to public domain license key (government produced content)
82         getPermissionWikiTag:function( rObj ){
83                 return '{{PD-USGov}}';
84         },
85         getExtraResourceDescWiki:function( rObj ){
86                 var o = "\n";
87                 //check for person
88                 if(  rObj.person && rObj.person['label'])
89                         o += '* featuring [[' + rObj.person['label'] + ']]' + "\n";
91                 if( rObj.parent_clip )
92                         o += '* part of longer [' + rObj.parent_clip + ' video clip]'+ "\n";
94                 if( rObj.person && rObj.person['url'] && rObj.person['label'] )
95                         o += '* also see speeches by [' +  $j.trim( rObj.person.url ) + ' ' + rObj.person['label'] + ']'+ "\n";
97                 //check for bill:
98                 if( rObj.bill && rObj.bill['label'] && rObj.bill['url'])
99                         o += '* related to bill: [[' + rObj.bill['label'] + ']] more bill [' + rObj.bill['url'] + ' video clips]'+ "\n";
100                 return o;
101         },
102         //format is "quote" followed by [[name of person]]
103         getInlineDescWiki:function( rObj ){
104                 var o = this.parent_getInlineDescWiki( rObj );
105                 //add in person if found
106                 if( rObj.person &&  rObj.person['label'] ){
107                         o = $j.trim(  o.replace(rObj.person['label'], '') );
108                         //trim leading :
109                         if(o.substr(0,1)==':')
110                                 o =  o.substr(1);
111                         //add quotes and person at the end:
112                         var d = this.getDateFromLink( rObj.link );
113                         o ='"' + o + '" [[' + rObj.person['label'] + ']] on ' + d.toDateString();
114                 }
115                 //could do ref or direct link:
116                 o += ' \'\'[' + $j.trim( rObj.link ) + ' source clip]\'\' ';
118                 //var o= '"' + o + '" by [[' + rObj.person['label'] + ']] '+
119                 //              '<ref>[' + rObj.link + ' Metavid Source Page] for ' + rObj.title +'</ref>';
120                 return o;
121         },
122         //give an updated start and end time updates the title and url
123         applyVideoAdj: function( rObj ){
124                 js_log('mv ApplyVideoAdj::');
125                 //update the titleKey:
126                 rObj['titleKey'] =       this.getTitleKey( rObj );
128                 //update the title:
129                 rObj['title'] = this.getTitle( rObj );
131                 //update the interface:
132                 js_log('update title to: ' + rObj['title']);
133                 $j('#rsd_resource_title').html( gM('rsd_resource_edit', rObj['title'] ) );
135                 //if the video is "roe" based select the ogg stream
136                 if( rObj.roe_url && rObj.pSobj.cp.stream_import_key){
137                         var source = $j('#embed_vid').get(0).media_element.getSourceById( rObj.pSobj.cp.stream_import_key );
138                         if(!source){
139                                 js_error('Error::could not find source: ' +  rObj.pSobj.cp.stream_import_key);
140                         }else{
141                                 rObj['src'] = source.getURI();
142                                 js_log("g src_key: " + rObj.pSobj.cp.stream_import_key + ' src:' + rObj['src']) ;
143                                 return true;
144                         }
145                 }
146         },
147         getEmbedHTML:function( rObj , options ){
148             if(!options)
149                      options={};
150                 var id_attr = (options['id'])?' id = "' + options['id'] +'" ': '';
151                 var style_attr = (options['max_width'])?' style="width:'+options['max_width']+'px;"':'';
152                 //@@maybe check type here ?
153                 if(options['only_poster']){
154                         return '<img ' + id_attr + ' src="' + rObj['poster']+'" ' + style_attr + '>';
155                 }else{
156                         return '<video ' + id_attr + ' roe="' + rObj['roe_url'] + '"></video>';
157                 }
158         },
159         getImageTransform:function( rObj, opt ){
160                 if( opt.width <= 80 ){
161                         return getURLParamReplace( rObj.poster, { 'size' : "icon" } )
162                 }else if( opt.width <= 160 ){
163                         return getURLParamReplace( rObj.poster, { 'size' : "small" } )
164                 }else if( opt.width <= 320 ){
165                         return getURLParamReplace( rObj.poster, { 'size' : 'medium' } )
166                 }else if( opt.width <= 512 ){
167                         return getURLParamReplace( rObj.poster, { 'size' : 'large' } )
168                 }else{
169                         return getURLParamReplace( rObj.poster, { 'size' : 'full' } )
170                 }
171         },
172         getEmbedObjParsedInfo:function(rObj, eb_id){
173                 var sources = $j('#'+eb_id).get(0).media_element.getSources();
174                 rObj.other_versions ='*[' + rObj['roe_url'] + ' XML of all Video Formats and Timed Text]'+"\n";
175                 for(var i in sources){
176                         var cur_source = sources[i];
177                         //rObj.other_versions += '*['+cur_source.getURI() +' ' + cur_source.title +']' + "\n";
178                         if( cur_source.id ==  this.cp.target_source_id)
179                                 rObj['url'] = cur_source.getURI();
180                 }
181                 //js_log('set url to: ' + rObj['url']);
182                 return rObj;
183         },
184         //update rObj for import:
185         updateDataForImport:function( rObj ){
186                 rObj['author']='US Government';
187                 //convert data to UTC type date:
188                 var d = this.getDateFromLink( rObj.link );
189                 rObj['date'] =   d.toDateString();
190                 rObj['license_template_tag']='PD-USGov';
191                 //update based on new start time:
192                 js_log('url is: ' + rObj.src + ' ns: ' + rObj.start_time + ' ne:' + rObj.end_time);
194                 return rObj;
195         },
196         getDateFromLink:function( link ){
197                 var dateExp = new RegExp(/_([0-9]+)\-([0-9]+)\-([0-9]+)/);
198                 var dParts = link.match (dateExp);
199                 var d = new Date();
200                 var year_full = (dParts[3].length==2)?'20'+dParts[3].toString():dParts[3];
201                 d.setFullYear(year_full, dParts[1]-1, dParts[2]);
202                 return d;
203         }