2 * a library for doing remote media searches
4 * initial targeted archives are:
12 "mwe-add_media_wizard" : "Add media wizard",
13 "mwe-media_search" : "Media search",
14 "rsd_box_layout" : "Box layout",
15 "rsd_list_layout" : "List layout",
16 "rsd_results_desc" : "Results",
17 "rsd_results_next" : "next",
18 "rsd_results_prev" : "previous",
19 "rsd_no_results" : "No search results for <b>$1<\/b>",
20 "mwe-upload_tab" : "Upload",
21 "rsd_layout" : "Layout:",
22 "rsd_resource_edit" : "Edit resource: $1",
23 "mwe-resource_description_page" : "Resource description page",
25 "rsd_local_resource_title" : "Local resource title",
26 "rsd_do_insert" : "Do insert",
27 "mwe-cc_title" : "Creative Commons",
28 "mwe-cc_by_title" : "Attribution",
29 "mwe-cc_nc_title" : "Noncommercial",
30 "mwe-cc_nd_title" : "No Derivative Works",
31 "mwe-cc_sa_title" : "Share Alike",
32 "mwe-cc_pd_title" : "Public Domain",
33 "mwe-unknown_license" : "Unknown license",
34 "mwe-no_import_by_url" : "This user or wiki <b>can not<\/b> import assets from remote URLs.<p>Do you need to login?<\/p><p>Is upload_by_url permission set for you?<\/br> Do you need may have to enable <a href=\"http:\/\/www.mediawiki.org\/wiki\/Manual:$wgAllowCopyUploads\">$wgAllowCopyUploads<\/a>.<\/p>",
35 "mwe-results_from" : "Results from <a href=\"$1\" target=\"_new\" >$2<\/a>",
36 "mwe-missing_desc_see_source" : "This asset is missing a description. Please see the [$1 orginal source] and help describe it.",
37 "rsd_config_error" : "Add media wizard configuration error: $1",
38 "mwe-your_recent_uploads" : "Your recent uploads to $1",
39 "mwe-upload_a_file" : "Upload a new file to $1",
40 "mwe-resource_page_desc" : "Resource page description:",
41 "mwe-edit_resource_desc" : "Edit wiki text resource description:",
42 "mwe-local_resource_title" : "Local resource title:",
43 "mwe-watch_this_page" : "Watch this page",
44 "mwe-do_import_resource" : "Import resource",
45 "mwe-update_preview" : "Update preview",
46 "mwe-cancel_import" : "Cancel import",
47 "mwe-importing_asset" : "Importing asset",
48 "mwe-preview_insert_resource" : "Preview insert of resource: $1",
49 "mwe-checking-resource": "Checking for resource",
50 "mwe-resource-needs-import": "Resource $1 needs to be imported to $2",
51 "mwe-ftype-svg" : "SVG vector file",
52 "mwe-ftype-jpg" : "JPEG image file",
53 "mwe-ftype-png" : "PNG image file",
54 "mwe-ftype-oga" : "Ogg audio file",
55 "mwe-ftype-ogg" : "Ogg video file",
56 "mwe-ftype-unk" : "Unknown File Format"
59 var default_remote_search_options
= {
60 'profile':'mediawiki_edit',
61 'target_container':null, //the div that will hold the search interface
63 'target_invocation': null, //the button or link that will invoke the search interface
65 'default_provider_id':'all', //all or one of the content_providers ids
68 'local_wiki_api_url':null,
70 //can be 'api', 'autodetect', 'remote_link'
71 'import_url_mode': 'autodetect',
75 'target_textbox':null,
76 'target_render_area': null, //where output render should go:
77 'instance_name': null, //a globally accessible callback instance name
78 'default_query':null, //default search query
79 //specific to sequence profile
81 'cFileNS':'File', //What is the canonical namespace prefix for images
82 //@@todo (should get that from the api or in-page vars)
84 'upload_api_target': 'local', // can be local or the url or remote
85 'upload_api_name' : null,
86 'upload_api_proxy_frame': null, //a page that will request mw.proxy.server
88 'enabled_cps':'all', //can be keyword 'all' or an array of enabled content provider keys
90 'disp_item':'wiki_commons' //sets the default display item:
93 if(typeof wgServer
== 'undefined')
95 if(typeof wgScriptPath
== 'undefined')
97 if(typeof stylepath
== 'undefined')
101 * base remoteSearch Driver interface
103 var remoteSearchDriver = function(iObj
){
104 return this.init( iObj
);
106 remoteSearchDriver
.prototype = {
107 results_cleared
:false,
108 //here we define the set of possible media content providers:
109 main_search_options
:{
111 'title': 'Select Providers'
114 'title': 'Advanced Options'
117 /** the default content providers list.
119 * (should be note that special tabs like "upload" and "combined" don't go into the content providers list:
120 * @note do not use double underscore in content providers names (used for id lookup)
122 * @@todo we will want to load more per user-preference and per category lookup
125 /*content_providers documentation:
126 * @@todo we should move the bulk of the configuration to each file
129 @enabled: whether the search provider can be selected
130 @checked: whether the search provider will show up as seleatable tab (todo: user preference)
131 @d: default: if the current cp should be displayed (only one should be the default)
132 @title: the title of the search provider
133 @desc: can use html... todo: need to localize
134 @api_url: the url to query against given the library type:
135 @lib: the search library to use corresponding to the
136 search object ie: 'mediaWiki' = new mediaWikiSearchSearch()
137 @tab_img: the tab image (if set to false use title text)
138 if === "ture" use standard location skin/images/{cp_id}_tab.png
139 if === string use as url for image
141 @linkback_icon default is: /wiki/skins/common/images/magnify-clip.png
143 //domain insert: two modes: simple config or domain list:
144 @local : if the content provider assets need to be imported or not.
145 @local_domains : sets of domains for which the content is local
146 //@@todo should query wgForeignFileRepos setting maybe interwikimap from the api
151 'title' : 'This Wiki',
152 'desc' : '(should be updated with the proper text) maybe import from some config value',
153 'api_url': ( wgServer
&& wgScriptPath
)? wgServer
+ wgScriptPath
+ '/api.php': null,
161 'title' :'Wikimedia Commons',
162 'desc' : 'Wikimedia Commons is a media file repository making available public domain '+
163 'and freely-licensed educational media content (images, sound and video clips) to all.',
164 'homepage': 'http://commons.wikimedia.org/wiki/Main_Page',
165 'api_url':'http://commons.wikimedia.org/w/api.php',
167 'resource_prefix': 'WC_', //prefix on imported resources (not applicable if the repository is local)
169 //if we should check for shared repository asset ( generally only applicable to commons )
172 //list all the domains where commons is local?
173 // probably should set this some other way by doing an api query
174 // or by seeding this config when calling the remote search?
175 'local_domains': ['wikimedia','wikipedia','wikibooks'],
176 //specific to wiki commons config:
177 'search_title':false, //disable title search
183 'title' : 'Archive.org',
184 'desc' : 'The Internet Archive, a digital library of cultural artifacts',
185 'homepage':'http://www.archive.org/about/about.php',
187 'api_url':'http://homeserver7.us.archive.org:8983/solr/select',
188 'lib' : 'archiveOrg',
190 'resource_prefix': 'AO_',
196 'title' : 'flickr.com',
197 'desc' : 'flickr.com, a online photo sharing site',
198 'homepage':'http://www.flickr.com/about/',
200 'api_url':'http://www.flickr.com/services/rest/',
203 'resource_prefix': '',
209 'title' : 'Metavid.org',
210 'homepage':'http://metavid.org/wiki/Metavid_Overview',
211 'desc' : 'Metavid hosts thousands of hours of US house and senate floor proceedings',
212 'api_url':'http://metavid.org/w/index.php?title=Special:MvExportSearch',
214 'local' :false, //if local set to true we can use local
215 'resource_prefix': 'MV_', //what prefix to use on imported resources
217 'local_domains': ['metavid'], // if the domain name contains metavid
218 // no need to import metavid content to metavid sites
220 'stream_import_key': 'mv_ogg_low_quality', // which stream to import, could be mv_ogg_high_quality
221 //or flash stream, see ROE xml for keys
223 'remote_embed_ext': false, //if running the remoteEmbed extension no need to copy local
224 //syntax will be [remoteEmbed:roe_url link title]
227 //special cp "upload"
234 //define the licenses
235 // ... this will get complicated quick...
236 // (just look at complexity for creative commons without exessive "duplicate data")
237 // ie cc_by could be "by/3.0/us/" or "by/2.1/jp/" to infinitum...
238 // some complexity should be negated by license equivalances.
240 // but we will have to abstract into another class let content providers provide license urls
241 // and we have to clone the license object and allow local overrides
244 //for now only support creative commons type licenses
245 //used page: http://creativecommons.org/licenses/
247 'base_img_url':'http://upload.wikimedia.org/wikipedia/commons/thumb/',
248 'base_license_url': 'http://creativecommons.org/licenses/',
261 'im':'1/11/Cc-by_new_white.svg/20px-Cc-by_new_white.svg.png'
264 'im':'2/2f/Cc-nc_white.svg/20px-Cc-nc_white.svg.png'
267 'im':'b/b3/Cc-nd_white.svg/20px-Cc-nd_white.svg.png'
270 'im':'d/df/Cc-sa_white.svg/20px-Cc-sa_white.svg.png'
273 'im':'5/51/Cc-pd-new_white.svg/20px-Cc-pd-new_white.svg.png'
280 * @param license_key the license key (ie "by-sa" or "by-nc-sa" etc)
282 getlicenseImgSet: function( licenseObj
){
283 //js_log('output images: '+ imgs);
284 return '<div class="rsd_license" title="'+ licenseObj
.title
+ '" >' +
285 '<a target="_new" href="'+ licenseObj
.lurl
+'" ' +
286 'title="' + licenseObj
.title
+ '">'+
287 licenseObj
.img_html
+
292 * getLicenceKeyFromKey
293 * @param license_key the key of the license (must be defined in: this.licenses.cc.licenses)
295 getLicenceFromKey:function( license_key
, force_url
){
296 //set the current license pointer:
297 var cl
= this.licenses
.cc
;
298 var title
= gM('mwe-cc_title');
300 var license_set
= license_key
.split('-');
301 for(var i
=0;i
< license_set
.length
; i
++){
302 var lkey
= license_set
[i
];
303 if(! cl
.license_img
[ lkey
] ){
304 js_log("MISSING::" + lkey
);
307 title
+= ' ' + gM( 'mwe-cc_' + lkey
+ '_title');
308 imgs
+='<img class="license_desc" width="20" src="'
309 + cl
.base_img_url
+ cl
.license_img
[ lkey
].im
+ '">';
311 var url
= (force_url
) ? force_url
: cl
.base_license_url
+ cl
.licenses
[ license_key
];
320 * getLicenceKeyFromUrl
321 * @param licence_url the url of the license
323 getLicenceFromUrl: function( license_url
){
324 //check for some pre-defined url types:
325 if( license_url
== 'http://www.usa.gov/copyright.shtml')
326 return this.getLicenceFromKey('pd' , license_url
);
328 //js_log("getLicenceFromUrl::" + license_url);
329 //first do a direct lookup check:
330 for(var j
=0; j
< this.licenses
.cc
.licenses
.length
; j
++){
331 var jL
= this.licenses
.cc
.licenses
[ j
];
334 var keyCheck
= 'publicdomain';
338 if( parseUri(license_url
).path
.indexOf('/'+ keyCheck
+'/') != -1){
339 return this.getLicenceFromKey(jL
, license_url
);
342 //could not find it return mwe-unknown_license
344 'title' : gM('mwe-unknown_license'),
345 'img_html' : '<span>' + gM('mwe-unknown_license') + '</span>',
351 * @param str mime type of the requested file
353 getTypeIcon:function( mimetype
) {
356 case 'image/svg+xml':
368 case 'application/ogg':
374 js_log("unkown ftype: " + mimetype
);
376 return '<div class="rsd_file_type ui-corner-all ui-state-default ui-widget-content" title="' + gM('mwe-ftype-' + typestr
) + '">' +
380 //some default layout values:
382 image_edit_width
: 400,
383 video_edit_width
: 400,
384 insert_text_pos
: 0, //insert at the start (will be overwritten by the user cursor pos)
385 result_display_mode
: 'box', //box or list
389 proxySetupDone
: null,
392 init: function( options
){
394 js_log('remoteSearchDriver:init');
396 //merge in the options:
397 //@@todo for cleaner config we should set _this.opt to the provided options)
398 $j
.extend( _this
, default_remote_search_options
, options
);
400 //update the base text:
401 if(_this
.target_textbox
)
402 _this
.getTexboxSelection();
404 //modify the content provider config based on options:
405 if(_this
.enabled_cps
!= 'all'){
406 for(var i
in this.content_providers
){
407 if( $j
.inArray(i
, _this
.enabled_cps
) != -1 ){
408 this.content_providers
[i
].enabled
= true;
410 this.content_providers
[i
].enabled
= false;
414 //set the upload target name if unset
415 if( _this
.upload_api_target
== 'local' && ! _this
.upload_api_name
&& wgSiteName
)
416 _this
.upload_api_name
= wgSiteName
;
419 //set up the target invocation:
420 if( $j( this.target_invocation
).length
==0 ){
421 js_log("RemoteSearchDriver:: no target invocation provided (will have to run your own doInitDisplay() )");
423 if( this.target_invocation
){
424 $j(this.target_invocation
).css('cursor','pointer').attr('title', gM('mwe-add_media_wizard')).click(function(){
425 _this
.doInitDisplay();
430 doInitDisplay:function(){
432 //setup the parent container:
435 this.init_interface_html();
437 this.add_interface_bindings();
439 //update the target binding to just un-hide the dialog:
440 if( this.target_invocation
){
441 $j(this.target_invocation
).unbind().click(function(){
442 js_log("doInitDisplay:target_invocation: click doReDisp");
447 doReDisplay: function(){
449 js_log("doReDisplay::");
450 //update the base text:
451 if( _this
.target_textbox
)
452 _this
.getTexboxSelection();
453 //$j(_this.target_container).dialog("open");
454 $j(_this
.target_container
).parents('.ui-dialog').fadeIn('slow');
455 //re-center the dialog:
456 $j(_this
.target_container
).dialog('option', 'position','center');
458 //gets the in and out points for insert position or grabs the selected text for search
459 getTexboxSelection:function(){
460 //update the caretPos
463 //if we have highlighted text use that as the query: (would be fun to add context menu once we have rich editor in-place)
464 if( this.caret_pos
.selection
)
465 this.default_query
= this.caret_pos
.selection
468 getCaretPos:function(){
470 var txtarea
= $j(this.target_textbox
).get(0);
471 var getTextCusorStartPos = function (o
){
472 if (o
.createTextRange
) {
473 var r
= document
.selection
.createRange().duplicate()
474 r
.moveEnd('character', o
.value
.length
)
475 if (r
.text
== '') return o
.value
.length
476 return o
.value
.lastIndexOf(r
.text
)
477 } else return o
.selectionStart
479 var getTextCusorEndPos = function (o
){
480 if (o
.createTextRange
) {
481 var r
= document
.selection
.createRange().duplicate();
482 r
.moveStart('character', -o
.value
.length
);
483 return r
.text
.length
;
485 return o
.selectionEnd
488 this.caret_pos
.s
= getTextCusorStartPos( txtarea
);
489 this.caret_pos
.e
= getTextCusorEndPos( txtarea
);
490 this.caret_pos
.text
= txtarea
.value
;
491 if(this.caret_pos
.s
&& this.caret_pos
.e
&&
492 (this.caret_pos
.s
!= this.caret_pos
.e
))
493 this.caret_pos
.selection
= this.caret_pos
.text
.substring(this.caret_pos
.s
, this.caret_pos
.e
).replace(/ /g
, '\xa0') || '\xa0';
495 js_log('got caret_pos:' + this.caret_pos
.s
);
496 //restore text value: (creating textRanges sometimes screws with the text content)
497 $j(this.target_textbox
).val(this.caret_pos
.text
);
499 init_modal:function(){
500 js_log("init_modal");
502 _this
.target_container
= '#rsd_modal_target';
503 //add the parent target_container if not provided or missing
504 if(!_this
.target_container
|| $j(_this
.target_container
).length
==0){
505 $j('body').append('<div id="rsd_modal_target" style="position:absolute;top:3em;left:0px;bottom:3em;right:0px;" title="' + gM('mwe-add_media_wizard') + '" ></div>');
506 //js_log('appended: #rsd_modal_target' + $j(_this.target_container).attr('id'));
507 //js_log('added target id:' + $j(_this.target_container).attr('id'));
509 js_log( 'width: ' + $j(window
).width() + ' height: ' + $j(window
).height());
511 cConf
['cancel'] = function(){
512 _this
.cancelClipEditCB();
515 js_log('do resize:: ' + _this
.target_container
);
516 $j( '#rsd_modal_target').dialog('option', 'width', $j(window
).width()-50 );
517 $j( '#rsd_modal_target').dialog('option', 'height', $j(window
).height()-50 );
518 $j( '#rsd_modal_target').dialog('option', 'position','center');
521 $j(_this
.target_container
).dialog({
529 //if we are 'editing' a item close that
530 //@@todo maybe prompt the user?
531 _this
.cancelClipEditCB();
532 $j(this).parents('.ui-dialog').fadeOut('slow');
536 $j(window
).resize(function(){
541 //re add cancel button
542 _this
.cancelClipEditCB();
544 //update the child position: (some of this should be pushed up-stream via dialog config options
545 $j(_this
.target_container
+'~ .ui-dialog-buttonpane').css({
546 'position':'absolute',
553 //sets up the initial html interface
554 init_interface_html:function(){
555 js_log('init_interface_html');
557 var dq
= (this.default_query
)? this.default_query
: '';
558 js_log('f::init_interface_html');
560 var o
= '<div class="rsd_control_container" style="width:100%">' +
561 '<form id="rsd_form" action="javascript:return false;" method="GET">'+
562 '<input class="ui-widget-content ui-corner-all" type="text" tabindex="1" value="' + dq
+ '" maxlength="512" id="rsd_q" name="rsd_q" '+
563 'size="20" autocomplete="off"/> '+
564 $j
.btnHtml( gM('mwe-media_search'), 'rms_search_button', 'search') +
566 //close up the control container:
569 //search provider tabs based on "checked" and "enabled" and "combined tab"
570 o
+='<div id="rsd_results_container" style="top:0px;bottom:0px;left:0px;right:0px;"></div>';
571 $j(this.target_container
).html( o
);
574 $j(this.target_container
+ ' .rms_search_button').btnBind().click(function(){
580 //run the default search:
581 if( this.default_query
)
584 add_interface_bindings:function(){
586 js_log("f:add_interface_bindings:");
589 $j('#mso_selprovider,#mso_selprovider_close').unbind().click(function(){
590 if($j('#rsd_options_bar:hidden').length
!=0 ){
591 $j('#rsd_options_bar').animate({
596 $j('#rsd_options_bar').animate({
599 }, "normal", function(){
605 $j('#rsd_form').unbind().submit(function(){
607 //don't submit the form
611 doUploadInteface:function(){
612 js_log("doUploadInteface::");
615 mv_set_loading('#tab-upload');
616 //do things async to keep interface snappy
617 setTimeout(function(){
618 //do config variable reality checks:
619 if( _this
.upload_api_target
== 'local' ){
620 if( ! _this
.local_wiki_api_url
){
621 $j('#tab-upload').html( gM( 'rsd_config_error', 'missing_local_api_url' ) );
624 _this
.upload_api_target
= _this
.local_wiki_api_url
;
628 //make sure we have a url for the upload target:
629 if( parseUri( _this
.upload_api_target
).host
== _this
.upload_api_target
){
630 $j('#tab-upload').html( gM('rsd_config_error', 'bad_api_url') );
633 //check if we need to setup the proxy::
634 if( parseUri( document
.URL
).host
!= parseUri( _this
.upload_api_target
).host
){
636 $j('#tab-upload').html( 'do proxy setup');
638 _this
.getUploadForm();
642 getUploadForm:function(){
644 mvJsLoader
.doLoad(['$j.fn.simpleUploadForm'],function(){
645 //get extends info about the file
646 var cp
= _this
.content_providers
['this_wiki'];
648 //check for "this_wiki" enabled
650 $j('#tab-upload').html('error this_wiki not enabled (can\'t get uploaded file info)');
654 //load this_wiki search system to grab the rObj
655 _this
.loadSearchLib(cp
, function(){
656 //do basic layout form on left upload "bin" on right
657 $j('#tab-upload').html('<table>' +
659 '<td valign="top" style="width:350px; padding-right: 12px;">' +
660 '<h4>' + gM('mwe-upload_a_file', _this
.upload_api_name
) + '</h4>' +
661 '<div id="upload_form">' +
662 mv_get_loading_img() +
665 '<td valign="top" id="upload_bin_cnt">' +
666 '<h4>' + gM('mwe-your_recent_uploads', _this
.upload_api_name
) + '</h4>' +
667 '<div id="upload_bin">' +
668 mv_get_loading_img() +
675 //fill in the user page:
676 if(typeof wgUserName
!= 'undefined' && wgUserName
){
677 //load the upload bin with anything the current user has uploaded
678 cp
.sObj
.getUserRecentUploads( wgUserName
, function(){
679 _this
.drawOutputResults();
682 $j('#upload_bin_cnt').empty();
685 //deal with the api form upload form directly:
686 $j('#upload_form').simpleUploadForm({
687 "api_target" : _this
.upload_api_target
,
688 "ondone_cb" : function( resultData
){
689 var wTitle
= resultData
['filename'];
691 _this
.addResourceEditLoader();
692 //@@note: we have most of what we need in resultData imageinfo
693 cp
.sObj
.addByTitle( wTitle
, function( rObj
){
694 //redraw (with added result if new)
695 _this
.drawOutputResults();
696 //pull up resource editor:
697 _this
.resourceEdit( rObj
, $j('#res_upload__' + rObj
.id
).get(0) );
699 //return false to close progress window:
703 }); //load searchLibs
704 }); //load simpleUploadForm
706 runSearch: function(){
707 js_log("f:runSearch::" + this.disp_item
);
709 var draw_direct_flag
= true;
711 //check if its the special upload tab case:
712 if( this.disp_item
== 'upload'){
713 this.doUploadInteface();
718 var cp
= this.content_providers
[this.disp_item
];
720 //check if we need to update:
721 if( typeof cp
.sObj
!= 'undefined' ){
722 if(cp
.sObj
.last_query
== $j('#rsd_q').val() && cp
.sObj
.last_offset
== cp
.offset
){
723 js_log('last query is: ' + cp
.sObj
.last_query
+ ' matches: ' + $j('#rsd_q').val() );
725 js_log('last query is: ' + cp
.sObj
.last_query
+ ' not match: ' + $j('#rsd_q').val() );
726 draw_direct_flag
= false;
729 draw_direct_flag
= false;
731 if( !draw_direct_flag
){
732 //set the content to loading while we do the search:
733 $j('#tab-' + this.disp_item
).html( mv_get_loading_img() );
735 //make sure the search library is loaded and issue the search request
736 this.getLibSearchResults( cp
);
739 //issue a api request & cache the result
740 //this check can be avoided by setting the this.import_url_mode = 'api' | 'form' | insted of 'autodetect' or 'none'
741 checkForCopyURLSupport:function ( callback
){
743 js_log('checkForCopyURLSupport:: ');
744 //check if the import url is diffrent from
745 //check if we need to setup the proxy::
746 /*if( parseUri( document.URL ).host != parseUri( _this.upload_api_target ).host ){
748 js_log(" doc.url:" + parseUri( document.URL ).host + ' != ' +parseUri( _this.upload_api_target ).host);
749 $j('#tab-' + this.disp_item ).html( 'do proxy setup');
753 //see if we already have the import mode:
754 if( this.import_url_mode
!= 'autodetect'){
755 js_log('import mode: ' + _this
.import_url_mode
);
758 //if we don't have the local wiki api defined we can't auto-detect use "link"
759 if(!_this
.local_wiki_api_url
){
760 js_log('import mode: remote link (no import_wiki_api_url)');
761 _this
.import_url_mode
= 'remote_link';
764 if( this.import_url_mode
== 'autodetect' ){
766 'data': { 'action':'paraminfo', 'modules':'upload' },
767 'url': _this
.local_wiki_api_url
769 //jump right into api checks:
770 for( var i
in data
.paraminfo
.modules
[0].parameters
){
771 var pname
= data
.paraminfo
.modules
[0].parameters
[i
].name
;
772 if( pname
== 'url' ){
773 js_log( 'Autodetect Upload Mode: api: copy by url:: ' );
774 //check permission too:
775 _this
.checkForCopyURLPermission(function( canCopyUrl
){
777 _this
.import_url_mode
= 'api';
778 js_log('import mode: ' + _this
.import_url_mode
);
781 _this
.import_url_mode
= 'none';
782 js_log('import mode: ' + _this
.import_url_mode
);
793 * checkForCopyURLPermission:
794 * not really necessary the api request to upload will return appropriate error if the user lacks permission. or $wgAllowCopyUploads is set to false
795 * (use this function if we want to issue a warning up front)
797 checkForCopyURLPermission:function( callback
){
801 'data':{ 'action' : 'query', 'meta' : 'userinfo', 'uiprop' : 'rights' },
802 'url': _this
.local_wiki_api_url
,
805 for( var i
in data
.query
.userinfo
.rights
){
806 var right
= data
.query
.userinfo
.rights
[i
];
807 //js_log('checking: ' + right ) ;
808 if(right
== 'upload_by_url'){
810 return true; //break out of the function
816 getLibSearchResults:function( cp
){
819 //first check if we should even run the search at all (can we import / insert into the page? )
820 if( !this.checkRepoLocal( cp
) && this.import_url_mode
== 'autodetect' ){
821 //cp is not local check if we can support the import mode:
822 this.checkForCopyURLSupport( function(){
823 _this
.getLibSearchResults( cp
);
826 }else if( !this.checkRepoLocal( cp
) && this.import_url_mode
== 'none'){
827 if( this.disp_item
== 'combined' ){
828 //combined results are harder to error handle just ignore that repo
829 cp
.sObj
.loading
= false;
831 $j('#tab-' + this.disp_item
).html( '<div style="padding:10px">'+ gM('mwe-no_import_by_url') +'</div>');
835 _this
.loadSearchLib(cp
, function(){
837 cp
.sObj
.getSearchResults();
838 _this
.checkResultsDone();
841 loadSearchLib:function(cp
, callback
){
843 //set up the library req:
848 js_log("loaded lib:: " + cp
.lib
);
849 //else we need to run the search:
854 eval('cp.sObj = new ' + cp
.lib
+ 'Search( iObj );' );
856 js_log('Error: could not find search lib for ' + cp_id
);
860 //inherit defaults if not set:
861 cp
.limit
= (cp
.limit
) ? cp
.limit
: cp
.sObj
.limit
;
862 cp
.offset
= (cp
.offset
) ? cp
.offset
: cp
.sObj
.offset
;
866 /* check for all the results to finish */
867 checkResultsDone: function(){
868 //js_log('rsd:checkResultsDone');
870 var loading_done
= true;
872 for(var cp_id
in this.content_providers
){
873 var cp
= this.content_providers
[ cp_id
];
874 if(typeof cp
['sObj'] != 'undefined'){
875 if( cp
.sObj
.loading
)
876 loading_done
= false;
880 this.drawOutputResults();
882 //make sure the instance name is up-to-date refrerance to _this;
883 eval( _this
.instance_name
+ ' = _this');
884 setTimeout( _this
.instance_name
+ '.checkResultsDone()', 50);
887 drawTabs: function(){
889 //add the tabs to the rsd_results container:
890 var o
='<div id="rsd_tabs_container" style="width:100%;">';
891 var selected_tab
= 0;
895 for(var cp_id
in this.content_providers
){
896 var cp
= this.content_providers
[cp_id
];
897 if( cp
.enabled
&& cp
.checked
&& cp
.api_url
){
898 //add selected default if set
899 if( this.disp_item
== cp_id
)
902 o
+='<li class="rsd_cp_tab">';
903 o
+='<a id="rsd_tab_' + cp_id
+ '" href="#tab-' + cp_id
+ '">';
904 if(cp
.tab_img
=== true){
905 o
+='<img alt="' + cp
.title
+'" src="' + mv_skin_img_path
+ 'remote_cp/' + cp_id
+ '_tab.png">';
913 tabc
+='<div id="tab-'+ cp_id
+'" class="rsd_results"/>';
916 //do an upload tab if enabled:
917 if( this.content_providers
['upload'].enabled
){
918 o
+='<li class="rsd_cp_tab" ><a id="rsd_tab_upload" href="#tab-upload">' + gM('mwe-upload_tab') + '</a></li>';
919 tabc
+='<div id="tab-upload" />';
920 if(this.disp_item
== 'upload')
921 selected_tab
= inx
++;
924 //output the tab content containers:
926 o
+='</div>'; //close tab container
928 //output the respective results holders
929 $j('#rsd_results_container').html(o
);
930 //setup bindings for tabs make them sortable: (@@todo remember order)
931 js_log('selected tab is: ' + selected_tab
);
932 $j("#rsd_tabs_container").tabs({
933 selected
:selected_tab
,
934 select: function(event
, ui
) {
935 _this
.selectTab( $j(ui
.tab
).attr('id').replace('rsd_tab_', '') );
938 }).find(".ui-tabs-nav").sortable({axis
:'x'});
940 /*$j('.rsd_cp_tab').click(function(){
941 _this.selectTab( $j(this).attr('id').replace(/rsd_tab_/, '') );
944 //setup key binding (no longer nesesary tabs provide this functionality)
945 /*$j().keyup(function(e){
946 js_log('keyup on : ' +e.which );
947 //if escape pressed clear the interface:
954 getResourceFromTitle:function( rTitle
, callback
){
958 'titles': _this
.cFileNS
+ ':' + rTitle
962 'url':this.local_wiki_api_url
964 //@@todo propogate the rObj
969 //@@todo we could load the id with the content provider id to find the object faster...
970 getResourceFromId:function( rid
){
971 //js_log('getResourceFromId:' + rid );
972 //strip out /res/ if preset:
973 rid
= rid
.replace(/res_/, '');
974 //js_log("looking at: " + rid);
979 //Set the upload helper cp_id (to render recent uploads by this user)
980 if(cp_id
== 'upload')
983 var cp
= this.content_providers
[cp_id
];
984 if(cp
&& cp
['sObj'] && cp
.sObj
.resultsObj
[rid
]){
985 return cp
.sObj
.resultsObj
[rid
];
987 js_log("ERROR: could not find " + rid
);
990 drawOutputResults: function(){
991 js_log('f:drawOutputResults::' + this.disp_item
);
995 var cp_id
= this.disp_item
;
997 if(this.disp_item
== 'upload'){
998 tab_target
= '#upload_bin';
999 var cp
= _this
.content_providers
['this_wiki'];
1001 var cp
= this.content_providers
[this.disp_item
];
1002 tab_target
= '#tab-' + cp_id
;
1003 //output the results bar / controls
1005 //empty the existing results:
1006 $j(tab_target
).empty();
1007 //@@todo give the user upload control love
1008 if(this.disp_item
!= 'upload'){
1009 _this
.setResultBarControl();
1012 var drawResultCount
= 0;
1014 //output all the results for the current disp_item
1015 if( typeof cp
['sObj'] != 'undefined' ){
1016 $j
.each(cp
.sObj
.resultsObj
, function(rInx
, rItem
){
1017 if( _this
.result_display_mode
== 'box' ){
1018 o
+='<div id="mv_result_' + rInx
+ '" class="mv_clip_box_result" style="width:' +
1019 _this
.thumb_width
+ 'px;height:'+ (_this
.thumb_width
-20) +'px;position:relative;">';
1020 //check for missing poster types for audio
1021 if( rItem
.mime
=='audio/ogg' && !rItem
.poster
){
1022 rItem
.poster
= mv_skin_img_path
+ 'sound_music_icon-80.png';
1024 //get a thumb with proper resolution transform if possible:
1025 o
+='<img title="'+rItem
.title
+'" class="rsd_res_item" id="res_' + cp_id
+ '__' + rInx
+
1026 '" style="width:' + _this
.thumb_width
+ 'px;" src="' +
1027 cp
.sObj
.getImageTransform( rItem
, { 'width' : _this
.thumb_width
} )
1029 //add a linkback to resource page in upper right:
1031 o
+='<div class="rsd_linkback ui-corner-all ui-state-default ui-widget-content" >' +
1032 '<a target="_new" title="' + gM('mwe-resource_description_page') +
1033 '" href="' + rItem
.link
+ '">'+ gM('mwe-link') + '</a>' +
1036 //add file type icon if known
1038 o
+= _this
.getTypeIcon( rItem
.mime
);
1041 //add license icons if present
1043 o
+= _this
.getlicenseImgSet( rItem
.license
);
1046 }else if(_this
.result_display_mode
== 'list'){
1047 o
+='<div id="mv_result_' + rInx
+ '" class="mv_clip_list_result" style="width:90%">';
1048 o
+='<img title="'+rItem
.title
+'" class="rsd_res_item" id="res_' + cp_id
+ '__' + rInx
+'" style="float:left;width:' +
1049 _this
.thumb_width
+ 'px;" src="' +
1050 cp
.sObj
.getImageTransform( rItem
, {'width':_this
.thumb_width
} )
1052 //add license icons if present
1054 o
+= _this
.getlicenseImgSet( rItem
.license
);
1057 o
+='<div style="clear:both" />';
1062 js_log('append to: ' + '#tab-' + cp_id
);
1063 //put in the tab output (plus clear the output)
1064 $j(tab_target
).append( o
+ '<div style="clear:both"/>');
1067 js_log( 'did drawResultCount :: ' + drawResultCount
+ ' append: ' + $j('#rsd_q').val() );
1069 //remove any old search res
1070 $j('#rsd_no_search_res').remove();
1071 if( drawResultCount
== 0 )
1072 $j('#tab-' + cp_id
).append( '<span style="padding:10px">' + gM( 'rsd_no_results', $j('#rsd_q').val() ) + '</span>');
1074 this.addResultBindings();
1076 addResultBindings:function(){
1078 $j('.mv_clip_'+_this
.result_display_mode
+'_result').hover(function(){
1079 $j(this).addClass('mv_clip_'+_this
.result_display_mode
+'_result_over');
1080 //also set the animated image if available
1081 var res_id
= $j(this).children('.rsd_res_item').attr('id');
1082 var rObj
= _this
.getResourceFromId( res_id
);
1083 if( rObj
.poster_ani
)
1084 $j('#' + res_id
).attr('src', rObj
.poster_ani
);
1086 $j(this).removeClass('mv_clip_'+_this
.result_display_mode
+'_result_over');
1087 var res_id
= $j(this).children('.rsd_res_item').attr('id');
1088 var rObj
= _this
.getResourceFromId( res_id
);
1089 //restore the original (non animated)
1090 if( rObj
.poster_ani
)
1091 $j('#' + res_id
).attr('src', rObj
.poster
);
1093 //resource click action: (bring up the resource editor)
1094 $j('.rsd_res_item').unbind().click(function(){
1095 var rObj
= _this
.getResourceFromId( $j(this).attr("id") );
1096 _this
.resourceEdit( rObj
, this );
1099 addResourceEditLoader:function(maxWidth
, overflow_style
){
1101 if(!maxWidth
)maxWidth
=400;
1102 if(!overflow_style
)overflow_style
='overflow:auto;';
1103 //remove any old instance:
1104 $j( _this
.target_container
).find('#rsd_resource_edit').remove();
1105 //add the edit layout window with loading place holders
1106 $j( _this
.target_container
).append('<div id="rsd_resource_edit" '+
1107 'style="position:absolute;top:0px;left:0px;bottom:0px;right:4px;background-color:#FFF;">' +
1108 '<div id="clip_edit_ctrl" class="ui-widget ui-widget-content ui-corner-all" style="position:absolute;'+
1109 'left:2px;top:5px;bottom:10px;width:' + ( maxWidth
+ 5 ) + 'px;overflow:auto;padding:5px;">'+
1110 mv_get_loading_img() +
1112 '<div id="clip_edit_disp" class="ui-widget ui-widget-content ui-corner-all"' +
1113 'style="position:absolute;' + overflow_style
+ ';left:'+ ( maxWidth
+ 20 ) +'px;right:0px;top:5px;bottom:10px;padding:5px;>' +
1114 mv_get_loading_img('position:absolute;top:30px;left:30px') +
1118 resourceEdit:function( rObj
, rsdElement
){
1119 js_log('f:resourceEdit:' + rObj
.title
);
1121 //remove any existing resource edit interface:
1122 $j('#rsd_resource_edit').remove();
1123 //set the media type:
1124 if(rObj
.mime
.indexOf('image')!=-1){
1125 //set width to default image_edit_width
1126 var maxWidth
= _this
.image_edit_width
;
1127 var mediaType
= 'image';
1128 }else if(rObj
.mime
.indexOf('audio')!=-1){
1129 var maxWidth
= _this
.video_edit_width
;
1130 var mediaType
= 'audio';
1132 //set to default video size:
1133 var maxWidth
= _this
.video_edit_width
;
1134 var mediaType
= 'video';
1136 //so that transcripts show ontop
1137 var overflow_style
= ( mediaType
=='video' )?'':'overflow:auto;';
1138 //append to the top level of model window:
1139 _this
.addResourceEditLoader(maxWidth
, overflow_style
);
1140 //update add media wizard title:
1141 $j( _this
.target_container
).dialog( 'option', 'title', gM('mwe-add_media_wizard')+': '+ gM('rsd_resource_edit', rObj
.title
) );
1142 js_log('did append to: '+ _this
.target_container
);
1144 $j('#rsd_resource_edit').css('opacity',0);
1146 $j('#rsd_edit_img').remove();//remove any existing rsd_edit_img
1148 //left side holds the image right size the controls /
1149 $j(rsdElement
).clone().attr('id', 'rsd_edit_img').appendTo('#clip_edit_disp').css({
1150 'position':'absolute',
1157 //try and keep aspect ratio for the thumbnail that we clicked:
1158 var tRatio
= $j(rsdElement
).height() / $j(rsdElement
).width();
1161 var tRatio
= 1; //set ratio to 1 if tRatio did not work.
1163 js_log('Set from ' + tRatio
+ ' to init thumbimage to ' + maxWidth
+ ' x ' + parseInt( tRatio
* maxWidth
) );
1164 //scale up image and to swap with high res version
1165 $j('#rsd_edit_img').animate({
1169 'width': maxWidth
+ 'px',
1170 'height': parseInt( tRatio
* maxWidth
) + 'px'
1171 }, "slow"); // do it slow to give it a chance to finish loading the HQ version
1173 if( mediaType
== 'image' ){
1174 _this
.loadHQImg(rObj
, {'width':maxWidth
}, 'rsd_edit_img', function(){
1175 $j('.mv_loading_img').remove();
1178 //also fade in the container:
1179 $j('#rsd_resource_edit').animate({
1181 'background-color':'#FFF',
1184 //do load the media Editor
1185 _this
.doMediaEdit( rObj
, mediaType
);
1187 loadHQImg:function(rObj
, size
, target_img_id
, callback
){
1188 // Get the HQ image url:
1189 rObj
.pSobj
.getImageObj( rObj
, size
, function( imObj
){
1190 rObj
['edit_url'] = imObj
.url
;
1192 js_log("edit url: " + rObj
.edit_url
);
1194 rObj
['width'] = imObj
.width
;
1195 rObj
['height'] = imObj
.height
;
1197 // See if we need to animate some transition
1198 if( size
.width
!= imObj
.width
){
1199 js_log('loadHQImg:size mismatch: ' + size
.width
+ ' != ' + imObj
.width
);
1200 //set the target id to the new size:
1201 $j('#'+target_img_id
).animate( {
1202 'width':imObj
.width
+ 'px',
1203 'height':imObj
.height
+ 'px'
1206 js_log('using req size: ' + imObj
.width
+ 'x' + imObj
.height
);
1207 $j('#'+target_img_id
).animate( {'width':imObj
.width
+'px', 'height' : imObj
.height
+ 'px'});
1209 //don't swap it in until its loaded:
1210 var img
= new Image();
1211 // load the image image:
1212 $j(img
).load(function () {
1213 $j('#'+target_img_id
).attr('src', rObj
.edit_url
);
1214 //let the caller know we are done and what size we ended up with:
1216 }).error(function () {
1217 js_log("Error with: " + rObj
.edit_url
);
1218 }).attr('src', rObj
.edit_url
);
1221 cancelClipEditCB:function(){
1223 js_log('cancelClipEditCB');
1224 var b_target
= _this
.target_container
+ '~ .ui-dialog-buttonpane';
1225 $j('#rsd_resource_edit').remove();
1226 //remove preview if its 'on'
1227 $j('#rsd_preview_display').remove();
1228 //restore the resource container:
1229 $j('#rsd_results_container').show();
1231 //restore the title:
1232 $j( _this
.target_container
).dialog( 'option', 'title', gM('mwe-add_media_wizard'));
1233 js_log("should update: " + b_target
+ ' with: cancel');
1234 //restore the buttons:
1235 $j(b_target
).html( $j
.btnHtml( 'Cancel' , 'mv_cancel_rsd', 'close'))
1236 .children('.mv_cancel_rsd')
1239 $j( _this
.target_container
).dialog('close');
1243 /*set-up the control actions for clipEdit with relevent callbacks */
1244 getClipEditControlActions:function( cp
){
1248 cConf
['insert'] = function(rObj
){
1249 _this
.insertResource(rObj
);
1251 //if not directly inserting the resource is support a preview option:
1252 if( _this
.import_url_mode
!= 'remote_link'){
1253 cConf
['preview'] = function(rObj
){
1254 _this
.previewResource( rObj
)
1257 cConf
['cancel'] = function(){
1258 _this
.cancelClipEditCB()
1262 //loads the media editor:
1263 doMediaEdit:function( rObj
, mediaType
){
1265 var cp
= rObj
.pSobj
.cp
;
1266 js_log('remoteSearchDriver::doMediaEdit: ' + mediaType
);
1269 'rObj' : rObj
, //the resource object
1270 'parent_ct' : 'rsd_modal_target',
1271 'clip_disp_ct' : 'clip_edit_disp',
1272 'control_ct' : 'clip_edit_ctrl',
1273 'media_type' : mediaType
,
1275 'controlActionsCb' : _this
.getClipEditControlActions( cp
)
1277 //set the base clip edit lib class req set:
1278 var clibs
= ['mvClipEdit'];
1280 if( mediaType
== 'image'){
1281 //display the mvClipEdit obj once we are done loading:
1282 mvJsLoader
.doLoad( clibs
, function(){
1283 //run the image clip tools
1284 _this
.cEdit
= new mvClipEdit( mvClipInit
);
1286 }else if( mediaType
== 'video' || mediaType
== 'audio'){
1287 js_log('media type:: ' + mediaType
);
1288 //get any additional embedding helper meta data prior to doing the actual embed
1289 // normally this meta should be provided in the search result (but archive.org has another query for more media meta)
1290 rObj
.pSobj
.getEmbedTimeMeta( rObj
, function(){
1291 //make sure we have the embedVideo libs:
1292 var runFlag
= false;
1293 mvJsLoader
.embedVideoCheck( function(){
1294 //strange concurency issue with callbacks
1295 //@@todo try and figure out why this callback is fired twice
1299 js_log('only run embed vid once');
1302 js_log('append html: ' + rObj
.pSobj
.getEmbedHTML( rObj
, {id
:'embed_vid'}) );
1303 $j('#clip_edit_disp').html(
1304 rObj
.pSobj
.getEmbedHTML( rObj
, {
1308 js_log("about to call rewrite_by_id::embed_vid");
1310 rewrite_by_id('embed_vid', function(){
1311 //grab any information that we got from the ROE xml or parsed from the media file
1312 rObj
.pSobj
.getEmbedObjParsedInfo( rObj
, 'embed_vid' );
1313 //add the re-sizable to the doLoad request:
1314 clibs
.push( '$j.ui.resizable');
1315 clibs
.push( '$j.fn.hoverIntent');
1316 mvJsLoader
.doLoad(clibs
, function(){
1317 //make sure the rsd_edit_img is hidden:
1318 $j('#rsd_edit_img').remove();
1319 //run the image clip tools
1320 _this
.cEdit
= new mvClipEdit( mvClipInit
);
1327 checkRepoLocal:function( cp
){
1331 //check if we can embed the content locally per a domain name check:
1332 var local_host
= parseUri( this.local_wiki_api_url
).host
;
1333 if( cp
.local_domains
) {
1334 for(var i
=0;i
< cp
.local_domains
.length
; i
++){
1335 var ld
= cp
.local_domains
[i
];
1336 if( local_host
.indexOf( ld
) != -1)
1343 checkImportResource:function( rObj
, cir_callback
){
1345 //add a loader ontop:
1346 $j
.addLoaderDialog( gM('mwe-checking-resource') );
1347 //extend the callback with close dialog
1348 var org_cir_callback
= cir_callback
;
1349 cir_callback = function( rObj
){
1350 var cat
= org_cir_callback
;
1351 $j
.closeLoaderDialog();
1352 if( org_cir_callback
&& typeof org_cir_callback
== 'function'){
1353 org_cir_callback( rObj
);
1356 //@@todo get the localized File/Image namespace name or do a general {NS}:Title
1357 var cp
= rObj
.pSobj
.cp
;
1360 //update base target_resource_title:
1361 rObj
.target_resource_title
= rObj
.titleKey
.replace(/File:|Image:/,'')
1363 //check if local repository
1364 //or if import mode if just "linking" (we should already have the 'url'
1366 if( this.checkRepoLocal( cp
) || this.import_url_mode
== 'remote_link'){
1367 //local repo jump directly to check Import Resource callback:
1368 cir_callback( rObj
);
1370 //check if the file is local (can be shared repo)
1371 if( cp
.check_shared
){
1372 _this
.checkForFile(rObj
.target_resource_title
, function(imagePage
){
1373 if( imagePage
&& imagePage
['imagerepository'] == 'shared' ){
1374 cir_callback( rObj
);
1376 _this
.checkPrefixNameImport( rObj
, cir_callback
);
1380 _this
.checkPrefixNameImport(rObj
, cir_callback
);
1384 checkPrefixNameImport: function(rObj
, cir_callback
){
1385 js_log('::checkPrefixNameImport:: ');
1386 var cp
= rObj
.pSobj
.cp
;
1388 //update target_resource_title with resource repository prefix:
1389 rObj
.target_resource_title
= cp
.resource_prefix
+ rObj
.target_resource_title
;
1390 //check if the file exists:
1391 _this
.checkForFile( rObj
.target_resource_title
, function( imagePage
){
1393 //update to local src
1394 rObj
.local_src
= imagePage
['imageinfo'][0].url
;
1395 //@@todo maybe update poster too?
1396 rObj
.local_poster
= imagePage
['imageinfo'][0].thumburl
;
1398 rObj
.target_resource_title
= imagePage
.title
.replace(/File:|Image:/,'');
1399 cir_callback( rObj
);
1401 //close the dialog and display the import interface:
1402 $j
.closeLoaderDialog();
1403 _this
.doImportInterface(rObj
, cir_callback
);
1407 doImportInterface : function( rObj
, callback
){
1409 js_log("doImportInterface:: update:"+ _this
.cFileNS
+ ':' + rObj
.target_resource_title
);
1410 //update the rObj with import info
1411 rObj
.pSobj
.updateDataForImport( rObj
);
1413 //setup the resource description from resource description:
1414 var wt
= '{{Information '+"\n";
1417 wt
+= '|Description= ' + rObj
.desc
+ "\n";
1419 wt
+= '|Description= ' + gM('mwe-missing_desc_see_source', rObj
.link
) + "\n";
1422 //output search specific info
1423 wt
+='|Source=' + rObj
.pSobj
.getImportResourceDescWiki( rObj
) + "\n";
1426 wt
+='|Author=' + rObj
.author
+"\n";
1429 wt
+='|Date=' + rObj
.date
+"\n";
1431 //add the Permision info:
1432 wt
+='|Permission=' + rObj
.pSobj
.getPermissionWikiTag( rObj
) +"\n";
1434 if( rObj
.other_versions
)
1435 wt
+='|other_versions=' + rObj
.other_versions
+ "\n";
1439 //get any extra categories or helpful links
1440 wt
+= rObj
.pSobj
.getExtraResourceDescWiki( rObj
);
1443 $j('#rsd_resource_import').remove();//remove any old resource imports
1445 //@@ show user dialog to import the resource
1446 $j( _this
.target_container
).append('<div id="rsd_resource_import" '+
1447 'class="ui-state-highlight ui-widget-content ui-state-error" ' +
1448 'style="position:absolute;top:50px;left:50px;right:50px;bottom:50px;z-index:5">' +
1449 '<h3 style="color:red">' + gM('mwe-resource-needs-import', [rObj
.title
, _this
.upload_api_name
] ) + '</h3>' +
1450 '<div id="rsd_preview_import_container" style="position:absolute;width:50%;bottom:0px;left:0px;overflow:auto;top:30px;">' +
1451 rObj
.pSobj
.getEmbedHTML( rObj
, {
1452 'id': _this
.target_container
+ '_rsd_pv_vid',
1455 }) + //get embedHTML with small thumb:
1456 '<br style="clear both">'+
1457 '<strong>'+gM('mwe-resource_page_desc') +'</strong>'+
1458 '<div id="rsd_import_desc" syle="display:inline;">'+
1459 mv_get_loading_img('position:absolute;top:5px;left:5px') +
1462 '<div id="rds_edit_import_container" style="position:absolute;left:50%;' +
1463 'bottom:0px;top:30px;right:0px;overflow:auto;">'+
1464 '<strong>' + gM('mwe-local_resource_title') + '</strong><br>'+
1465 '<input type="text" size="30" value="' + rObj
.target_resource_title
+ '" readonly="true"><br>'+
1466 '<strong>' + gM('mwe-edit_resource_desc') + '</strong>' +
1467 '<textarea id="rsd_import_ta" id="mv_img_desc" style="width:90%;" rows="8" cols="50">' +
1470 '<input type="checkbox" value="true" id="wpWatchthis" name="wpWatchthis" tabindex="7"/>' +
1471 '<label for="wpWatchthis">'+gM('mwe-watch_this_page')+'</label><br><br><br>' +
1473 $j
.btnHtml(gM('mwe-do_import_resource'), 'rsd_import_doimport', 'check' ) + ' ' +
1475 $j
.btnHtml(gM('mwe-update_preview'), 'rsd_import_apreview', 'refresh' ) + '<div style="clear:both;height:20px;"/>' +
1477 $j
.btnHtml(gM('mwe-cancel_import'), 'rsd_import_acancel', 'close' ) + ' ' +
1480 //output the rendered and non-rendered version of description for easy switching:
1484 //update video tag (if a video)
1485 if( rObj
.mime
.indexOf('video/') !== -1 )
1486 rewrite_by_id( $j(_this
.target_container
).attr('id') + '_rsd_pv_vid');
1488 //load the preview text:
1489 _this
.getParsedWikiText( wt
, _this
.cFileNS
+':'+ rObj
.target_resource_title
, function( o
){
1490 $j('#rsd_import_desc').html(o
);
1493 $j( _this
.target_container
+ ' .rsd_import_apreview').btnBind().click(function(){
1494 js_log("do preview asset");
1495 //load the preview text:
1496 _this
.getParsedWikiText( $j('#rsd_import_ta').val(), _this
.cFileNS
+':'+ rObj
.target_resource_title
, function( o
){
1497 js_log('got updated preivew: ');
1498 $j('#rsd_import_desc').html(o
);
1501 $j(_this
.target_container
+ ' .rsd_import_doimport').btnBind().click(function(){
1502 js_log("do import asset:" + _this
.import_url_mode
);
1503 //check import mode:
1504 if( _this
.import_url_mode
== 'api' ){
1505 if( parseUri( document
.URL
).host
!= parseUri( _this
.upload_api_target
).host
){
1506 _this
.setupProxy( function(){
1508 //_this.doImportAPI( rObj , callback);
1511 _this
.doImportAPI( rObj
, callback
);
1514 js_log("Error: import mode is not form or API (can not copy asset)");
1517 $j( _this
.target_container
+ ' .rsd_import_acancel').btnBind().click(function(){
1518 $j('#rsd_resource_import').fadeOut("fast",function(){
1524 * sets up the proxy for the remote inserts
1526 setupProxy:function(callback
){
1529 if( _this
.proxySetupDone
){
1530 if(callback
) callback();
1533 //setup the the proxy via mv_embed $j.apiProxy loader:
1534 if( ! _this
.upload_api_proxy_frame
){
1535 js_log("Error:: remote api but no proxy frame target");
1541 'server_frame' : _this
.upload_api_proxy_frame
,
1543 //now that the api is setup call actual import
1549 checkForFile:function( fName
, callback
){
1550 js_log("checkForFile::");
1554 'titles': _this
.cFileNS
+ ':' + fName
,
1555 'prop' : 'imageinfo',
1559 //first check the api for imagerepository
1562 'url':this.local_wiki_api_url
1564 if( data
.query
.pages
){
1565 for(var i
in data
.query
.pages
){
1566 for(var j
in data
.query
.pages
[i
]){
1567 if(j
== 'missing' && data
.query
.pages
[i
].imagerepository
!= 'shared'){
1568 js_log(fName
+ " not found");
1573 //else page is found:
1574 js_log(fName
+ " found");
1575 callback( data
.query
.pages
[i
] );
1581 doImportAPI:function(rObj
, cir_callback
){
1583 js_log(":doImportAPI:");
1584 $j
.addLoaderDialog( gM('mwe-importing_asset') );
1585 //baseUploadInterface
1587 'mvBaseUploadInterface',
1590 js_log('mvBaseUploadInterface ready');
1591 //initiate a upload object ( similar to url copy ):
1592 myUp
= new mvBaseUploadInterface({
1593 'api_url' : _this
.local_wiki_api_url
,
1594 'done_upload_cb':function(){
1595 js_log('doImportAPI:: run callback::' );
1596 //we have finished the upload:
1598 //close up the rsd_resource_import
1599 $j('#rsd_resource_import').remove();
1600 //return the parent callback:
1601 return cir_callback();
1604 //get the edit token if we have it handy
1605 _this
.getEditToken(function( token
){
1606 myUp
.etoken
= token
;
1608 //close the loader now that we are ready to present the progress dialog::
1609 $j
.closeLoaderDialog();
1613 'filename' : rObj
.target_resource_title
,
1614 'comment' : $j('#rsd_import_ta').val()
1621 getEditToken:function(callback
){
1622 //first try the page form:
1623 var etoken
= $j("input[name='wpEditToken']").val();
1628 //@@todo try to load over ajax if( _this.local_wiki_api_url ) is set
1629 // (your on the api domain but are inserting from a normal page view)
1630 if( _this
.local_wiki_api_url
){
1631 get_mw_token(null, _this
.local_wiki_api_url
, function(token
){
1638 previewResource:function( rObj
){
1640 this.checkImportResource( rObj
, function(){
1641 //put another window ontop:
1642 $j( _this
.target_container
).append('<div id="rsd_preview_display"' +
1643 'style="position:absolute;overflow:hidden;z-index:4;top:0px;bottom:0px;right:0px;left:0px;background-color:#FFF;">' +
1644 mv_get_loading_img('top:30px;left:30px') +
1647 var bPlaneTarget
= _this
.target_container
+'~ .ui-dialog-buttonpane';
1648 var pTitle
= $j( _this
.target_container
).dialog('option', 'title');
1651 $j( _this
.target_container
).dialog('option', 'title', gM('mwe-preview_insert_resource', rObj
.title
) );
1653 //update buttons preview:
1654 $j(bPlaneTarget
).html( $j
.btnHtml( gM('rsd_do_insert'), 'preview_do_insert', 'check') + ' ' )
1655 .children('.preview_do_insert')
1657 _this
.insertResource( rObj
);
1659 //update cancel button
1660 $j(bPlaneTarget
).append('<a href="#" class="preview_close">Do More Modification</a>')
1661 .children('.preview_close')
1663 $j('#rsd_preview_display').remove();
1665 $j( _this
.target_container
).dialog('option', 'title', pTitle
);
1666 //restore buttons (from the clipEdit object::)
1667 _this
.cEdit
.updateInsertControlActions();
1670 //update the preview_wtext
1671 _this
.updatePreviewText( rObj
);
1672 _this
.getParsedWikiText(_this
.preview_wtext
, _this
.target_title
,
1674 $j('#rsd_preview_display').html( phtml
);
1675 //update the display of video tag items (if any)
1681 updatePreviewText:function( rObj
){
1684 if( _this
.import_url_mode
== 'remote_link' ){
1685 _this
.cur_embed_code
= rObj
.pSobj
.getEmbedHTML(rObj
);
1687 _this
.cur_embed_code
= rObj
.pSobj
.getEmbedWikiCode( rObj
);
1690 //insert at start if textInput cursor has not been set (ie == length)
1691 if( _this
.caret_pos
&& _this
.caret_pos
.text
){
1692 if( _this
.caret_pos
.text
.length
== _this
.caret_pos
.s
)
1693 _this
.caret_pos
.s
=0;
1694 _this
.preview_wtext
= _this
.caret_pos
.text
.substring(0, _this
.caret_pos
.s
) +
1695 _this
.cur_embed_code
+
1696 _this
.caret_pos
.text
.substring( _this
.caret_pos
.s
);
1698 _this
.preview_wtext
= $j(_this
.target_textbox
).val() + _this
.cur_embed_code
;
1700 //check for missing </refrences>
1701 if( _this
.preview_wtext
.indexOf('<references/>') ==-1 && _this
.preview_wtext
.indexOf('<ref>') != -1 )
1702 _this
.preview_wtext
= _this
.preview_wtext
+ '<references/>';
1704 getParsedWikiText:function( wikitext
, title
, callback
){
1706 'data':{'action':'parse',
1709 'url':this.local_wiki_api_url
1711 callback( data
.parse
.text
['*'] );
1715 insertResource:function( rObj
){
1716 js_log('insertResource: ' + rObj
.title
);
1719 //dobule check that the resource is present:
1720 this.checkImportResource( rObj
, function(){
1721 _this
.updatePreviewText( rObj
);
1722 $j(_this
.target_textbox
).val( _this
.preview_wtext
);
1724 //update the render area (if present)
1725 if(_this
.target_render_area
&& _this
.cur_embed_code
){
1726 //output with some padding:
1727 $j(_this
.target_render_area
).append( _this
.cur_embed_code
+ '<div style="clear:both;height:10px">')
1729 //update the player if video or audio:
1730 if( rObj
.mime
.indexOf('audio')!=-1 ||
1731 rObj
.mime
.indexOf('video')!=-1 ||
1732 rObj
.mime
.indexOf('/ogg') !=-1){
1733 mvJsLoader
.embedVideoCheck(function(){
1741 closeAll:function(){
1743 js_log("close all:: " + _this
.target_container
);
1744 _this
.cancelClipEditCB();
1745 $j(_this
.target_container
).dialog('close');
1747 setResultBarControl:function( ){
1749 var box_dark_url
= mv_skin_img_path
+ 'box_layout_icon_dark.png';
1750 var box_light_url
= mv_skin_img_path
+ 'box_layout_icon.png';
1751 var list_dark_url
= mv_skin_img_path
+ 'list_layout_icon_dark.png';
1752 var list_light_url
= mv_skin_img_path
+ 'list_layout_icon.png';
1755 if( this.content_providers
[this.disp_item
] ){
1756 var cp
= this.content_providers
[this.disp_item
];
1757 about_desc
='<span style="position:relative;top:0px;font-style:italic;">' +
1758 '<i>' + gM('mwe-results_from', [cp
.homepage
, cp
.title
]) + '</i></span>';
1759 $j('#tab-'+this.disp_item
).append( '<div id="rds_results_bar">'+
1760 '<span style="float:left;top:0px;font-style:italic;">'+
1761 gM('rsd_layout')+' '+
1762 '<img id="msc_box_layout" ' +
1763 'title = "' + gM('rsd_box_layout') + '" '+
1764 'src = "' + ( (_this
.result_display_mode
=='box')?box_dark_url
:box_light_url
) + '" ' +
1765 'style="width:20px;height:20px;cursor:pointer;"> ' +
1766 '<img id="msc_list_layout" '+
1767 'title = "' + gM('rsd_list_layout') + '" '+
1768 'src = "' + ( (_this
.result_display_mode
=='list')?list_dark_url
:list_light_url
) + '" '+
1769 'style="width:20px;height:20px;cursor:pointer;">'+
1772 '<span id="rsd_paging_ctrl" style="float:right;"></span>'+
1775 //get paging with bindings:
1776 this.getPaging('#rsd_paging_ctrl');
1778 $j('#msc_box_layout').hover(function(){
1779 $j(this).attr("src", box_dark_url
);
1781 $j(this).attr("src", ( (_this
.result_display_mode
=='box')?box_dark_url
:box_light_url
) );
1782 }).click(function(){
1783 $j(this).attr("src", box_dark_url
);
1784 $j('#msc_list_layout').attr("src", list_light_url
);
1785 _this
.setDispMode('box');
1788 $j('#msc_list_layout').hover(function(){
1789 $j(this).attr("src", list_dark_url
);
1791 $j(this).attr("src", ( (_this
.result_display_mode
=='list')?list_dark_url
:list_light_url
) );
1792 }).click(function(){
1793 $j(this).attr("src", list_dark_url
);
1794 $j('#msc_box_layout').attr("src", box_light_url
);
1795 _this
.setDispMode('list');
1799 getPaging:function(target
){
1801 var cp_id
= this.disp_item
;
1802 if( this.disp_item
== 'upload'){
1803 var cp
= _this
.content_providers
['this_wiki'];
1805 var cp
= this.content_providers
[ this.disp_item
];
1807 //js_log('getPaging:'+ cp_id + ' len: ' + cp.sObj.num_results);
1808 var to_num
= ( cp
.limit
> cp
.sObj
.num_results
)?
1809 (cp
.offset
+ cp
.sObj
.num_results
):
1810 (cp
.offset
+ cp
.limit
);
1811 var out
= gM('rsd_results_desc') + ' ' + (cp
.offset
+1) + ' to ' + to_num
;
1812 //check if we have more results (next prev link)
1813 if( cp
.offset
>= cp
.limit
)
1814 out
+=' <a href="#" id="rsd_pprev">' + gM('rsd_results_prev') + ' ' + cp
.limit
+ '</a>';
1816 if( cp
.sObj
.more_results
)
1817 out
+=' <a href="#" id="rsd_pnext">' + gM('rsd_results_next') + ' ' + cp
.limit
+ '</a>';
1819 $j(target
).html(out
);
1821 $j('#rsd_pnext').click(function(){
1822 cp
.offset
+= cp
.limit
;
1825 $j('#rsd_pprev').click(function(){
1826 cp
.offset
-= cp
.limit
;
1835 selectTab:function( selected_cp_id
){
1836 js_log('select tab: ' + selected_cp_id
);
1837 this.disp_item
= selected_cp_id
;
1838 if( this.disp_item
== 'upload' ){
1839 this.doUploadInteface();
1841 //update the search results:
1845 setDispMode:function(mode
){
1846 js_log('setDispMode:' + mode
);
1847 this.result_display_mode
=mode
;
1848 //run /update search display:
1849 this.drawOutputResults();