r59439 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59438‎ | r59439 | r59440 >
Date:03:10, 26 November 2009
Author:tstarling
Status:deferred (Comments)
Tags:
Comment:
Fixes for remoteSearchDriver.js and related. Untested, probably doesn't work. Somewhat less complete than r59278, I haven't done the comments and some bad variable names remain.

* Fixed multiple occurrences of </br> where <br/> was meant
* Made getSelection() into an accessor for this.caret_pos
* Split getTexboxSelection() into three accessors
* Merged init_interface_bindings() with initDialog()
* Split off showUploadForm_internal() from showUploadForm()
* Moved the upload check in showSearchTab() to its own function showCurrentTab()
* Moved the result display section of waitForResults() to a callback
* Removed the instance_name hack
* Fixed unanchored regex /res_/
* Split doMediaEdit() into showImageEditor() and showVideoEditor()
* Fixed unanchored regex /File:|Image:/
* Split updatePreviewText() into accessors getPreviewText() and getEmbedCode()
* Moved the doImportInterface() call from checkPrefixNameImport() to the checkImportResource() caller
* Use consistent spelling for "license"

Promoted anonymous functions to methods:
* getUploadForm_internal
* getResultHtml

Renamed functions:
* getlicenseImgSet -> getLicenseIconHtml
* setDispMode -> setDisplayMode
* getParsedWikiText -> parse
* init_modal -> createDialogContainer
* init_interface_html -> initDialog
* doUploadInteface -> showUploadTab
* getUploadForm -> showUploadForm
* runSearch -> showSearchTab
* checkResultsDone -> waitForResults
* drawOutputResults -> showResults
* loadHQImg -> loadHighQualityImage
* resourceEdit -> showResourceEditor
* cancelClipEditCB -> onCancelClipEdit
* checkRepoLocal -> isProviderLocal
* checkForFile -> findFileInLocalWiki
* checkImportResource -> isFileLocallyAvailable
* checkPrefixNameImport -> isFileAlreadyImported
* doImportInterface -> showImportUI
* doImportAPI -> doApiImport
* previewResource -> showPreview
* getResourceObjet -> getResourceObject
Modified paths:
  • /trunk/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/archiveOrgSearch.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/flickrSearch.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/metavidSearch.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/simpleUploadForm.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libSequencer/mvSequencer.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/mv_embed.js (modified) (history)

Diff [purge]

Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js
@@ -5,7 +5,7 @@
66 loadGM( {
77 "mwe-imported_from" : "$1 imported from [$2 $3]. See the original [$4 resource page] for more information.",
88 "mwe-import-description" : "$1, imported from $2"
9 -} )
 9+} );
1010
1111 /*
1212 * rsd_default_rss_item_mapping
@@ -33,7 +33,7 @@
3434 'desc' : 'description',
3535 // multiple items
3636 'category' : '.media:category@label|url'
37 -}
 37+};
3838
3939 var baseRemoteSearch = function( iObj ) {
4040 return this.init( iObj );
@@ -114,6 +114,10 @@
115115 // Add pointer to parent search obj:( this.cp.limit )? this.cp.limit : this.limit,
116116
117117 rObj['pSobj'] = _this;
 118+
 119+ // Set target_resource_title
 120+ _this.updateTargetResourceTitle( rObj );
 121+
118122 // add the result to the result set:
119123 _this.resultsObj[ inx ] = rObj;
120124 _this.num_results++;
@@ -283,7 +287,7 @@
284288 return '';
285289 },
286290 /**
287 - * Get the licence wikiText tag for a given resource Object.
 291+ * Get the license wikiText tag for a given resource Object.
288292 *
289293 * By default license permission wiki text is cc based template mapping
290294 * (does not confirm the templates actually exist)
@@ -370,7 +374,7 @@
371375 * Updates / normalizes the target_resource_title
372376 */
373377 updateTargetResourceTitle:function( rObj ) {
374 - rObj.target_resource_title = rObj.titleKey.replace( / File: | Image: / , '' );
 378+ rObj.target_resource_title = rObj.titleKey.replace( /^(File:|Image:)/ , '' );
375379 rObj.target_resource_title = this.cp.resource_prefix + rObj.target_resource_title;
376380 }
377381 }
Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/archiveOrgSearch.js
@@ -83,7 +83,7 @@
8484 'src' : _this.downloadUrl + resource.identifier + '/format=Ogg+video',
8585 'mime' : 'application/ogg',
8686 // Set the license: (rsd is a pointer to the parent remoteSearchDriver )
87 - 'license' : this.rsd.getLicenceFromUrl( resource.licenseurl ),
 87+ 'license' : this.rsd.getLicenseFromUrl( resource.licenseurl ),
8888 'pSobj' :_this
8989
9090 };
@@ -127,4 +127,4 @@
128128 return '<video ' + id_attr + ' src="' + src + '" poster="' + rObj.poster + '" type="video/ogg"></video>';
129129 }
130130 }
131 -}
\ No newline at end of file
 131+}
Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/metavidSearch.js
@@ -66,7 +66,7 @@
6767 rObj['stream_name'] = proe.queryKey['stream_name'];
6868
6969 // All metavid content is public domain:
70 - rObj['license'] = _this.rsd.getLicenceFromKey( 'pd' );
 70+ rObj['license'] = _this.rsd.getLicenseFromKey( 'pd' );
7171
7272 // Transform the title into a wiki_safe title:
7373 rObj['titleKey'] = _this.getTitleKey( rObj );
Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/flickrSearch.js
@@ -19,10 +19,10 @@
2020 dtUrl : 'http://www.flickr.com/photos/',
2121 // @@todo probably would be good to read the api-key from configuration
2222 apikey : '2867787a545cc66c0bce6f2e57aca1d1',
23 - // What licence we are interested in
24 - _licence_keys: '4,5,7,8',
 23+ // What license we are interested in
 24+ _license_keys: '4,5,7,8',
2525 _srctypes: ['t', 'sq', 's', 'm', 'o'],
26 - licenceMap: {
 26+ licenseMap: {
2727 '4' : 'http://creativecommons.org/licenses/by/3.0/',
2828 '5' : 'http://creativecommons.org/licenses/by-sa/3.0/',
2929 '7' : 'http://www.flickr.com/commons/usage/',
@@ -53,7 +53,7 @@
5454 var reqObj = {
5555 'method':'flickr.photos.search',
5656 'format':'json',
57 - 'license':this._licence_keys,
 57+ 'license':this._license_keys,
5858 'api_key':this.apikey,
5959 'per_page': this.cp.limit,
6060 'page' : this.cp.offset,
@@ -82,7 +82,7 @@
8383 }
8484 for ( var resource_id in data.photos.photo ) {
8585 var sourceResource = data.photos.photo[ resource_id ];
86 - var rObj = _this.getResourceObjet( sourceResource );
 86+ var rObj = _this.getResourceObject( sourceResource );
8787 _this.resultsObj[ resource_id ] = rObj;
8888 }
8989 }
@@ -90,7 +90,7 @@
9191 /**
9292 * Gets an individual resource object from a given source Resource
9393 */
94 - getResourceObjet: function( resource ){
 94+ getResourceObject: function( resource ){
9595 var _this = this;
9696 var rObj = {
9797 'titleKey' : resource.title + '.jpg',
@@ -101,7 +101,7 @@
102102 'thumbheight': resource.height_t,
103103 'desc' : resource.title,
104104 // Set the license
105 - 'license' : this.rsd.getLicenceFromUrl( _this.licenceMap[ resource.license ] ),
 105+ 'license' : this.rsd.getLicenceFromUrl( _this.licenseMap[ resource.license ] ),
106106 'pSobj' : _this,
107107 // Assume image/jpeg for flickr response
108108 'mime' : 'image/jpeg'
@@ -169,4 +169,4 @@
170170 return 's';
171171
172172 }
173 -}
\ No newline at end of file
 173+}
Index: trunk/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js
@@ -1,6 +1,6 @@
22 /*
33 * remoteSearchDriver
4 - * Provides a base interface for the Add-Media-Wizard
 4+ * Provides a base interface for the Add-Media-Wizard
55 * supporting remote searching of http archives for free images/audio/video assets
66 */
77
@@ -51,60 +51,59 @@
5252 "mwe-ftype-oga" : "Ogg audio file",
5353 "mwe-ftype-ogg" : "Ogg video file",
5454 "mwe-ftype-unk" : "Unknown file format",
55 -
 55+
5656 "rsd-wiki_commons-title": "Wikimedia Commons",
5757 "rsd-wiki_commons": "Wikimedia Commons, an archive of freely-licensed educational media content (images, sound and video clips)",
58 -
 58+
5959 "rsd-this_wiki-title" : "This wiki",
6060 "rsd-this_wiki-desc" : "The local wiki install",
61 -
 61+
6262 "rsd-archive_org-title": "Archive.org",
6363 "rsd-archive_org-desc" : "The Internet Archive, a digital library of cultural artifacts",
64 -
 64+
6565 "rsd-flickr-title" : "Flickr.com",
6666 "rsd-flickr-desc" : "Flickr.com, a online photo sharing site",
6767 "rsd-metavid-title" : "Metavid.org",
6868 "rsd-metavid-desc" : "Metavid.org, a community archive of US House and Senate floor proceedings"
69 -
 69+
7070 } );
7171
7272 var default_remote_search_options = {
73 - 'profile':'mediawiki_edit',
74 - 'target_container':null, // the div that will hold the search interface
 73+ 'profile': 'mediawiki_edit',
 74+ 'target_container': null, // the div that will hold the search interface
7575
76 - 'target_invocation': null, // the button or link that will invoke the search interface
 76+ 'target_invoke_button': null, // the button or link that will invoke the search interface
7777
78 - 'default_provider_id':'all', // all or one of the content_providers ids
 78+ 'default_provider_id': 'all', // all or one of the content_providers ids
7979
80 - 'caret_pos':null,
81 - 'local_wiki_api_url':null,
 80+ 'local_wiki_api_url': null,
8281
8382 // Can be 'api', 'autodetect', 'remote_link'
8483 'import_url_mode': 'api',
8584
86 - 'target_title':null,
87 -
 85+ 'target_title': null,
 86+
8887 // Edit tools (can be an array of tools or keyword 'all')
89 - 'enabled_tools' : 'all',
90 -
 88+ 'enabled_tools': 'all',
9189
92 - 'target_textbox':null,
 90+
 91+ 'target_textbox': null,
9392 'target_render_area': null, // where output render should go:
9493 'instance_name': null, // a globally accessible callback instance name
95 - 'default_query':null, // default search query
 94+ 'default_query': null, // default search query
9695
9796 // Specific to sequence profile
98 - 'p_seq':null,
99 - 'cFileNS':'File', // What is the canonical namespace prefix for images
100 - // @@todo (should get that from the api or in-page vars)
 97+ 'p_seq': null,
 98+ 'cFileNS': 'File', // What is the canonical namespace prefix for images
 99+ // @@todo (should get that from the api or in-page vars)
101100
102101 'upload_api_target': 'local', // can be local or the url or remote
103 - 'upload_api_name' : null,
 102+ 'upload_api_name': null,
104103 'upload_api_proxy_frame': null, // a page that will request mw.proxy.server
105104
106 - 'enabled_cps':'all', // can be keyword 'all' or an array of enabled content provider keys
 105+ 'enabled_providers': 'all', // can be keyword 'all' or an array of enabled content provider keys
107106
108 - 'disp_item':null // sets the default display item:
 107+ 'currentProvider': null // sets the default display item:
109108 }
110109
111110 if ( typeof wgServer == 'undefined' )
@@ -115,14 +114,20 @@
116115 stylepath = '';
117116
118117 /*
119 - * Base remoteSearch Driver interface
 118+ * Base remoteSearch Driver interface
120119 */
121120 var remoteSearchDriver = function( iObj ) {
122121 return this.init( iObj );
123122 }
 123+
124124 remoteSearchDriver.prototype = {
125 - results_cleared:false,
 125+ results_cleared: false,
 126+
 127+ caretPos: null, // lazy initialised
 128+ textboxValue: null, // lazy initialised
 129+
126130 // here we define the set of possible media content providers:
 131+ // FIXME: unused
127132 main_search_options: {
128133 'selprovider': {
129134 'title': 'Select Providers'
@@ -131,6 +136,7 @@
132137 'title': 'Advanced Options'
133138 }
134139 },
 140+
135141 /** the default content providers list.
136142 *
137143 * (should be note that special tabs like "upload" and "combined" don't go into the content providers list:
@@ -145,15 +151,15 @@
146152
147153 @enabled: whether the search provider can be selected
148154 @checked: whether the search provider will show up as selectable tab
149 - @d: default: if the current cp should be displayed (only one should be the default)
150 - @title: the title of the search provider
151 - @desc: can use html
 155+ @default: default: if the current cp should be displayed (only one should be the default)
 156+ @title: the title of the search provider
 157+ @desc: can use html
152158 @api_url: the url to query against given the library type:
153 - @lib: the search library to use corresponding to the
154 - search object ie: 'mediaWiki' = new mediaWikiSearchSearch()
 159+ @lib: the search library to use corresponding to the
 160+ search object ie: 'mediaWiki' = new mediaWikiSearchSearch()
155161 @tab_img: the tab image (if set to false use title text)
156 - if === "ture" use standard location skin/images/{cp_id}_tab.png
157 - if === string use as url for image
 162+ if === "true" use standard location skin/images/{cp_id}_tab.png
 163+ if === string use as url for image
158164
159165 @linkback_icon default is: /wiki/skins/common/images/magnify-clip.png
160166
@@ -162,160 +168,85 @@
163169 @local_domains : sets of domains for which the content is local
164170 //@@todo should query wgForeignFileRepos setting maybe interwikimap from the api
165171 */
166 -
 172+
167173 'this_wiki': {
168174 'enabled': 1,
169175 'checked': 1,
170 - 'api_url': ( wgServer && wgScriptPath ) ? wgServer + wgScriptPath + '/api.php': null,
171 - 'lib' : 'mediaWiki',
172 - 'local' : true,
 176+ 'api_url': ( wgServer && wgScriptPath ) ?
 177+ wgServer + wgScriptPath + '/api.php' : null,
 178+ 'lib': 'mediaWiki',
 179+ 'local': true,
173180 'tab_img': false
174181 },
175182 'wiki_commons': {
176183 'enabled': 1,
177184 'checked': 1,
178185 'homepage': 'http://commons.wikimedia.org/wiki/Main_Page',
179 - 'api_url':'http://commons.wikimedia.org/w/api.php',
180 - 'lib' :'mediaWiki',
 186+ 'api_url': 'http://commons.wikimedia.org/w/api.php',
 187+ 'lib': 'mediaWiki',
181188 'resource_prefix': 'WC_', // prefix on imported resources (not applicable if the repository is local)
182189
183190 // if we should check for shared repository asset ( generally only applicable to commons )
184 - 'check_shared':true,
 191+ 'check_shared': true,
185192
186193 // list all the domains where commons is local?
187194 // probably should set this some other way by doing an api query
188195 // or by seeding this config when calling the remote search?
189 - 'local_domains': ['wikimedia', 'wikipedia', 'wikibooks'],
 196+ 'local_domains': [ 'wikimedia', 'wikipedia', 'wikibooks' ],
190197 // specific to wiki commons config:
191 - 'search_title':false, // disable title search
192 - 'tab_img':true
 198+ 'search_title': false, // disable title search
 199+ 'tab_img': true
193200 },
194201 'archive_org': {
195 - 'enabled':1,
196 - 'checked':1,
197 - 'homepage':'http://www.archive.org/about/about.php',
 202+ 'enabled': 1,
 203+ 'checked': 1,
 204+ 'homepage': 'http://www.archive.org/about/about.php',
198205
199 - 'api_url':'http://homeserver7.us.archive.org:8983/solr/select',
200 - 'lib' : 'archiveOrg',
201 - 'local' : false,
 206+ 'api_url': 'http://homeserver7.us.archive.org:8983/solr/select',
 207+ 'lib': 'archiveOrg',
 208+ 'local': false,
202209 'resource_prefix': 'AO_',
203 - 'tab_img':true
 210+ 'tab_img': true
204211 },
205212 'flickr': {
206 - 'enabled':1,
207 - 'checked':1,
208 - 'homepage':'http://www.flickr.com/about/',
 213+ 'enabled': 1,
 214+ 'checked': 1,
 215+ 'homepage': 'http://www.flickr.com/about/',
209216
210 - 'api_url':'http://www.flickr.com/services/rest/',
211 - 'lib' : 'flickr',
212 - 'local' : false,
213 - // Just prefix with Flickr_ for now.
 217+ 'api_url': 'http://www.flickr.com/services/rest/',
 218+ 'lib': 'flickr',
 219+ 'local': false,
 220+ // Just prefix with Flickr_ for now.
214221 'resource_prefix': 'Flickr_',
215 - 'tab_img':true
 222+ 'tab_img': true
216223 },
217224 'metavid': {
218 - 'enabled' : 1,
219 - 'checked' : 1,
220 - 'homepage':'http://metavid.org/wiki/Metavid_Overview',
221 - 'api_url':'http://metavid.org/w/index.php?title=Special:MvExportSearch',
222 - 'lib' : 'metavid',
223 - 'local' :false, // if local set to true we can use local
 225+ 'enabled': 1,
 226+ 'checked': 1,
 227+ 'homepage': 'http://metavid.org/wiki/Metavid_Overview',
 228+ 'api_url': 'http://metavid.org/w/index.php?title=Special:MvExportSearch',
 229+ 'lib': 'metavid',
 230+ 'local': false, // if local set to true we can use local
224231 'resource_prefix': 'MV_', // what prefix to use on imported resources
225232
226233 'local_domains': ['metavid'], // if the domain name contains metavid
227 - // no need to import metavid content to metavid sites
 234+ // no need to import metavid content to metavid sites
228235
229236 'stream_import_key': 'mv_ogg_low_quality', // which stream to import, could be mv_ogg_high_quality
230 - // or flash stream, see ROE xml for keys
 237+ // or flash stream, see ROE xml for keys
231238
232239 'remote_embed_ext': false, // if running the remoteEmbed extension no need to copy local
233 - // syntax will be [remoteEmbed:roe_url link title]
234 - 'tab_img':true
 240+ // syntax will be [remoteEmbed:roe_url link title]
 241+ 'tab_img': true
235242 },
236243 // special cp "upload"
237244 'upload': {
238 - 'enabled':1,
239 - 'checked':1,
240 - 'title' :'Upload'
 245+ 'enabled': 1,
 246+ 'checked': 1,
 247+ 'title': 'Upload'
241248 }
242249 },
243 - // some default layout values:
244 - thumb_width : 80,
245 - image_edit_width : 400,
246 - video_edit_width : 400,
247 - insert_text_pos : 0, // insert at the start (will be overwritten by the user cursor pos)
248 - result_display_mode : 'box', // box or list
249250
250 - cUpLoader : null,
251 - cEdit : null,
252 - proxySetupDone : null,
253 - dmodalCss : { },
254 -
255 - init: function( options ) {
256 - var _this = this;
257 - js_log( 'remoteSearchDriver:init' );
258 - //add in a local "id" refrence top each cp:
259 - for(var cp_id in this.content_providers){
260 - this.content_providers[ cp_id ].id = cp_id;
261 - }
262 -
263 - // merge in the options:
264 - // @@todo for cleaner config we should set _this.opt to the provided options)
265 - $j.extend( _this, default_remote_search_options, options );
266 -
267 - // Quick fix for cases where people put ['all'] instead of 'all' for enabled_cps
268 - if ( _this.enabled_cps.length == 1 && _this.enabled_cps[0] == 'all' )
269 - _this.enabled_cps = 'all';
270 -
271 - // modify the content provider config based on options:
272 - for ( var i in this.content_providers ) {
273 - if ( _this.enabled_cps == 'all' && !this.disp_item ) {
274 - this.disp_item = i;
275 - // end the for loop (no need to idorate if enabled_cps == 'all'
276 - break;
277 - } else {
278 - if ( $j.inArray( i, _this.enabled_cps ) != -1 ) {
279 - // if no default display set to first enabled cp:
280 - if ( !this.disp_item )
281 - this.disp_item = i;
282 - this.content_providers[i].enabled = true;
283 - } else {
284 - if ( _this.enabled_cps != 'all' ) {
285 - this.content_providers[i].enabled = false;
286 - }
287 - }
288 - }
289 - }
290 -
291 - // set the upload target name if unset
292 - if ( _this.upload_api_target == 'local' && ! _this.upload_api_name && typeof wgSiteName != 'undefined' )
293 - _this.upload_api_name = wgSiteName;
294 -
295 - // if the upload_api_proxy_frame is set _this.upload_api_target to "proxy"
296 - if ( _this.upload_api_proxy_frame )
297 - _this.upload_api_target = 'proxy';
298 -
299 - // map "local" to the local api
300 - if ( _this.upload_api_target == 'local' ) {
301 - if ( ! _this.local_wiki_api_url ) {
302 - $j( '#tab-upload' ).html( gM( 'rsd_config_error', 'missing_local_api_url' ) );
303 - return false;
304 - } else {
305 - _this.upload_api_target = _this.local_wiki_api_url;
306 - }
307 - }
308 -
309 - // set up the target invocation:
310 - if ( $j( this.target_invocation ).length == 0 ) {
311 - js_log( "RemoteSearchDriver:: no target invocation provided (will have to run your own doInitDisplay() )" );
312 - } else {
313 - if ( this.target_invocation ) {
314 - $j( this.target_invocation ).css( 'cursor', 'pointer' ).attr( 'title', gM( 'mwe-add_media_wizard' ) ).click( function() {
315 - _this.doInitDisplay();
316 - } );
317 - }
318 - }
319 - },
320251 // define the licenses
321252 // ... this will get complicated quick...
322253 // (just look at complexity for creative commons without excessive "duplicate data")
@@ -331,7 +262,7 @@
332263 'cc': {
333264 'base_img_url':'http://upload.wikimedia.org/wikipedia/commons/thumb/',
334265 'base_license_url': 'http://creativecommons.org/licenses/',
335 - 'licenses':[
 266+ 'licenses': [
336267 'by',
337268 'by-sa',
338269 'by-nc-nd',
@@ -341,377 +272,541 @@
342273 'by-sa',
343274 'pd'
344275 ],
345 - 'license_img': {
 276+ 'license_images': {
346277 'by': {
347 - 'im':'1/11/Cc-by_new_white.svg/20px-Cc-by_new_white.svg.png'
 278+ 'image_url': '1/11/Cc-by_new_white.svg/20px-Cc-by_new_white.svg.png'
348279 },
349280 'nc': {
350 - 'im':'2/2f/Cc-nc_white.svg/20px-Cc-nc_white.svg.png'
 281+ 'image_url': '2/2f/Cc-nc_white.svg/20px-Cc-nc_white.svg.png'
351282 },
352283 'nd': {
353 - 'im':'b/b3/Cc-nd_white.svg/20px-Cc-nd_white.svg.png'
 284+ 'image_url': 'b/b3/Cc-nd_white.svg/20px-Cc-nd_white.svg.png'
354285 },
355286 'sa': {
356 - 'im':'d/df/Cc-sa_white.svg/20px-Cc-sa_white.svg.png'
 287+ 'image_url': 'd/df/Cc-sa_white.svg/20px-Cc-sa_white.svg.png'
357288 },
358289 'pd': {
359 - 'im':'5/51/Cc-pd-new_white.svg/20px-Cc-pd-new_white.svg.png'
 290+ 'image_url': '5/51/Cc-pd-new_white.svg/20px-Cc-pd-new_white.svg.png'
360291 }
361292 }
362293 }
363294 },
 295+
 296+ // some default layout values:
 297+ thumb_width: 80,
 298+ image_edit_width: 400,
 299+ video_edit_width: 400,
 300+ insert_text_pos: 0, // insert at the start (will be overwritten by the user cursor pos)
 301+ displayMode : 'box', // box or list
 302+
 303+ cUpLoader: null,
 304+ clipEdit: null,
 305+ proxySetupDone: null,
 306+ dmodalCss: {},
 307+
 308+ init: function( options ) {
 309+ var _this = this;
 310+ js_log( 'remoteSearchDriver:init' );
 311+ // Add in a local "id" reference to each provider
 312+ for ( var cp_id in this.content_providers ) {
 313+ this.content_providers[ cp_id ].id = cp_id;
 314+ }
 315+
 316+ // Merge in the options
 317+ // @@todo for cleaner config we should set _this.opt to the provided options
 318+ $j.extend( _this, default_remote_search_options, options );
 319+
 320+ // Quick fix for cases where people put ['all'] instead of 'all' for enabled_providers
 321+ if ( _this.enabled_providers.length == 1 && _this.enabled_providers[0] == 'all' )
 322+ _this.enabled_providers = 'all';
 323+
 324+ // Set up content_providers
 325+ for ( var provider in this.content_providers ) {
 326+ if ( _this.enabled_providers == 'all' && !this.currentProvider ) {
 327+ this.currentProvider = provider;
 328+ break;
 329+ } else {
 330+ if ( $j.inArray( provider, _this.enabled_providers ) != -1 ) {
 331+ // This provider is enabled
 332+ this.content_providers[provider].enabled = true;
 333+ // Set the current provider to the first enabled one
 334+ if ( !this.currentProvider ) {
 335+ this.currentProvider = provider;
 336+ }
 337+ } else {
 338+ // This provider is disabled
 339+ if ( _this.enabled_providers != 'all' ) {
 340+ this.content_providers[provider].enabled = false;
 341+ }
 342+ }
 343+ }
 344+ }
 345+
 346+ // Set the upload target name if unset
 347+ if ( _this.upload_api_target == 'local'
 348+ && ! _this.upload_api_name
 349+ && typeof wgSiteName != 'undefined' )
 350+ {
 351+ _this.upload_api_name = wgSiteName;
 352+ }
 353+
 354+ // Set the target to "proxy" if a proxy frame is configured
 355+ if ( _this.upload_api_proxy_frame )
 356+ _this.upload_api_target = 'proxy';
 357+
 358+ // Set up the local API upload URL
 359+ if ( _this.upload_api_target == 'local' ) {
 360+ if ( ! _this.local_wiki_api_url ) {
 361+ $j( '#tab-upload' ).html( gM( 'rsd_config_error', 'missing_local_api_url' ) );
 362+ return false;
 363+ } else {
 364+ _this.upload_api_target = _this.local_wiki_api_url;
 365+ }
 366+ }
 367+
 368+ // Set up the "add media wizard" button, which invokes this object
 369+ if ( $j( this.target_invoke_button ).length == 0 ) {
 370+ js_log( "RemoteSearchDriver:: no target invocation provided " +
 371+ "(will have to run your own createUI() )" );
 372+ } else {
 373+ if ( this.target_invoke_button ) {
 374+ $j( this.target_invoke_button )
 375+ .css( 'cursor', 'pointer' )
 376+ .attr( 'title', gM( 'mwe-add_media_wizard' ) )
 377+ .click( function() {
 378+ _this.createUI();
 379+ } );
 380+ }
 381+ }
 382+ },
 383+
364384 /*
365 - * getlicenseImgSet
 385+ * getLicenseIconHtml
366386 * @param license_key the license key (ie "by-sa" or "by-nc-sa" etc)
367387 */
368 - getlicenseImgSet: function( licenseObj ) {
 388+ getLicenseIconHtml: function( licenseObj ) {
369389 // js_log('output images: '+ imgs);
370390 return '<div class="rsd_license" title="' + licenseObj.title + '" >' +
371 - '<a target="_new" href="' + licenseObj.lurl + '" ' +
372 - 'title="' + licenseObj.title + '">' +
373 - licenseObj.img_html +
374 - '</a>' +
375 - '</div>';
 391+ '<a target="_new" href="' + licenseObj.lurl + '" ' +
 392+ 'title="' + licenseObj.title + '">' +
 393+ licenseObj.img_html +
 394+ '</a>' +
 395+ '</div>';
376396 },
 397+
377398 /*
378 - * getLicenceKeyFromKey
 399+ * getLicenseKeyFromKey
379400 * @param license_key the key of the license (must be defined in: this.licenses.cc.licenses)
380401 */
381 - getLicenceFromKey:function( license_key , force_url ) {
 402+ getLicenseFromKey: function( license_key, force_url ) {
382403 // set the current license pointer:
383404 var cl = this.licenses.cc;
384405 var title = gM( 'mwe-cc_title' );
385406 var imgs = '';
386407 var license_set = license_key.split( '-' );
387408 for ( var i = 0; i < license_set.length; i++ ) {
388 - var lkey = license_set[i];
389 - if ( ! cl.license_img[ lkey ] ) {
 409+ var lkey = license_set[i];
 410+ if ( !cl.license_images[ lkey ] ) {
390411 js_log( "MISSING::" + lkey );
391412 }
392 -
 413+
393414 title += ' ' + gM( 'mwe-cc_' + lkey + '_title' );
394 - imgs += '<img class="license_desc" width="20" src="'
395 - + cl.base_img_url + cl.license_img[ lkey ].im + '">';
 415+ imgs += '<img class="license_desc" width="20" src="' +
 416+ cl.base_img_url + cl.license_images[ lkey ].image_url + '">';
396417 }
397418 var url = ( force_url ) ? force_url : cl.base_license_url + cl.licenses[ license_key ];
398419 return {
399 - 'title' : title,
400 - 'img_html' : imgs,
401 - 'key' : license_key,
402 - 'lurl' : url
 420+ 'title': title,
 421+ 'img_html': imgs,
 422+ 'key': license_key,
 423+ 'lurl': url
403424 };
404425 },
 426+
405427 /*
406 - * getLicenceKeyFromUrl
407 - * @param licence_url the url of the license
 428+ * getLicenseKeyFromUrl
 429+ * @param license_url the url of the license
408430 */
409 - getLicenceFromUrl: function( license_url ) {
 431+ getLicenseFromUrl: function( license_url ) {
410432 // check for some pre-defined url types:
411433 if ( license_url == 'http://www.usa.gov/copyright.shtml' ||
412434 license_url == 'http://creativecommons.org/licenses/publicdomain' )
413 - return this.getLicenceFromKey( 'pd' , license_url );
414 -
415 -
416 - // js_log("getLicenceFromUrl::" + license_url);
 435+ return this.getLicenseFromKey( 'pd' , license_url );
 436+
 437+
 438+ // js_log("getLicenseFromUrl::" + license_url);
417439 // first do a direct lookup check:
418440 for ( var j = 0; j < this.licenses.cc.licenses.length; j++ ) {
419441 var jL = this.licenses.cc.licenses[ j ];
420 - // special 'pd' case:
 442+ // special 'pd' case:
421443 if ( jL == 'pd' ) {
422444 var keyCheck = 'publicdomain';
423445 } else {
424446 var keyCheck = jL;
425447 }
426448 if ( mw.parseUri( license_url ).path.indexOf( '/' + keyCheck + '/' ) != -1 ) {
427 - return this.getLicenceFromKey( jL , license_url );
 449+ return this.getLicenseFromKey( jL , license_url );
428450 }
429 - };
 451+ }
430452 // Could not find it return mwe-unknown_license
431453 return {
432 - 'title' : gM( 'mwe-unknown_license' ),
433 - 'img_html' : '<span>' + gM( 'mwe-unknown_license' ) + '</span>',
434 - 'lurl' : license_url
 454+ 'title': gM( 'mwe-unknown_license' ),
 455+ 'img_html': '<span>' + gM( 'mwe-unknown_license' ) + '</span>',
 456+ 'lurl': license_url
435457 };
436458 },
 459+
437460 /**
438461 * getTypeIcon
439462 * @param str mime type of the requested file
440463 */
441 - getTypeIcon:function( mimetype ) {
 464+ getTypeIcon: function( mimetype ) {
442465 var typestr = 'unk';
443 - switch( mimetype ) {
 466+ switch ( mimetype ) {
444467 case 'image/svg+xml':
445468 typestr = 'svg';
446 - break;
 469+ break;
447470 case 'image/jpeg':
448471 typestr = 'jpg'
449 - break;
 472+ break;
450473 case 'image/png':
451474 typestr = 'png';
452 - break;
 475+ break;
453476 case 'audio/ogg':
454477 typestr = 'oga';
455478 case 'video/ogg':
456479 case 'application/ogg':
457480 typestr = 'ogg';
458 - break;
 481+ break;
459482 }
460 -
 483+
461484 if ( typestr == 'unk' ) {
462485 js_log( "unkown ftype: " + mimetype );
463486 return '';
464487 }
465 -
466 - return '<div class="rsd_file_type ui-corner-all ui-state-default ui-widget-content" title="' + gM( 'mwe-ftype-' + typestr ) + '">' +
467 - typestr +
468 - '</div>'
 488+
 489+ return '<div ' +
 490+ 'class="rsd_file_type ui-corner-all ui-state-default ui-widget-content" ' +
 491+ 'title="' + gM( 'mwe-ftype-' + typestr ) + '">' +
 492+ typestr +
 493+ '</div>';
469494 },
470 - doInitDisplay:function() {
 495+
 496+ createUI: function() {
471497 var _this = this;
472 -
473 - // try and get the text selection:
474 - _this.getTexboxSelection();
475 -
 498+
 499+ this.clearTextboxCache();
476500 // setup the parent container:
477 - this.init_modal();
 501+ this.createDialogContainer();
478502 // fill in the html:
479 - this.init_interface_html();
 503+ this.initDialog();
480504 // bind actions:
481505 this.add_interface_bindings();
482506
483507 // update the target binding to just un-hide the dialog:
484 - if ( this.target_invocation ) {
485 - $j( this.target_invocation ).unbind().click( function() {
486 - js_log( "doInitDisplay:target_invocation: click doReDisp" );
487 - _this.doReDisplay();
488 - } );
489 - }
 508+ if ( this.target_invoke_button ) {
 509+ $j( this.target_invoke_button )
 510+ .unbind()
 511+ .click( function() {
 512+ js_log( "createUI:target_invoke_button: click showDialog" );
 513+ _this.showDialog();
 514+ } );
 515+ }
490516 },
491 - doReDisplay: function() {
 517+
 518+ showDialog: function() {
492519 var _this = this;
493 - js_log( "doReDisplay::" );
494 - // update the base text:
495 - _this.getTexboxSelection();
496 - if ( _this.default_query != $j( '#rsd_q' ).val() ) {
497 - $j( '#rsd_q' ).val( _this.default_query );
498 - _this.runSearch();
 520+ js_log( "showDialog::" );
 521+ _this.clearTextboxCache();
 522+ var query = _this.getDefaultQuery();
 523+ if ( query != $j( '#rsd_q' ).val() ) {
 524+ $j( '#rsd_q' ).val( query );
 525+ _this.showCurrentTab();
499526 }
500527 // $j(_this.target_container).dialog("open");
501528 $j( _this.target_container ).parents( '.ui-dialog' ).fadeIn( 'slow' );
502529 // re-center the dialog:
503530 $j( _this.target_container ).dialog( 'option', 'position', 'center' );
504531 },
505 - // gets the in and out points for insert position or grabs the selected text for search
506 - getTexboxSelection:function() {
507 - if ( this.target_textbox ) {
508 - // get the selection text:
509 - var ts = $j( this.target_textbox ).textSelection();
510 - if ( ts != '' ) {
511 - this.default_query = ts;
 532+
 533+ clearTextboxCache: function() {
 534+ this.caretPos = null;
 535+ this.textboxValue = null;
 536+ this.default_query = null;
 537+ },
 538+
 539+ getCaretPos: function() {
 540+ if ( this.caretPos == null ) {
 541+ if ( this.target_textbox ) {
 542+ this.caretPos = $j( this.target_textbox ).getCaretPosition();
 543+ } else {
 544+ this.caretPos = false;
512545 }
513 - // get the caretPos / value
514 - this.caret_pos = { };
515 - this.caret_pos.text = $j( this.target_textbox ).val();
516 - this.caret_pos.s = $j( this.target_textbox ).getCaretPosition();
517546 }
 547+ return this.caretPos;
518548 },
519 - init_modal:function() {
520 - js_log( "init_modal" );
 549+
 550+ getTextboxValue: function() {
 551+ if ( this.textboxValue == null ) {
 552+ if ( this.target_textbox ) {
 553+ this.textboxValue = $j( this.target_textbox ).val();
 554+ } else {
 555+ this.textboxValue = '';
 556+ }
 557+ }
 558+ return this.textboxValue;
 559+ },
 560+
 561+ getDefaultQuery: function() {
 562+ if ( this.default_query == null ) {
 563+ if ( this.target_textbox ) {
 564+ var ts = $j( this.target_textbox ).textSelection();
 565+ if ( ts != '' ) {
 566+ this.default_query = ts;
 567+ } else {
 568+ this.default_query = '';
 569+ }
 570+ }
 571+ }
 572+ return this.default_query;
 573+ },
 574+
 575+ createDialogContainer: function() {
 576+ js_log( "createDialogContainer" );
521577 var _this = this;
522578 // add the parent target_container if not provided or missing
523 - if ( !_this.target_container || $j( _this.target_container ).length == 0 ) {
524 - _this.target_container = '#rsd_modal_target';
525 - $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>' );
526 - // js_log('appended: #rsd_modal_target' + $j(_this.target_container).attr('id'));
527 - // js_log('added target id:' + $j(_this.target_container).attr('id'));
528 - // get layout
529 - js_log( 'width: ' + $j( window ).width() + ' height: ' + $j( window ).height() );
530 - var cBtn = { };
531 - cBtn[ gM( 'mwe-cancel' ) ] = function() {
532 - _this.cancelClipEditCB();
 579+ if ( _this.target_container && $j( _this.target_container ).length != 0 ) {
 580+ js_log( 'dialog already exists' );
 581+ return;
 582+ }
 583+
 584+ _this.target_container = '#rsd_modal_target';
 585+ $j( 'body' ).append(
 586+ '<div ' +
 587+ 'id="rsd_modal_target" ' +
 588+ 'style="position:absolute;top:3em;left:0px;bottom:3em;right:0px;" ' +
 589+ 'title="' + gM( 'mwe-add_media_wizard' ) + '" >' +
 590+ '</div>' );
 591+ // js_log('appended: #rsd_modal_target' + $j(_this.target_container).attr('id'));
 592+ // js_log('added target id:' + $j(_this.target_container).attr('id'));
 593+ // get layout
 594+ js_log( 'width: ' + $j( window ).width() + ' height: ' + $j( window ).height() );
 595+ var cBtn = {};
 596+ cBtn[ gM( 'mwe-cancel' ) ] = function() {
 597+ _this.onCancelClipEdit();
 598+ }
 599+
 600+ $j( _this.target_container ).dialog( {
 601+ bgiframe: true,
 602+ autoOpen: true,
 603+ modal: true,
 604+ draggable: false,
 605+ resizable: false,
 606+ buttons: cBtn,
 607+ close: function() {
 608+ // if we are 'editing' a item close that
 609+ // @@todo maybe prompt the user?
 610+ _this.onCancelClipEdit();
 611+ $j( this ).parents( '.ui-dialog' ).fadeOut( 'slow' );
533612 }
534 -
535 - $j( _this.target_container ).dialog( {
536 - bgiframe: true,
537 - autoOpen: true,
538 - modal: true,
539 - draggable:false,
540 - resizable:false,
541 - buttons:cBtn,
542 - close: function() {
543 - // if we are 'editing' a item close that
544 - // @@todo maybe prompt the user?
545 - _this.cancelClipEditCB();
546 - $j( this ).parents( '.ui-dialog' ).fadeOut( 'slow' );
547 - }
548 - } );
 613+ } );
 614+ $j( _this.target_container ).dialogFitWindow();
 615+ $j( window ).resize( function() {
549616 $j( _this.target_container ).dialogFitWindow();
550 - $j( window ).resize( function() {
551 - $j( _this.target_container ).dialogFitWindow();
552 - } );
553 -
554 - // add cancel callback and updated button with icon
555 - _this.cancelClipEditCB();
556 - }
 617+ } );
 618+
 619+ // add cancel callback and updated button with icon
 620+ _this.onCancelClipEdit();
557621 },
 622+
558623 // sets up the initial html interface
559 - init_interface_html:function() {
560 - js_log( 'init_interface_html' );
 624+ initDialog: function() {
 625+ js_log( 'initDialog' );
561626 var _this = this;
562 - var dq = ( this.default_query ) ? this.default_query : '';
563 - js_log( 'f::init_interface_html' );
 627+ js_log( 'f::initDialog' );
564628
565629 var o = '<div class="rsd_control_container" style="width:100%">' +
566 - '<form id="rsd_form" action="javascript:return false;" method="GET">' +
567 - '<input class="ui-widget-content ui-corner-all" type="text" tabindex="1" value="' + dq + '" maxlength="512" id="rsd_q" name="rsd_q" ' +
568 - 'size="20" autocomplete="off" />' +
569 - $j.btnHtml( gM( 'mwe-media_search' ), 'rms_search_button', 'search' ) +
570 - '</form>';
 630+ '<form id="rsd_form" action="javascript:return false;" method="GET">' +
 631+ '<input ' +
 632+ 'class="ui-widget-content ui-corner-all" ' +
 633+ 'type="text" ' +
 634+ 'tabindex="1" ' +
 635+ 'value="' + this.getDefaultQuery() + '" ' +
 636+ 'maxlength="512" ' +
 637+ 'id="rsd_q" ' +
 638+ 'name="rsd_q" ' +
 639+ 'size="20" ' +
 640+ 'autocomplete="off" />' +
 641+ $j.btnHtml( gM( 'mwe-media_search' ), 'rms_search_button', 'search' ) +
 642+ '</form>';
571643 // close up the control container:
572644 o += '</div>';
573 -
 645+
574646 // search provider tabs based on "checked" and "enabled" and "combined tab"
575 - o += '<div id="rsd_results_container" style="top:0px;bottom:0px;left:0px;right:0px;"></div>';
 647+ o += '<div ' +
 648+ 'id="rsd_results_container" ' +
 649+ 'style="top:0px;bottom:0px;left:0px;right:0px;">' +
 650+ '</div>';
576651 $j( this.target_container ).html( o );
577652 // add simple styles:
578653 $j( this.target_container + ' .rms_search_button' ).btnBind().click( function() {
579 - _this.runSearch();
 654+ _this.showCurrentTab();
580655 } );
581656
582657 // draw the tabs:
583 - this.drawTabs();
 658+ this.createTabs();
584659 // run the default search:
585 - if ( this.default_query )
586 - this.runSearch();
587 - },
588 - add_interface_bindings:function() {
589 - var _this = this;
590 - js_log( "f:add_interface_bindings:" );
 660+ if ( this.getDefaultQuery() )
 661+ this.showCurrentTab();
591662
592 -
593 - $j( '#mso_selprovider,#mso_selprovider_close' ).unbind().click( function() {
594 - if ( $j( '#rsd_options_bar:hidden' ).length != 0 ) {
595 - $j( '#rsd_options_bar' ).animate( {
596 - 'height':'110px',
597 - 'opacity':1
598 - }, "normal" );
599 - } else {
600 - $j( '#rsd_options_bar' ).animate( {
601 - 'height':'0px',
602 - 'opacity':0
603 - }, "normal", function() {
604 - $j( this ).hide();
605 - } );
606 - }
607 - } );
 663+ // Add bindings
 664+ $j( '#mso_selprovider,#mso_selprovider_close' )
 665+ .unbind()
 666+ .click( function() {
 667+ if ( $j( '#rsd_options_bar:hidden' ).length != 0 ) {
 668+ $j( '#rsd_options_bar' ).animate( {
 669+ 'height': '110px',
 670+ 'opacity': 1
 671+ }, "normal" );
 672+ } else {
 673+ $j( '#rsd_options_bar' ).animate( {
 674+ 'height': '0px',
 675+ 'opacity': 0
 676+ }, "normal", function() {
 677+ $j( this ).hide();
 678+ } );
 679+ }
 680+ } );
608681 // set form bindings
609 - $j( '#rsd_form' ).unbind().submit( function() {
610 - _this.runSearch();
611 - // don't submit the form
612 - return false;
613 - } );
 682+ $j( '#rsd_form' )
 683+ .unbind()
 684+ .submit( function() {
 685+ _this.showCurrentTab();
 686+ // don't submit the form
 687+ return false;
 688+ } );
614689 },
615 - doUploadInteface:function() {
616 - js_log( "doUploadInteface::" );
 690+
 691+ showUploadTab: function() {
 692+ js_log( "showUploadTab::" );
617693 var _this = this;
618694 // set it to loading:
619695 mv_set_loading( '#tab-upload' );
620696 // do things async to keep interface snappy
621 - setTimeout( function() {
622 - // check if we need to setup the proxy::
623 - if ( _this.upload_api_target == 'proxy' ) {
624 - _this.setupProxy( function() {
625 - _this.getUploadForm();
626 - } );
627 - } else {
628 - _this.getUploadForm();
629 - }
630 - }, 1 );
 697+ setTimeout(
 698+ function() {
 699+ // check if we need to setup the proxy::
 700+ if ( _this.upload_api_target == 'proxy' ) {
 701+ _this.setupProxy( function() {
 702+ _this.showUploadForm();
 703+ } );
 704+ } else {
 705+ _this.showUploadForm();
 706+ }
 707+ },
 708+ 1 );
631709 },
632 - getUploadForm:function() {
 710+
 711+ showUploadForm: function() {
633712 var _this = this;
634713 mvJsLoader.doLoad( ['$j.fn.simpleUploadForm'], function() {
635714 // get extends info about the file
636 - var cp = _this.content_providers['this_wiki'];
637 -
 715+ var provider = _this.content_providers['this_wiki'];
 716+
638717 // check for "this_wiki" enabled
639 - /*if(!cp.enabled){
640 - $j('#tab-upload').html('error this_wiki not enabled (can\'t get uploaded file info)');
 718+ /*if(!provider.enabled){
 719+ $j('#tab-upload')
 720+ .html('error this_wiki not enabled (can\'t get uploaded file info)');
641721 return false;
642722 }*/
643 -
644 - // load this_wiki search system to grab the rObj
645 - _this.loadSearchLib( cp, function() {
646 - // do basic layout form on left upload "bin" on right
647 - $j( '#tab-upload' ).html( '<table>' +
648 - '<tr>' +
649 - '<td valign="top" style="width:350px; padding-right: 12px;">' +
650 - '<h4>' + gM( 'mwe-upload_a_file', _this.upload_api_name ) + '</h4>' +
651 - '<div id="upload_form">' +
652 - mv_get_loading_img() +
653 - '</div>' +
654 - '</td>' +
655 - '<td valign="top" id="upload_bin_cnt">' +
656 - '<h4>' + gM( 'mwe-your_recent_uploads', _this.upload_api_name ) + '</h4>' +
657 - '<div id="upload_bin">' +
658 - mv_get_loading_img() +
659 - '</div>' +
660 - '</td>' +
661 - '</tr>' +
662 - '</table>' );
663 -
664 -
665 - // fill in the user page:
666 - if ( typeof wgUserName != 'undefined' && wgUserName ) {
667 - // load the upload bin with anything the current user has uploaded
668 - cp.sObj.getUserRecentUploads( wgUserName, function() {
669 - _this.drawOutputResults();
670 - } );
671 - } else {
672 - $j( '#upload_bin_cnt' ).empty();
673 - }
674 -
675 - // deal with the api form upload form directly:
676 - $j( '#upload_form' ).simpleUploadForm( {
677 - "api_target" : _this.upload_api_target,
678 - "ondone_cb" : function( resultData ) {
679 - var wTitle = resultData['filename'];
680 - // add a loading div
681 - _this.addResourceEditLoader();
682 - // @@note: we have most of what we need in resultData imageinfo
683 - cp.sObj.addByTitle( wTitle, function( rObj ) {
684 - // Redraw ( with added result if new )
685 - _this.drawOutputResults();
686 - // Pull up resource editor:
687 - _this.resourceEdit( rObj, $j( '#res_upload__' + rObj.id ).get( 0 ) );
688 - } );
689 - // Return false to close progress window:
690 - return false;
691 - }
 723+
 724+ // load this_wiki search system to grab the resource
 725+ _this.loadSearchLib( provider, function() {
 726+ _this.showUploadForm_internal( provider );
 727+ } );
 728+ } );
 729+ },
 730+
 731+ showUploadForm_internal: function( provider ) {
 732+ var _this = this;
 733+ var uploadMsg = gM( 'mwe-upload_a_file', _this.upload_api_name );
 734+ var recentUploadsMsg = gM( 'mwe-your_recent_uploads', _this.upload_api_name );
 735+ // do basic layout form on left upload "bin" on right
 736+ $j( '#tab-upload' ).html(
 737+ '<table>' +
 738+ '<tr>' +
 739+ '<td valign="top" style="width:350px; padding-right: 12px;">' +
 740+ '<h4>' + uploadMsg + '</h4>' +
 741+ '<div id="upload_form">' +
 742+ mv_get_loading_img() +
 743+ '</div>' +
 744+ '</td>' +
 745+ '<td valign="top" id="upload_bin_cnt">' +
 746+ '<h4>' + recentUploadsMsg + '</h4>' +
 747+ '<div id="upload_bin">' +
 748+ mv_get_loading_img() +
 749+ '</div>' +
 750+ '</td>' +
 751+ '</tr>' +
 752+ '</table>' );
 753+
 754+
 755+ // fill in the user page:
 756+ if ( typeof wgUserName != 'undefined' && wgUserName ) {
 757+ // load the upload bin with anything the current user has uploaded
 758+ provider.sObj.getUserRecentUploads( wgUserName, function() {
 759+ _this.showResults();
 760+ } );
 761+ } else {
 762+ $j( '#upload_bin_cnt' ).empty();
 763+ }
 764+
 765+ // deal with the api form upload form directly:
 766+ $j( '#upload_form' ).simpleUploadForm( {
 767+ "api_target" : _this.upload_api_target,
 768+ "ondone_cb": function( resultData ) {
 769+ var wTitle = resultData['filename'];
 770+ // add a loading div
 771+ _this.addResourceEditLoader();
 772+ // @@note: we have most of what we need in resultData imageinfo
 773+ provider.sObj.addByTitle( wTitle, function( resource ) {
 774+ // Redraw ( with added result if new )
 775+ _this.showResults();
 776+ // Pull up resource editor:
 777+ _this.showResourceEditor( resource, $j( '#res_upload__' + resource.id ).get( 0 ) );
692778 } );
693 - } ); // load searchLibs
694 - } ); // load simpleUploadForm
 779+ // Return false to close progress window:
 780+ return false;
 781+ }
 782+ } );
695783 },
696 - runSearch: function( restPage ) {
697 - js_log( "f:runSearch::" + this.disp_item );
698784
699 - var draw_direct_flag = true;
700 -
701 - // check if its the special upload tab case:
702 - if ( this.disp_item == 'upload' ) {
703 - this.doUploadInteface();
704 - return true;
 785+ showCurrentTab: function() {
 786+ if ( this.currentProvider == 'upload' ) {
 787+ this.showUploadTab();
 788+ } else {
 789+ this.showSearchTab( this.currentProvider, false );
705790 }
706 -
707 - // else do runSearch
708 - var cp = this.content_providers[this.disp_item];
 791+ }
709792
 793+ showSearchTab: function( providerName, resetPaging ) {
 794+ js_log( "f:showSearchTab::" + providerName );
 795+
 796+ var draw_direct_flag = true;
 797+
 798+ // else do showSearchTab
 799+ var provider = this.content_providers[providerName];
 800+
710801 // check if we need to update:
711 - if ( typeof cp.sObj != 'undefined' ) {
712 - if ( cp.sObj.last_query == $j( '#rsd_q' ).val() && cp.sObj.last_offset == cp.offset ) {
713 - js_log( 'last query is: ' + cp.sObj.last_query + ' matches: ' + $j( '#rsd_q' ).val() );
 802+ if ( typeof provider.sObj != 'undefined' ) {
 803+ if ( provider.sObj.last_query == $j( '#rsd_q' ).val()
 804+ && provider.sObj.last_offset == provider.offset )
 805+ {
 806+ js_log( 'last query is: ' + provider.sObj.last_query +
 807+ ' matches: ' + $j( '#rsd_q' ).val() );
714808 } else {
715 - js_log( 'last query is: ' + cp.sObj.last_query + ' not match: ' + $j( '#rsd_q' ).val() );
 809+ js_log( 'last query is: ' + provider.sObj.last_query +
 810+ ' not match: ' + $j( '#rsd_q' ).val() );
716811 draw_direct_flag = false;
717812 }
718813 } else {
@@ -719,23 +814,25 @@
720815 }
721816 if ( !draw_direct_flag ) {
722817 // see if we should reset the paging
723 - if ( restPage ) {
724 - cp.sObj.offset = cp.offset = 0;
 818+ if ( resetPaging ) {
 819+ provider.sObj.offset = provider.offset = 0;
725820 }
726 -
 821+
727822 // set the content to loading while we do the search:
728 - $j( '#tab-' + this.disp_item ).html( mv_get_loading_img() );
 823+ $j( '#tab-' + providerName ).html( mv_get_loading_img() );
729824
730825 // Make sure the search library is loaded and issue the search request
731 - this.getLibSearchResults( cp );
 826+ this.getLibSearchResults( provider );
732827 }
733828 },
 829+
734830 // Issue a api request & cache the result
735 - // this check can be avoided by setting the this.import_url_mode = 'api' | 'form' | instead of 'autodetect' or 'none'
736 - checkForCopyURLSupport:function ( callback ) {
 831+ // this check can be avoided by setting the
 832+ // this.import_url_mode = 'api' | 'form' | instead of 'autodetect' or 'none'
 833+ checkForCopyURLSupport: function ( callback ) {
737834 var _this = this;
738835 js_log( 'checkForCopyURLSupport:: ' );
739 -
 836+
740837 // See if we already have the import mode:
741838 if ( this.import_url_mode != 'autodetect' ) {
742839 js_log( 'import mode: ' + _this.import_url_mode );
@@ -748,117 +845,132 @@
749846 callback();
750847 }
751848 if ( this.import_url_mode == 'autodetect' ) {
752 - do_api_req( {
753 - 'url': _this.upload_api_target,
754 - 'data': {
755 - 'action':'paraminfo',
756 - 'modules':'upload'
757 - }
758 - }, function( data ) {
759 - // jump right into api checks:
760 - for ( var i in data.paraminfo.modules[0].parameters ) {
761 - var pname = data.paraminfo.modules[0].parameters[i].name;
762 - if ( pname == 'url' ) {
763 - js_log( 'Autodetect Upload Mode: api: copy by url:: ' );
764 - // check permission too:
765 - _this.checkForCopyURLPermission( function( canCopyUrl ) {
766 - if ( canCopyUrl ) {
767 - _this.import_url_mode = 'api';
768 - js_log( 'import mode: ' + _this.import_url_mode );
769 - callback();
770 - } else {
771 - _this.import_url_mode = 'none';
772 - js_log( 'import mode: ' + _this.import_url_mode );
773 - callback();
774 - }
775 - } );
776 - break;
 849+ do_api_req(
 850+ {
 851+ 'url': _this.upload_api_target,
 852+ 'data': {
 853+ 'action': 'paraminfo',
 854+ 'modules': 'upload'
777855 }
 856+ }, function( data ) {
 857+ // jump right into api checks:
 858+ for ( var i in data.paraminfo.modules[0].parameters ) {
 859+ var pname = data.paraminfo.modules[0].parameters[i].name;
 860+ if ( pname == 'url' ) {
 861+ js_log( 'Autodetect Upload Mode: api: copy by url:: ' );
 862+ // check permission too:
 863+ _this.checkForCopyURLPermission( function( canCopyUrl ) {
 864+ if ( canCopyUrl ) {
 865+ _this.import_url_mode = 'api';
 866+ js_log( 'import mode: ' + _this.import_url_mode );
 867+ callback();
 868+ } else {
 869+ _this.import_url_mode = 'none';
 870+ js_log( 'import mode: ' + _this.import_url_mode );
 871+ callback();
 872+ }
 873+ } );
 874+ break;
 875+ }
 876+ }
778877 }
779 - } );
 878+ );
780879 }
781880 },
 881+
782882 /*
783883 * checkForCopyURLPermission:
784 - * not really necessary the api request to upload will return appropriate error if the user lacks permission. or $wgAllowCopyUploads is set to false
 884+ * not really necessary the api request to upload will return appropriate error
 885+ * if the user lacks permission. or $wgAllowCopyUploads is set to false
785886 * (use this function if we want to issue a warning up front)
786887 */
787 - checkForCopyURLPermission:function( callback ) {
 888+ checkForCopyURLPermission: function( callback ) {
788889 var _this = this;
789890 // do api check:
790 - do_api_req( {
 891+ do_api_req(
 892+ {
791893 'data': { 'action' : 'query', 'meta' : 'userinfo', 'uiprop' : 'rights' },
792894 'url': _this.upload_api_target,
793895 'userinfo' : true
794 - }, function( data ) {
795 - for ( var i in data.query.userinfo.rights ) {
796 - var right = data.query.userinfo.rights[i];
797 - // js_log('checking: ' + right ) ;
798 - if ( right == 'upload_by_url' ) {
799 - callback( true );
800 - return true; // break out of the function
 896+ }, function( data ) {
 897+ for ( var i in data.query.userinfo.rights ) {
 898+ var right = data.query.userinfo.rights[i];
 899+ // js_log('checking: ' + right ) ;
 900+ if ( right == 'upload_by_url' ) {
 901+ callback( true );
 902+ return true; // break out of the function
 903+ }
801904 }
802 - }
803 - callback( false );
804 - } );
 905+ callback( false );
 906+ }
 907+ );
805908 },
806 - getLibSearchResults:function( cp ) {
 909+
 910+ getLibSearchResults: function( provider ) {
807911 var _this = this;
808912
809 - // first check if we should even run the search at all (can we import / insert into the page? )
810 - if ( !this.checkRepoLocal( cp ) && this.import_url_mode == 'autodetect' ) {
811 - // cp is not local check if we can support the import mode:
 913+ // first check if we should even run the search at all (can we import / insert
 914+ // into the page? )
 915+ if ( !this.isProviderLocal( provider ) && this.import_url_mode == 'autodetect' ) {
 916+ // provider is not local check if we can support the import mode:
812917 this.checkForCopyURLSupport( function() {
813 - _this.getLibSearchResults( cp );
 918+ _this.getLibSearchResults( provider );
814919 } );
815920 return false;
816 - } else if ( !this.checkRepoLocal( cp ) && this.import_url_mode == 'none' ) {
817 - if ( this.disp_item == 'combined' ) {
 921+ } else if ( !this.isProviderLocal( provider ) && this.import_url_mode == 'none' ) {
 922+ if ( this.currentProvider == 'combined' ) {
818923 // combined results are harder to error handle just ignore that repo
819 - cp.sObj.loading = false;
 924+ provider.sObj.loading = false;
820925 } else {
821 - $j( '#tab-' + this.disp_item ).html( '<div style="padding:10px">' + gM( 'mwe-no_import_by_url' ) + '</div>' );
 926+ $j( '#tab-' + this.currentProvider ).html(
 927+ '<div style="padding:10px">' +
 928+ gM( 'mwe-no_import_by_url' ) +
 929+ '</div>' );
822930 }
823931 return false;
824932 }
825 - _this.loadSearchLib( cp, function() {
 933+ _this.loadSearchLib( provider, function() {
826934 // Do the search
827 - cp.sObj.getSearchResults();
828 - _this.checkResultsDone();
 935+ provider.sObj.getSearchResults();
 936+ _this.waitForResults( function() {
 937+ this.showResults();
 938+ } );
829939 } );
830940 },
831 - loadSearchLib:function( cp, callback ) {
 941+
 942+ loadSearchLib: function( provider, callback ) {
832943 var _this = this;
833944 // set up the library req:
834945 mvJsLoader.doLoad( [
835946 'baseRemoteSearch',
836 - cp.lib + 'Search'
 947+ provider.lib + 'Search'
837948 ], function() {
838 - js_log( "loaded lib:: " + cp.lib );
 949+ js_log( "loaded lib:: " + provider.lib );
839950 // else we need to run the search:
840 - var iObj = {
841 - 'cp' : cp,
842 - 'rsd' : _this
 951+ var options = {
 952+ 'provider': provider,
 953+ 'rsd': _this
843954 };
844 - eval( 'cp.sObj = new ' + cp.lib + 'Search( iObj );' );
845 - if ( !cp.sObj ) {
 955+ eval( 'provider.sObj = new ' + provider.lib + 'Search( options );' );
 956+ if ( !provider.sObj ) {
846957 js_log( 'Error: could not find search lib for ' + cp_id );
847958 return false;
848959 }
849960
850961 // inherit defaults if not set:
851 - cp.limit = ( cp.limit ) ? cp.limit : cp.sObj.limit;
852 - cp.offset = ( cp.offset ) ? cp.offset : cp.sObj.offset;
 962+ provider.limit = provider.limit ? provider.limit : provider.sObj.limit;
 963+ provider.offset = provider.offset ? provider.offset : provider.sObj.offset;
853964 callback();
854965 } );
855966 },
 967+
856968 /* check for all the results to finish */
857 - checkResultsDone: function() {
858 - // js_log('rsd:checkResultsDone');
 969+ waitForResults: function( callback ) {
 970+ // js_log('rsd:waitForResults');
859971 var _this = this;
860972 var loading_done = true;
861973
862 - for ( var cp_id in this.content_providers ) {
 974+ for ( var cp_id in this.content_providers ) {
863975 var cp = this.content_providers[ cp_id ];
864976 if ( typeof cp['sObj'] != 'undefined' ) {
865977 if ( cp.sObj.loading )
@@ -866,666 +978,826 @@
867979 }
868980 }
869981 if ( loading_done ) {
870 - this.drawOutputResults();
 982+ callback();
871983 } else {
872 - // make sure the instance name is up-to-date refrerance to _this;
873 - eval( _this.instance_name + ' = _this' );
874 - setTimeout( _this.instance_name + '.checkResultsDone()', 50 );
 984+ setTimeout(
 985+ function() {
 986+ _this.waitForResults( callback );
 987+ },
 988+ 50
 989+ );
875990 }
876991 },
877 - drawTabs: function() {
 992+
 993+ createTabs: function() {
878994 var _this = this;
879995 // add the tabs to the rsd_results container:
880 - var o = '<div id="rsd_tabs_container" style="width:100%;">';
 996+ var s = '<div id="rsd_tabs_container" style="width:100%;">';
881997 var selected_tab = 0;
882 - var inx = 0;
883 - o += '<ul>';
884 - var tabc = '';
885 - for ( var cp_id in this.content_providers ) {
886 - var cp = this.content_providers[cp_id];
887 - if ( cp.enabled && cp.checked && cp.api_url ) {
888 - // add selected default if set
889 - if ( this.disp_item == cp_id )
890 - selected_tab = inx;
 998+ var index = 0;
 999+ s += '<ul>';
 1000+ var content = '';
 1001+ for ( var providerName in this.content_providers ) {
 1002+ var provider = this.content_providers[providerName];
 1003+ var tabImage = mv_embed_path + '/skins/common/remote_cp/' + providerName + '_tab.png';
 1004+ if ( provider.enabled && provider.checked && provider.api_url ) {
 1005+ // add selected default if set
 1006+ if ( this.currentProvider == providerName )
 1007+ selected_tab = index;
8911008
892 - o += '<li class="rsd_cp_tab">';
893 - o += '<a id="rsd_tab_' + cp_id + '" href="#tab-' + cp_id + '">';
894 - if ( cp.tab_img === true ) {
895 - o += '<img alt="' + gM( 'rsd-' + cp_id + '-title' ) + '" src="' + mv_embed_path + '/skins/common/remote_cp/' + cp_id + '_tab.png">';
896 - } else {
897 - o += gM( 'rsd-' + cp_id + '-title' );
898 - }
899 - o += '</a>';
900 - o += '</li>';
901 - inx++;
902 - }
903 - tabc += '<div id="tab-' + cp_id + '" class="rsd_results"/>';
904 -
 1009+ s += '<li class="rsd_cp_tab">';
 1010+ s += '<a id="rsd_tab_' + providerName + '" href="#tab-' + providerName + '">';
 1011+ if ( provider.tab_img === true ) {
 1012+ s += '<img alt="' + gM( 'rsd-' + providerName + '-title' ) + '" ' +
 1013+ 'src="' + tabImage + '">';
 1014+ } else {
 1015+ s += gM( 'rsd-' + providerName + '-title' );
 1016+ }
 1017+ s += '</a>';
 1018+ s += '</li>';
 1019+ index++;
9051020 }
906 - // Do an upload tab if enabled:
907 - if ( this.content_providers['upload'].enabled ) {
908 - o += '<li class="rsd_cp_tab" ><a id="rsd_tab_upload" href="#tab-upload">' + gM( 'mwe-upload_tab' ) + '</a></li>';
909 - tabc += '<div id="tab-upload" />';
910 - if ( this.disp_item == 'upload' )
911 - selected_tab = inx++;
912 - }
913 - o += '</ul>';
914 - // Output the tab content containers:
915 - o += tabc;
916 - o += '</div>'; // close tab container
 1021+ content += '<div id="tab-' + providerName + '" class="rsd_results"/>';
 1022+ }
 1023+ // Do an upload tab if enabled:
 1024+ if ( this.content_providers['upload'].enabled ) {
 1025+ s += '<li class="rsd_cp_tab" >' +
 1026+ '<a id="rsd_tab_upload" href="#tab-upload">' +
 1027+ gM( 'mwe-upload_tab' ) +
 1028+ '</a></li>';
 1029+ content += '<div id="tab-upload" />';
 1030+ if ( this.currentProvider == 'upload' )
 1031+ selected_tab = index++;
 1032+ }
 1033+ s += '</ul>';
 1034+ // Output the tab content containers:
 1035+ s += content;
 1036+ s += '</div>'; // close tab container
9171037
9181038 // Output the respective results holders
919 - $j( '#rsd_results_container' ).html( o );
 1039+ $j( '#rsd_results_container' ).html( s );
9201040 // Setup bindings for tabs make them sortable: (@@todo remember order)
9211041 js_log( 'selected tab is: ' + selected_tab );
922 - $j( "#rsd_tabs_container" ).tabs( {
923 - selected:selected_tab,
924 - select: function( event, ui ) {
925 - _this.selectTab( $j( ui.tab ).attr( 'id' ).replace( 'rsd_tab_', '' ) );
926 - }
927 - // Add sorting
928 - } ).find( ".ui-tabs-nav" ).sortable( { axis:'x' } );
929 - // @@todo store sorted repo
 1042+ $j( "#rsd_tabs_container" )
 1043+ .tabs( {
 1044+ selected: selected_tab,
 1045+ select: function( event, ui ) {
 1046+ _this.selectTab( $j( ui.tab ).attr( 'id' ).replace( 'rsd_tab_', '' ) );
 1047+ }
 1048+ })
 1049+ // Add sorting
 1050+ .find( ".ui-tabs-nav" ).sortable( { axis: 'x' } );
 1051+ // @@todo store sorted repo
 1052+ },
9301053
931 - },
9321054 // Resource title
933 - getResourceFromTitle : function( rTitle , callback ) {
 1055+ getResourceFromTitle: function( title, callback ) {
9341056 var _this = this;
9351057 reqObj = {
936 - 'action':'query',
937 - 'titles': _this.cFileNS + ':' + rTitle
 1058+ 'action': 'query',
 1059+ 'titles': _this.cFileNS + ':' + title
9381060 };
9391061 do_api_req( {
940 - 'data':reqObj,
941 - 'url':this.local_wiki_api_url
 1062+ 'data': reqObj,
 1063+ 'url': this.local_wiki_api_url
9421064 }, function( data ) {
943 - // @@todo propagate the rObj
944 - var rObj = { };
 1065+ // @@todo propagate the resource
 1066+ var resource = {};
9451067 }
9461068 );
9471069 },
 1070+
9481071 // @@todo we could load the id with the content provider id to find the object faster...
949 - getResourceFromId:function( rid ) {
950 - //js_log('getResourceFromId:' + rid );
951 - // strip out /res/ if preset:
952 - rid = rid.replace( /res_/, '' );
953 - // js_log("looking at: " + rid);
954 - p = rid.split( '__' );
955 - var cp_id = p[0];
956 - var rid = p[1];
957 -
958 - // Set the upload helper cp_id (to render recent uploads by this user)
959 - if ( cp_id == 'upload' )
960 - cp_id = 'this_wiki';
 1072+ getResourceFromId: function( id ) {
 1073+ var parts = id.replace( /^res_/, '' ).split( '__' );
 1074+ var providerName = parts[0];
 1075+ var resIndex = parts[1];
9611076
962 - var cp = this.content_providers[cp_id];
963 - if ( cp && cp['sObj'] && cp.sObj.resultsObj[rid] ) {
964 - return cp.sObj.resultsObj[rid];
 1077+ // Set the upload helper providerName (to render recent uploads by this user)
 1078+ if ( providerName == 'upload' )
 1079+ providerName = 'this_wiki';
 1080+
 1081+ var provider = this.content_providers[providerName];
 1082+ if ( provider && provider['sObj'] && provider.sObj.resultsObj[resIndex] ) {
 1083+ return provider.sObj.resultsObj[resIndex];
9651084 }
966 - js_log( "ERROR: could not find " + rid );
 1085+ js_log( "ERROR: could not find " + resIndex );
9671086 return false;
9681087 },
969 - drawOutputResults: function() {
970 - js_log( 'f:drawOutputResults::' + this.disp_item );
 1088+
 1089+ showResults: function() {
 1090+ js_log( 'f:showResults::' + this.currentProvider );
9711091 var _this = this;
9721092 var o = '';
973 -
974 - var cp_id = this.disp_item;
975 - var tab_target = '';
976 - if ( this.disp_item == 'upload' ) {
977 - tab_target = '#upload_bin';
978 - var cp = _this.content_providers['this_wiki'];
 1093+ var tabSelector = '';
 1094+
 1095+ if ( this.currentProvider == 'upload' ) {
 1096+ tabSelector = '#upload_bin';
 1097+ var provider = _this.content_providers['this_wiki'];
9791098 } else {
980 - var cp = this.content_providers[this.disp_item];
981 - tab_target = '#tab-' + cp_id;
982 - // Output the results bar / controls
 1099+ var provider = this.content_providers[this.currentProvider];
 1100+ tabSelector = '#tab-' + this.currentProvider;
 1101+ // Output the results bar / controls
9831102 }
9841103 // Empty the existing results:
985 - $j( tab_target ).empty();
986 - // @@todo give the user upload control love
987 - if ( this.disp_item != 'upload' ) {
988 - _this.setResultBarControl();
 1104+ $j( tabSelector ).empty();
 1105+ // @@todo give the user upload control love
 1106+ if ( this.currentProvider != 'upload' ) {
 1107+ _this.showResultsHeader();
9891108 }
990 -
991 - var drawResultCount = 0;
9921109
993 - // Output all the results for the current disp_item
994 - if ( typeof cp['sObj'] != 'undefined' ) {
995 - $j.each( cp.sObj.resultsObj, function( rInx, rItem ) {
996 - if ( _this.result_display_mode == 'box' ) {
997 - o += '<div id="mv_result_' + rInx + '" class="mv_clip_box_result" style="width:' +
998 - _this.thumb_width + 'px;height:' + ( _this.thumb_width - 20 ) + 'px;position:relative;">';
999 - // Check for missing poster types for audio
1000 - if ( rItem.mime == 'audio/ogg' && !rItem.poster ) {
1001 - rItem.poster = mv_skin_img_path + 'sound_music_icon-80.png';
1002 - }
1003 - // Get a thumb with proper resolution transform if possible:
1004 - o += '<img title="' + rItem.title + '" class="rsd_res_item" id="res_' + cp_id + '__' + rInx +
1005 - '" style="width:' + _this.thumb_width + 'px;" src="' +
1006 - cp.sObj.getImageTransform( rItem, { 'width' : _this.thumb_width } )
1007 - + '">';
1008 - // Add a linkback to resource page in upper right:
1009 - if ( rItem.link )
1010 - o += '<div class="rsd_linkback ui-corner-all ui-state-default ui-widget-content" >' +
1011 - '<a target="_new" title="' + gM( 'mwe-resource_description_page' ) +
1012 - '" href="' + rItem.link + '">' + gM( 'mwe-link' ) + '</a>' +
1013 - '</div>';
1014 -
1015 - // Add file type icon if known
1016 - if ( rItem.mime ) {
1017 - o += _this.getTypeIcon( rItem.mime );
1018 - }
1019 -
1020 - // Add license icons if present
1021 - if ( rItem.license )
1022 - o += _this.getlicenseImgSet( rItem.license );
1023 -
1024 - o += '</div>';
1025 - } else if ( _this.result_display_mode == 'list' ) {
1026 - o += '<div id="mv_result_' + rInx + '" class="mv_clip_list_result" style="width:90%">';
1027 - o += '<img title="' + rItem.title + '" class="rsd_res_item" id="res_' + cp_id + '__' + rInx + '" style="float:left;width:' +
1028 - _this.thumb_width + 'px;" src="' +
1029 - cp.sObj.getImageTransform( rItem, { 'width':_this.thumb_width } )
1030 - + '">';
1031 - // Add license icons if present
1032 - if ( rItem.license )
1033 - o += _this.getlicenseImgSet( rItem.license );
 1110+ var numResults = 0;
10341111
1035 - o += rItem.desc ;
1036 - o += '<div style="clear:both" />';
1037 - o += '</div>';
1038 - }
1039 - drawResultCount++;
 1112+ // Output all the results for the current currentProvider
 1113+ if ( typeof provider['sObj'] != 'undefined' ) {
 1114+ $j.each( provider.sObj.resultsObj, function( resIndex, resource ) {
 1115+ o += _this.getResultHtml( provider, resIndex, resource );
 1116+ numResults++;
10401117 } );
10411118 js_log( 'append to: ' + '#tab-' + cp_id );
10421119 // Put in the tab output (plus clear the output)
1043 - $j( tab_target ).append( o + '<div style="clear:both"/>' );
 1120+ $j( tabSelector ).append( o + '<div style="clear:both"/>' );
10441121 }
10451122
1046 - js_log( 'did drawResultCount :: ' + drawResultCount + ' append: ' + $j( '#rsd_q' ).val() );
 1123+ js_log( 'did numResults :: ' + numResults +
 1124+ ' append: ' + $j( '#rsd_q' ).val() );
10471125
10481126 // Remove any old search res
10491127 $j( '#rsd_no_search_res' ).remove();
1050 - if ( drawResultCount == 0 )
1051 - $j( '#tab-' + cp_id ).append( '<span style="padding:10px">' + gM( 'rsd_no_results', $j( '#rsd_q' ).val() ) + '</span>' );
1052 -
 1128+ if ( numResults == 0 ) {
 1129+ $j( '#tab-' + cp_id ).append(
 1130+ '<span style="padding:10px">' +
 1131+ gM( 'rsd_no_results', $j( '#rsd_q' ).val() ) +
 1132+ '</span>' );
 1133+ }
10531134 this.addResultBindings();
10541135 },
1055 - addResultBindings:function() {
 1136+
 1137+ getResultHtml: function( provider, resIndex, resource ) {
 1138+ var o = '';
 1139+ if ( this.displayMode == 'box' ) {
 1140+ o += '<div id="mv_result_' + resIndex + '" ' +
 1141+ 'class="mv_clip_box_result" ' +
 1142+ 'style="' +
 1143+ 'width:' + this.thumb_width + 'px;' +
 1144+ 'height:' + ( this.thumb_width - 20 ) + 'px;' +
 1145+ 'position:relative;">';
 1146+ // Check for missing poster types for audio
 1147+ if ( resource.mime == 'audio/ogg' && !resource.poster ) {
 1148+ resource.poster = mv_skin_img_path + 'sound_music_icon-80.png';
 1149+ }
 1150+ // Get a thumb with proper resolution transform if possible:
 1151+ var thumbUrl = provider.sObj.getImageTransform( resource,
 1152+ { 'width' : this.thumb_width } );
 1153+
 1154+ o += '<img title="' + resource.title + '" ' +
 1155+ 'class="rsd_res_item" id="res_' + cp_id + '__' + resIndex + '" ' +
 1156+ 'style="width:' + this.thumb_width + 'px;" ' +
 1157+ 'src="' + thumbUrl + '">';
 1158+ // Add a linkback to resource page in upper right:
 1159+ if ( resource.link ) {
 1160+ o += '<div class="' +
 1161+ 'rsd_linkback ui-corner-all ui-state-default ui-widget-content" >' +
 1162+ '<a target="_new" title="' + gM( 'mwe-resource_description_page' ) +
 1163+ '" href="' + resource.link + '">' + gM( 'mwe-link' ) + '</a>' +
 1164+ '</div>';
 1165+ }
 1166+
 1167+ // Add file type icon if known
 1168+ if ( resource.mime ) {
 1169+ o += this.getTypeIcon( resource.mime );
 1170+ }
 1171+
 1172+ // Add license icons if present
 1173+ if ( resource.license )
 1174+ o += this.getLicenseIconHtml( resource.license );
 1175+
 1176+ o += '</div>';
 1177+ } else if ( this.displayMode == 'list' ) {
 1178+ o += '<div id="mv_result_' + resIndex + '" class="mv_clip_list_result" style="width:90%">';
 1179+ o +=
 1180+ '<img ' +
 1181+ 'title="' + resource.title + '" ' +
 1182+ 'class="rsd_res_item" id="res_' + cp_id + '__' + resIndex + '" ' +
 1183+ 'style="float:left;width:' + this.thumb_width + 'px;" ' +
 1184+ 'src="' + provider.sObj.getImageTransform( resource, { 'width': this.thumb_width } ) + '">';
 1185+ // Add license icons if present
 1186+ if ( resource.license )
 1187+ o += this.getLicenseIconHtml( resource.license );
 1188+
 1189+ o += resource.desc ;
 1190+ o += '<div style="clear:both" />';
 1191+ o += '</div>';
 1192+ }
 1193+ return o;
 1194+ }
 1195+
 1196+ addResultBindings: function() {
10561197 var _this = this;
1057 - $j( '.mv_clip_' + _this.result_display_mode + '_result' ).hover( function() {
1058 - $j( this ).addClass( 'mv_clip_' + _this.result_display_mode + '_result_over' );
1059 - // Also set the animated image if available
1060 - var res_id = $j( this ).children( '.rsd_res_item' ).attr( 'id' );
1061 - var rObj = _this.getResourceFromId( res_id );
1062 - if ( rObj.poster_ani )
1063 - $j( '#' + res_id ).attr( 'src', rObj.poster_ani );
1064 - }, function() {
1065 - $j( this ).removeClass( 'mv_clip_' + _this.result_display_mode + '_result_over' );
1066 - var res_id = $j( this ).children( '.rsd_res_item' ).attr( 'id' );
1067 - var rObj = _this.getResourceFromId( res_id );
1068 - // Restore the original (non animated)
1069 - if ( rObj.poster_ani )
1070 - $j( '#' + res_id ).attr( 'src', rObj.poster );
1071 - } );
 1198+ $j( '.mv_clip_' + _this.displayMode + '_result' ).hover(
 1199+ function() {
 1200+ $j( this ).addClass( 'mv_clip_' + _this.displayMode + '_result_over' );
 1201+ // Also set the animated image if available
 1202+ var res_id = $j( this ).children( '.rsd_res_item' ).attr( 'id' );
 1203+ var resource = _this.getResourceFromId( res_id );
 1204+ if ( resource.poster_ani )
 1205+ $j( '#' + res_id ).attr( 'src', resource.poster_ani );
 1206+ }, function() {
 1207+ $j( this ).removeClass(
 1208+ 'mv_clip_' + _this.displayMode + '_result_over' );
 1209+ var res_id = $j( this ).children( '.rsd_res_item' ).attr( 'id' );
 1210+ var resource = _this.getResourceFromId( res_id );
 1211+ // Restore the original (non animated)
 1212+ if ( resource.poster_ani )
 1213+ $j( '#' + res_id ).attr( 'src', resource.poster );
 1214+ }
 1215+ );
10721216 // Resource click action: (bring up the resource editor)
10731217 $j( '.rsd_res_item' ).unbind().click( function() {
1074 - var rObj = _this.getResourceFromId( $j( this ).attr( "id" ) );
1075 - _this.resourceEdit( rObj, this );
 1218+ var resource = _this.getResourceFromId( $j( this ).attr( "id" ) );
 1219+ _this.showResourceEditor( resource, this );
10761220 } );
10771221 },
1078 - addResourceEditLoader:function( maxWidth, overflow_style ) {
 1222+
 1223+ addResourceEditLoader: function( maxWidth, overflowStyle ) {
10791224 var _this = this;
1080 - if ( !maxWidth )maxWidth = 400;
1081 - if ( !overflow_style )overflow_style = 'overflow:auto;';
 1225+ if ( !maxWidth ) maxWidth = 400;
 1226+ if ( !overflowStyle ) overflowStyle = 'overflow:auto;';
10821227 // Remove any old instance:
10831228 $j( _this.target_container ).find( '#rsd_resource_edit' ).remove();
1084 -
 1229+
10851230 // Hide the results container
10861231 $j( '#rsd_results_container' ).hide();
1087 -
 1232+
10881233 var pt = $j( _this.target_container ).html();
10891234 // Add the edit layout window with loading place holders
1090 - $j( _this.target_container ).append( '<div id="rsd_resource_edit" ' +
1091 - 'style="position:absolute;top:0px;left:0px;bottom:0px;right:4px;background-color:#FFF;"> ' +
1092 - '<div id="clip_edit_ctrl" class="ui-widget ui-widget-content ui-corner-all" style="position:absolute;' +
1093 - 'left:2px;top:5px;bottom:10px;width:' + ( maxWidth + 5 ) + 'px;overflow:auto;padding:5px;" >' +
1094 - '</div>' +
1095 - '<div id="clip_edit_disp" class="ui-widget ui-widget-content ui-corner-all"' +
1096 - 'style="position:absolute;' + overflow_style + ';left:' + ( maxWidth + 20 ) + 'px;right:0px;top:5px;bottom:10px;padding:5px;" >' +
1097 - mv_get_loading_img( 'position:absolute;top:30px;left:30px' ) +
1098 - '</div>' +
1099 - '</div>' );
 1235+ $j( _this.target_container ).append(
 1236+ '<div id="rsd_resource_edit" ' +
 1237+ 'style="position:absolute;top:0px;left:0px;' +
 1238+ 'bottom:0px;right:4px;background-color:#FFF;"> ' +
 1239+ '<div id="clip_edit_ctrl" ' +
 1240+ 'class="ui-widget ui-widget-content ui-corner-all" ' +
 1241+ 'style="position:absolute;left:2px;top:5px;bottom:10px;' +
 1242+ 'width:' + ( maxWidth + 5 ) + 'px;overflow:auto;padding:5px;" >' +
 1243+ '</div>' +
 1244+ '<div id="clip_edit_disp" ' +
 1245+ 'class="ui-widget ui-widget-content ui-corner-all"' +
 1246+ 'style="position:absolute;' + overflowStyle + ';' +
 1247+ 'left:' + ( maxWidth + 20 ) + 'px;right:0px;top:5px;bottom:10px;' +
 1248+ 'padding:5px;" >' +
 1249+ mv_get_loading_img( 'position:absolute;top:30px;left:30px' ) +
 1250+ '</div>' +
 1251+ '</div>' );
11001252 },
1101 - resourceEdit:function( rObj, rsdElement ) {
1102 - js_log( 'f:resourceEdit:' + rObj.title );
1103 - var _this = this;
1104 - // Remove any existing resource edit interface:
1105 - $j( '#rsd_resource_edit' ).remove();
1106 - // set the media type:
1107 - if ( rObj.mime.indexOf( 'image' ) != -1 ) {
1108 - // Set width to default image_edit_width
1109 - var maxWidth = _this.image_edit_width;
1110 - var mediaType = 'image';
1111 - } else if ( rObj.mime.indexOf( 'audio' ) != -1 ) {
1112 - var maxWidth = _this.video_edit_width;
1113 - var mediaType = 'audio';
 1253+
 1254+ getEditWidth: function( resource ) {
 1255+ var mediaType = this.getMediaType( resource );
 1256+ if ( mediaType == 'image' ) {
 1257+ return resource.image_edit_width;
11141258 } else {
1115 - // Set to default video size:
1116 - var maxWidth = _this.video_edit_width;
1117 - var mediaType = 'video';
 1259+ return resource.video_edit_width;
11181260 }
1119 - // So that transcripts show ontop
1120 - var overflow_style = ( mediaType == 'video' ) ? '':'overflow:auto;';
 1261+ },
 1262+
 1263+ getMediaType: function( resource ) {
 1264+ if ( resource.mime.indexOf( 'image' ) != -1 ) {
 1265+ return 'image';
 1266+ } else if ( resource.mime.indexOf( 'audio' ) != -1 ) {
 1267+ return 'audio';
 1268+ } else {
 1269+ return 'video';
 1270+ }
 1271+ },
 1272+
 1273+ removeResourceEditor: function() {
 1274+ $j( '#rsd_resource_edit' ).remove();
 1275+ $j( '#rsd_resource_edit' ).css( 'opacity', 0 );
 1276+ $j( '#rsd_edit_img' ).remove();
 1277+ }
 1278+
 1279+ showResourceEditor: function( resource, rsdElement ) {
 1280+ js_log( 'f:showResourceEditor:' + resource.title );
 1281+ var _this = this;
 1282+
 1283+ // Remove any existing resource edit interface
 1284+ _this.removeResourceEditor();
 1285+
 1286+ var mediaType = _this.getMediaType( resource );
 1287+ var maxWidth = _this.getEditWidth( resource );
 1288+
 1289+ // So that transcripts show on top
 1290+ var overflow_style = ( mediaType == 'video' ) ? '' : 'overflow:auto;';
11211291 // Append to the top level of model window:
11221292 _this.addResourceEditLoader( maxWidth, overflow_style );
11231293 // update add media wizard title:
1124 - $j( _this.target_container ).dialog( 'option', 'title', gM( 'mwe-add_media_wizard' ) + ': ' + gM( 'rsd_resource_edit', rObj.title ) );
 1294+ var dialogTitle = gM( 'mwe-add_media_wizard' ) + ': ' +
 1295+ gM( 'rsd_resource_edit', resource.title );
 1296+ $j( _this.target_container ).dialog( 'option', 'title', dialogTitle );
11251297 js_log( 'did append to: ' + _this.target_container );
11261298
1127 - $j( '#rsd_resource_edit' ).css( 'opacity', 0 );
 1299+ // Left side holds the image right size the controls /
 1300+ $j( rsdElement )
 1301+ .clone()
 1302+ .attr( 'id', 'rsd_edit_img' )
 1303+ .appendTo( '#clip_edit_disp' )
 1304+ .css( {
 1305+ 'position':'absolute',
 1306+ 'top':'40%',
 1307+ 'left':'20%',
 1308+ 'cursor':'default',
 1309+ 'opacity':0
 1310+ } );
11281311
1129 - $j( '#rsd_edit_img' ).remove();// remove any existing rsd_edit_img
1130 -
1131 - // Left side holds the image right size the controls /
1132 - $j( rsdElement ). clone ().attr( 'id', 'rsd_edit_img' ).appendTo( '#clip_edit_disp' ).css( {
1133 - 'position':'absolute',
1134 - 'top':'40%',
1135 - 'left':'20%',
1136 - 'cursor':'default',
1137 - 'opacity':0
1138 - } );
1139 -
1140 - // Try and keep aspect ratio for the thumbnail that we clicked:
 1312+ // Try and keep aspect ratio for the thumbnail that we clicked:
11411313 var tRatio = $j( rsdElement ).height() / $j( rsdElement ).width();
11421314
1143 - if (! tRatio )
1144 - var tRatio = 1; // set ratio to 1 if tRatio did not work.
1145 -
1146 - js_log( 'Set from ' + tRatio + ' to init thumbimage to ' + maxWidth + ' x ' + parseInt( tRatio * maxWidth ) );
 1315+ if ( !tRatio ) {
 1316+ var tRatio = 1; // set ratio to 1 if tRatio did not work.
 1317+ }
 1318+ js_log( 'Set from ' + tRatio + ' to init thumbimage to ' +
 1319+ maxWidth + ' x ' + parseInt( tRatio * maxWidth ) );
11471320 // Scale up image and to swap with high res version
1148 - $j( '#rsd_edit_img' ).animate( {
1149 - 'opacity':1,
1150 - 'top':'5px',
1151 - 'left':'5px',
1152 - 'width': maxWidth + 'px',
1153 - 'height': parseInt( tRatio * maxWidth ) + 'px'
1154 - }, "slow" ); // Do it slow to give it a chance to finish loading the HQ version
 1321+ $j( '#rsd_edit_img' ).animate(
 1322+ {
 1323+ 'opacity': 1,
 1324+ 'top': '5px',
 1325+ 'left': '5px',
 1326+ 'width': maxWidth + 'px',
 1327+ 'height': parseInt( tRatio * maxWidth ) + 'px'
 1328+ },
 1329+ "slow" ); // Do it slow to give it a chance to finish loading the high quality version
11551330
11561331 if ( mediaType == 'image' ) {
1157 - _this.loadHQImg( rObj, { 'width':maxWidth }, 'rsd_edit_img', function() {
1158 - $j( '.mv_loading_img' ).remove();
1159 - } );
 1332+ _this.loadHighQualityImage(
 1333+ resource,
 1334+ { 'width': maxWidth },
 1335+ 'rsd_edit_img',
 1336+ function() {
 1337+ $j( '.mv_loading_img' ).remove();
 1338+ }
 1339+ );
11601340 }
11611341 // Also fade in the container:
11621342 $j( '#rsd_resource_edit' ).animate( {
1163 - 'opacity':1,
1164 - 'background-color':'#FFF',
1165 - 'z-index':99
 1343+ 'opacity': 1,
 1344+ 'background-color': '#FFF',
 1345+ 'z-index': 99
11661346 } );
1167 - // Do load the media Editor
1168 - _this.doMediaEdit( rObj , mediaType );
 1347+
 1348+ // Show the editor itself
 1349+ if ( mediaType == 'image' ) {
 1350+ _this.showImageEditor( resource );
 1351+ } else if ( mediaType == 'video' || mediaType == 'audio' ) {
 1352+ _this.showVideoEditor( resource );
 1353+ }
11691354 },
1170 - loadHQImg:function( rObj, size, target_img_id, callback ) {
1171 - // Get the HQ image url:
1172 - rObj.pSobj.getImageObj( rObj, size, function( imObj ) {
1173 - rObj['edit_url'] = imObj.url;
11741355
1175 - js_log( "edit url: " + rObj.edit_url );
1176 - // Update the rObj
1177 - rObj['width'] = imObj.width;
1178 - rObj['height'] = imObj.height;
 1356+ loadHighQualityImage: function( resource, size, target_img_id, callback ) {
 1357+ // Get the high quality image url:
 1358+ resource.pSobj.getImageObj( resource, size, function( imObj ) {
 1359+ resource['edit_url'] = imObj.url;
11791360
 1361+ js_log( "edit url: " + resource.edit_url );
 1362+ // Update the resource
 1363+ resource['width'] = imObj.width;
 1364+ resource['height'] = imObj.height;
 1365+
11801366 // See if we need to animate some transition
11811367 if ( size.width != imObj.width ) {
1182 - js_log( 'loadHQImg:size mismatch: ' + size.width + ' != ' + imObj.width );
 1368+ js_log( 'loadHighQualityImage:size mismatch: ' + size.width + ' != ' + imObj.width );
11831369 // Set the target id to the new size:
11841370 $j( '#' + target_img_id ).animate( {
1185 - 'width':imObj.width + 'px',
1186 - 'height':imObj.height + 'px'
1187 - } );
 1371+ 'width': imObj.width + 'px',
 1372+ 'height': imObj.height + 'px'
 1373+ });
11881374 } else {
11891375 js_log( 'using req size: ' + imObj.width + 'x' + imObj.height );
1190 - $j( '#' + target_img_id ).animate( { 'width':imObj.width + 'px', 'height' : imObj.height + 'px' } );
 1376+ $j( '#' + target_img_id ).animate( {
 1377+ 'width': imObj.width + 'px',
 1378+ 'height': imObj.height + 'px'
 1379+ });
11911380 }
11921381 // Don't swap it in until its loaded:
11931382 var img = new Image();
11941383 // Load the image image:
11951384 $j( img ).load( function () {
1196 - $j( '#' + target_img_id ).attr( 'src', rObj.edit_url );
 1385+ $j( '#' + target_img_id ).attr( 'src', resource.edit_url );
11971386 // Let the caller know we are done and what size we ended up with:
11981387 callback();
11991388 } ).error( function () {
1200 - js_log( "Error with: " + rObj.edit_url );
1201 - } ).attr( 'src', rObj.edit_url );
1202 - } );
 1389+ js_log( "Error with: " + resource.edit_url );
 1390+ } ).attr( 'src', resource.edit_url );
 1391+ } );
12031392 },
1204 - cancelClipEditCB:function() {
 1393+
 1394+ onCancelClipEdit: function() {
12051395 var _this = this;
1206 - js_log( 'cancelClipEditCB' );
1207 - var b_target = _this.target_container + '~ .ui-dialog-buttonpane';
 1396+ js_log( 'onCancelClipEdit' );
 1397+ var b_target = _this.target_container + '~ .ui-dialog-buttonpane';
12081398 $j( '#rsd_resource_edit' ).remove();
12091399 // Remove preview if its 'on'
12101400 $j( '#rsd_preview_display' ).remove();
12111401 // Restore the resource container:
12121402 $j( '#rsd_results_container' ).show();
1213 -
 1403+
12141404 // Restore the title:
12151405 $j( _this.target_container ).dialog( 'option', 'title', gM( 'mwe-add_media_wizard' ) );
12161406 js_log( "should update: " + b_target + ' with: cancel' );
1217 - // Restore the buttons:
1218 - $j( b_target ).html( $j.btnHtml( gM( 'mwe-cancel' ) , 'mv_cancel_rsd', 'close' ) )
 1407+ // Restore the buttons:
 1408+ $j( b_target )
 1409+ .html( $j.btnHtml( gM( 'mwe-cancel' ) , 'mv_cancel_rsd', 'close' ) )
12191410 .children( '.mv_cancel_rsd' )
12201411 .btnBind()
12211412 .click( function() {
12221413 $j( _this.target_container ).dialog( 'close' );
12231414 } );
12241415 },
1225 - /* getClipEditControlActions
1226 - * Set-up the control actions for clipEdit with relevant callbacks
1227 - */
1228 - getClipEditControlActions:function( cp ) {
 1416+
 1417+ /**
 1418+ * Get the control actions for clipEdit with relevant callbacks
 1419+ */
 1420+ getClipEditControlActions: function( provider ) {
12291421 var _this = this;
1230 - var cConf = { };
 1422+ var actions = { };
12311423
1232 - cConf['insert'] = function( rObj ) {
1233 - _this.insertResource( rObj );
 1424+ actions['insert'] = function( resource ) {
 1425+ _this.insertResource( resource );
12341426 }
12351427 // If not directly inserting the resource is support a preview option:
12361428 if ( _this.import_url_mode != 'remote_link' ) {
1237 - cConf['preview'] = function( rObj ) {
1238 - _this.previewResource( rObj )
 1429+ actions['preview'] = function( resource ) {
 1430+ _this.showPreview( resource )
12391431 };
12401432 }
1241 - cConf['cancel'] = function() {
1242 - _this.cancelClipEditCB()
 1433+ actions['cancel'] = function() {
 1434+ _this.onCancelClipEdit()
12431435 }
1244 - return cConf;
 1436+ return actions;
12451437 },
1246 - // Loads the media editor:
1247 - doMediaEdit:function( rObj , mediaType ) {
 1438+
 1439+ getClipEditOptions: function( resource ) {
 1440+ return {
 1441+ 'rObj': resource,
 1442+ 'parent_ct': 'rsd_modal_target',
 1443+ 'clip_disp_ct': 'clip_edit_disp',
 1444+ 'control_ct': 'clip_edit_ctrl',
 1445+ 'media_type': this.getMediaType( resource ),
 1446+ 'p_rsdObj': this,
 1447+ 'controlActionsCb': this.getClipEditControlActions( resource.pSobj.cp ),
 1448+ 'enabled_tools': this.enabled_tools
 1449+ };
 1450+ },
 1451+
 1452+ /**
 1453+ * Internal function called by showResourceEditor() to show an image editor
 1454+ */
 1455+ showImageEditor: function( resource ) {
12481456 var _this = this;
1249 - var cp = rObj.pSobj.cp;
1250 - js_log( 'remoteSearchDriver::doMediaEdit: ' + mediaType );
1251 -
1252 - var mvClipInit = {
1253 - 'rObj' : rObj, // the resource object
1254 - 'parent_ct' : 'rsd_modal_target',
1255 - 'clip_disp_ct' : 'clip_edit_disp',
1256 - 'control_ct' : 'clip_edit_ctrl',
1257 - 'media_type' : mediaType,
1258 - 'p_rsdObj' : _this,
1259 - 'controlActionsCb' : _this.getClipEditControlActions( cp ),
1260 - 'enabled_tools' : _this.enabled_tools
1261 - };
1262 - // Set the base clip edit lib class req set:
1263 - var clibs = ['mvClipEdit'];
1264 -
1265 - if ( mediaType == 'image' ) {
1266 - // Display the mvClipEdit obj once we are done loading:
1267 - mvJsLoader.doLoad( clibs, function() {
1268 - // Run the image clip tools
1269 - _this.cEdit = new mvClipEdit( mvClipInit );
1270 - } );
1271 - } else if ( mediaType == 'video' || mediaType == 'audio' ) {
1272 - js_log( 'media type:: ' + mediaType );
1273 - // Get any additional embedding helper meta data prior to doing the actual embed
1274 - // normally this meta should be provided in the search result (but archive.org has another query for more media meta)
1275 - rObj.pSobj.addResourceInfoCallback( rObj, function() {
1276 - // Make sure we have the embedVideo libs:
1277 - var runFlag = false;
1278 - mvJsLoader.embedVideoCheck( function() {
1279 - // Strange concurrency issue with callbacks
1280 - // @@todo try and figure out why this callback is fired twice
1281 - if ( !runFlag ) {
1282 - runFlag = true;
1283 - } else {
1284 - js_log( 'Error: embedVideoCheck run twice' );
1285 - return false;
1286 - }
1287 - js_log( 'append html: ' + rObj.pSobj.getEmbedHTML( rObj, { id:'embed_vid' } ) );
1288 - $j( '#clip_edit_disp' ).html(
1289 - rObj.pSobj.getEmbedHTML( rObj, {
1290 - id : 'embed_vid'
1291 - } )
1292 - );
1293 - js_log( "about to call rewrite_by_id::embed_vid" );
1294 - // Rewrite by id
1295 - rewrite_by_id( 'embed_vid', function() {
1296 - // Grab information avaliable from the embed instance
1297 - rObj.pSobj.addResourceInfoFromEmbedInstance( rObj, 'embed_vid' );
1298 -
1299 - // Add the re-sizable to the doLoad request:
1300 - clibs.push( '$j.ui.resizable' );
1301 - clibs.push( '$j.fn.hoverIntent' );
1302 - mvJsLoader.doLoad( clibs, function() {
1303 - // Make sure the rsd_edit_img is removed:
1304 - $j( '#rsd_edit_img' ).remove();
1305 - // Run the image clip tools
1306 - _this.cEdit = new mvClipEdit( mvClipInit );
1307 - } );
 1457+ var options = _this.getClipEditOptions( resource );
 1458+ // Display the mvClipEdit obj once we are done loading:
 1459+ mvJsLoader.doLoad( clibs, function() {
 1460+ // Run the image clip tools
 1461+ _this.clipEdit = new mvClipEdit( options );
 1462+ } );
 1463+ },
 1464+
 1465+ /**
 1466+ * Internal function called by showResourceEditor() to show a video or audio
 1467+ * editor.
 1468+ */
 1469+ showVideoEditor: function( resource ) {
 1470+ var _this = this;
 1471+ var options = _this.getClipEditOptions( resource );
 1472+ var mediaType = this.getMediaType( resource );
 1473+
 1474+ js_log( 'media type:: ' + mediaType );
 1475+ // Get any additional embedding helper meta data prior to doing the actual embed
 1476+ // normally this meta should be provided in the search result
 1477+ // (but archive.org has another query for more media meta)
 1478+ resource.pSobj.addResourceInfoCallback( resource, function() {
 1479+ // Make sure we have the embedVideo libs:
 1480+ var runFlag = false;
 1481+ mvJsLoader.embedVideoCheck( function() {
 1482+ // Strange concurrency issue with callbacks
 1483+ // @@todo try and figure out why this callback is fired twice
 1484+ if ( !runFlag ) {
 1485+ runFlag = true;
 1486+ } else {
 1487+ js_log( 'Error: embedVideoCheck run twice' );
 1488+ return false;
 1489+ }
 1490+ var embedHtml = resource.pSobj.getEmbedHTML( resource,
 1491+ { id : 'embed_vid' } );
 1492+ js_log( 'append html: ' + embedHtml );
 1493+ $j( '#clip_edit_disp' ).html( embedHtml );
 1494+ js_log( "about to call rewrite_by_id::embed_vid" );
 1495+ // Rewrite by id
 1496+ rewrite_by_id( 'embed_vid', function() {
 1497+ // Grab information avaliable from the embed instance
 1498+ resource.pSobj.addResourceInfoFromEmbedInstance( resource, 'embed_vid' );
 1499+
 1500+ // Add the re-sizable to the doLoad request:
 1501+ clibs.push( '$j.ui.resizable' );
 1502+ clibs.push( '$j.fn.hoverIntent' );
 1503+ mvJsLoader.doLoad( clibs, function() {
 1504+ // Make sure the rsd_edit_img is removed:
 1505+ $j( '#rsd_edit_img' ).remove();
 1506+ // Run the image clip tools
 1507+ _this.clipEdit = new mvClipEdit( options );
13081508 } );
13091509 } );
13101510 } );
1311 - }
 1511+ } );
13121512 },
1313 - checkRepoLocal:function( cp ) {
1314 - if ( cp.local ) {
 1513+
 1514+ isProviderLocal: function( provider ) {
 1515+ if ( provider.local ) {
13151516 return true;
13161517 } else {
13171518 // Check if we can embed the content locally per a domain name check:
1318 - var local_host = mw.parseUri( this.local_wiki_api_url ).host;
1319 - if ( cp.local_domains ) {
1320 - for ( var i = 0; i < cp.local_domains.length; i++ ) {
1321 - var ld = cp.local_domains[i];
1322 - if ( local_host.indexOf( ld ) != -1 )
1323 - return true;
 1519+ var localHost = mw.parseUri( this.local_wiki_api_url ).host;
 1520+ if ( provider.local_domains ) {
 1521+ for ( var i = 0; i < provider.local_domains.length; i++ ) {
 1522+ var domain = provider.local_domains[i];
 1523+ if ( localHost.indexOf( domain ) != -1 )
 1524+ return true;
13241525 }
13251526 }
13261527 return false;
13271528 }
13281529 },
1329 - checkImportResource:function( rObj, cir_callback ) {
 1530+
 1531+ /**
 1532+ * Check if the file is either a local upload, or if it has already been
 1533+ * imported under the standard filename scheme.
 1534+ *
 1535+ * Calls the callback with two parameters:
 1536+ * callback( resource, status )
 1537+ *
 1538+ * resource: a resource object pointing to the local file if there is one,
 1539+ * or false if not
 1540+ *
 1541+ * status: may be 'local', 'shared', 'imported' or 'missing'
 1542+ */
 1543+ isFileLocallyAvailable: function( resource, callback ) {
13301544 var _this = this;
1331 - // Add a loader ontop:
 1545+ // Add a loader on top
13321546 $j.addLoaderDialog( gM( 'mwe-checking-resource' ) );
1333 - // Extend the callback with close dialog
1334 - var org_cir_callback = cir_callback;
1335 - cir_callback = function( rObj ) {
1336 - var cat = org_cir_callback;
 1547+
 1548+ // Extend the callback, closing the loader dialog before chaining
 1549+ myCallback = function( newRes, status ) {
13371550 $j.closeLoaderDialog();
1338 - if ( typeof org_cir_callback == 'function' ) {
1339 - org_cir_callback( rObj );
 1551+ if ( typeof callback == 'function' ) {
 1552+ callback( newRes, status );
13401553 }
13411554 }
 1555+
13421556 // @@todo get the localized File/Image namespace name or do a general {NS}:Title
1343 - var cp = rObj.pSobj.cp;
 1557+ var provider = resource.pSobj.cp;
13441558 var _this = this;
13451559
 1560+ // Clone the resource
 1561+ var proto = {};
 1562+ proto.prototype = resource;
 1563+ var myRes = new proto;
 1564+
13461565 // Update base target_resource_title:
1347 - rObj.target_resource_title = rObj.titleKey.replace( /File:|Image:/ , '' )
 1566+ myRes.target_resource_title = myRes.titleKey.replace( /^(File:|Image:)/ , '' )
13481567
13491568 // check if local repository
13501569 // or if import mode if just "linking" (we should already have the 'url'
13511570
1352 - if ( this.checkRepoLocal( cp ) || this.import_url_mode == 'remote_link' ) {
1353 - // Local repo jump directly to check Import Resource callback:
1354 - cir_callback( rObj );
 1571+ if ( this.isProviderLocal( provider ) || this.import_url_mode == 'remote_link' ) {
 1572+ // Local repo, jump directly to the callback:
 1573+ myCallback( myRes, 'local' );
13551574 } else {
1356 - // Check if the file is local (can be shared repo)
1357 - if ( cp.check_shared ) {
1358 - _this.checkForFile( rObj.target_resource_title, function( imagePage ) {
 1575+ // Check if the file is local (can be shared repo)
 1576+ if ( provider.check_shared ) {
 1577+ _this.findFileInLocalWiki( myRes.target_resource_title, function( imagePage ) {
13591578 if ( imagePage && imagePage['imagerepository'] == 'shared' ) {
1360 - cir_callback( rObj );
 1579+ myCallback( myRes, 'shared' );
13611580 } else {
1362 - _this.checkPrefixNameImport( rObj, cir_callback );
 1581+ _this.isFileAlreadyImported( myRes, myCallback );
13631582 }
13641583 } );
13651584 } else {
1366 - _this.checkPrefixNameImport( rObj, cir_callback );
 1585+ _this.isFileAlreadyImported( myRes, myCallback );
13671586 }
13681587 }
13691588 },
1370 - checkPrefixNameImport: function( rObj, cir_callback ) {
1371 - js_log( '::checkPrefixNameImport:: ' );
1372 - var cp = rObj.pSobj.cp;
 1589+
 1590+ /**
 1591+ * Check if the file is already imported with this extension's filename scheme
 1592+ *
 1593+ * Calls the callback with two parameters:
 1594+ * callback( resource, status )
 1595+ *
 1596+ * If the image is found, the status will be 'imported' and the resource
 1597+ * will be the new local resource.
 1598+ *
 1599+ * If the image is not found, the status will be 'missing' and the resource
 1600+ * will be false.
 1601+ */
 1602+ isFileAlreadyImported: function( resource, callback ) {
 1603+ js_log( '::isFileAlreadyImported:: ' );
13731604 var _this = this;
 1605+
 1606+ // Clone the resource
 1607+ var proto = {};
 1608+ proto.prototype = resource;
 1609+ var myRes = new proto;
 1610+
 1611+ var provider = myRes.pSobj.cp;
 1612+
13741613 // update target_resource_title with resource repository prefix:
1375 - rObj.target_resource_title = cp.resource_prefix + rObj.target_resource_title;
1376 - // check if the file exists:
1377 - _this.checkForFile( rObj.target_resource_title, function( imagePage ) {
 1614+ myRes.target_resource_title = provider.resource_prefix + myRes.target_resource_title;
 1615+ // check if the file exists:
 1616+ _this.findFileInLocalWiki( myRes.target_resource_title, function( imagePage ) {
13781617 if ( imagePage ) {
13791618 // update to local src
1380 - rObj.local_src = imagePage['imageinfo'][0].url;
 1619+ myRes.local_src = imagePage['imageinfo'][0].url;
13811620 // @@todo maybe update poster too?
1382 - rObj.local_poster = imagePage['imageinfo'][0].thumburl;
1383 - // update the title:
1384 - rObj.target_resource_title = imagePage.title.replace(/File:|Image:/ , '' );
1385 - cir_callback( rObj );
 1621+ myRes.local_poster = imagePage['imageinfo'][0].thumburl;
 1622+ // update the title:
 1623+ myRes.target_resource_title = imagePage.title.replace(/^(File:|Image:)/ , '' );
 1624+ callback( myRes, 'imported' );
13861625 } else {
1387 - // close the dialog and display the import interface:
1388 - $j.closeLoaderDialog();
1389 - _this.doImportInterface( rObj, cir_callback );
 1626+ callback( false, 'missing' );
13901627 }
13911628 } );
13921629 },
1393 - doImportInterface : function( rObj, callback ) {
 1630+
 1631+ showImportUI: function( resource, callback ) {
13941632 var _this = this;
1395 - js_log( "doImportInterface:: update:" + _this.cFileNS + ':' + rObj.target_resource_title );
 1633+ js_log( "showImportUI:: update:" + _this.cFileNS + ':' +
 1634+ resource.target_resource_title );
13961635
13971636 // setup the resource description from resource description:
1398 - var wt = '{{Information ' + "\n";
 1637+ // FIXME: i18n, namespace
 1638+ var desc = '{{Information ' + "\n";
13991639
1400 - if ( rObj.desc ) {
1401 - wt += '|Description= ' + rObj.desc + "\n";
 1640+ if ( resource.desc ) {
 1641+ desc += '|Description= ' + resource.desc + "\n";
14021642 } else {
1403 - wt += '|Description= ' + gM( 'mwe-missing_desc_see_source', rObj.link ) + "\n";
 1643+ desc += '|Description= ' + gM( 'mwe-missing_desc_see_source', resource.link ) + "\n";
14041644 }
14051645
14061646 // output search specific info
1407 - wt += '|Source=' + rObj.pSobj.getImportResourceDescWiki( rObj ) + "\n";
 1647+ desc += '|Source=' + resource.pSobj.getImportResourceDescWiki( resource ) + "\n";
14081648
1409 - if ( rObj.author )
1410 - wt += '|Author=' + rObj.author + "\n";
 1649+ if ( resource.author )
 1650+ desc += '|Author=' + resource.author + "\n";
14111651
1412 - if ( rObj.date )
1413 - wt += '|Date=' + rObj.date + "\n";
 1652+ if ( resource.date )
 1653+ desc += '|Date=' + resource.date + "\n";
14141654
14151655 // add the Permision info:
1416 - wt += '|Permission=' + rObj.pSobj.getPermissionWikiTag( rObj ) + "\n";
 1656+ desc += '|Permission=' + resource.pSobj.getPermissionWikiTag( resource ) + "\n";
14171657
1418 - if ( rObj.other_versions )
1419 - wt += '|other_versions=' + rObj.other_versions + "\n";
 1658+ if ( resource.other_versions )
 1659+ desc += '|other_versions=' + resource.other_versions + "\n";
14201660
1421 - wt += '}}';
 1661+ desc += '}}';
14221662
14231663 // get any extra categories or helpful links
1424 - wt += rObj.pSobj.getExtraResourceDescWiki( rObj );
 1664+ desc += resource.pSobj.getExtraResourceDescWiki( resource );
14251665
14261666
14271667 $j( '#rsd_resource_import' ).remove();// remove any old resource imports
14281668
14291669 // @@ show user dialog to import the resource
1430 - $j( _this.target_container ).append( '<div id="rsd_resource_import" ' +
1431 - 'class="ui-widget-content" style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;z-index:5">' +
1432 - '<h3 style="color:red;padding:5px;">' + gM( 'mwe-resource-needs-import', [rObj.title, _this.upload_api_name] ) + '</h3>' +
1433 - '<div id="rsd_preview_import_container" style="position:absolute;width:50%;bottom:0px;left:5px;overflow:auto;top:30px;">' +
1434 - rObj.pSobj.getEmbedHTML( rObj, {
1435 - 'id': _this.target_container + '_rsd_pv_vid',
1436 - 'max_height':'220',
1437 - 'only_poster':true
1438 - } ) + // get embedHTML with small thumb:
1439 - '<br style="clear both"/>' +
1440 - '<strong>' + gM( 'mwe-resource_page_desc' ) + '</strong>' +
1441 - '<div id="rsd_import_desc" style="display:inline;">' +
1442 - mv_get_loading_img( 'position:absolute;top:5px;left:5px' ) +
1443 - '</div>' +
1444 - '</div>' +
1445 - '<div id="rds_edit_import_container" style="position:absolute;left:50%;' +
1446 - 'bottom:0px;top:30px;right:0px;overflow:auto;">' +
1447 - '<strong>' + gM( 'mwe-local_resource_title' ) + '</strong><br>' +
1448 - '<input type="text" size="30" value="' + rObj.target_resource_title + '" /></br>' +
1449 - '<strong>' + gM( 'mwe-edit_resource_desc' ) + '</strong>' +
1450 - '<textarea id="rsd_import_ta" id="mv_img_desc" style="width:90%;" rows="8" cols="50">' +
1451 - wt +
1452 - '</textarea></br>' +
1453 - '<input type="checkbox" value="true" id="wpWatchthis" name="wpWatchthis" tabindex="7" />' +
1454 - '<label for="wpWatchthis">' + gM( 'mwe-watch_this_page' ) + '</label></br></br></br>' +
1455 - $j.btnHtml( gM( 'mwe-update_preview' ), 'rsd_import_apreview', 'refresh' ) + ' ' +
1456 - '</div>' +
1457 - // output the rendered and non-rendered version of description for easy switching:
1458 - '</div>' );
1459 - var bPlaneTarget = _this.target_container + '~ .ui-dialog-buttonpane';
1460 - $j( bPlaneTarget ).html (
1461 - // add the btns to the bottom:
1462 - $j.btnHtml( gM( 'mwe-do_import_resource' ), 'rsd_import_doimport', 'check' ) + ' ' +
 1670+ $j( _this.target_container ).append(
 1671+ '<div id="rsd_resource_import" ' +
 1672+ 'class="ui-widget-content" ' +
 1673+ 'style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;z-index:5">' +
 1674+ '<h3 style="color:red;padding:5px;">' +
 1675+ gM( 'mwe-resource-needs-import', [resource.title, _this.upload_api_name] ) +
 1676+ '</h3>' +
 1677+ '<div id="rsd_preview_import_container" ' +
 1678+ 'style="position:absolute;width:50%;bottom:0px;left:5px;' +
 1679+ 'overflow:auto;top:30px;">' +
 1680+ resource.pSobj.getEmbedHTML( resource, {
 1681+ 'id': _this.target_container + '_rsd_pv_vid',
 1682+ 'max_height': '220',
 1683+ 'only_poster': true
 1684+ } ) + // get embedHTML with small thumb:
 1685+ '<br style="clear both"/>' +
 1686+ '<strong>' + gM( 'mwe-resource_page_desc' ) + '</strong>' +
 1687+ '<div id="rsd_import_desc" style="display:inline;">' +
 1688+ mv_get_loading_img( 'position:absolute;top:5px;left:5px' ) +
 1689+ '</div>' +
 1690+ '</div>' +
 1691+ '<div id="rds_edit_import_container" ' +
 1692+ 'style="position:absolute; ' +
 1693+ 'left:50%;bottom:0px;top:30px;right:0px;overflow:auto;">' +
 1694+ '<strong>' + gM( 'mwe-local_resource_title' ) + '</strong>' +
 1695+ // FIXME: invalid HTML, <br> must be empty
 1696+ '<br/>' +
 1697+ '<input type="text" size="30" value="' + resource.target_resource_title + '" />' +
 1698+ '<br/>' +
 1699+ '<strong>' + gM( 'mwe-edit_resource_desc' ) + '</strong>' +
 1700+ // FIXME: invalid HTML, two id attributes
 1701+ '<textarea id="rsd_import_ta" id="mv_img_desc" ' +
 1702+ 'style="width:90%;" rows="8" cols="50">' +
 1703+ desc +
 1704+ '</textarea>' +
 1705+ '<br/>' +
 1706+ '<input type="checkbox" value="true" id="wpWatchthis" ' +
 1707+ 'name="wpWatchthis" tabindex="7" />' +
 1708+ '<label for="wpWatchthis">' + gM( 'mwe-watch_this_page' ) + '</label> ' +
 1709+ '<br/><br/><br/>' +
 1710+ $j.btnHtml( gM( 'mwe-update_preview' ), 'rsd_import_apreview', 'refresh' ) +
 1711+ ' ' +
 1712+ '</div>' +
 1713+ // output the rendered and non-rendered version of description for easy switching:
 1714+ '</div>' );
 1715+ var buttonPaneSelector = _this.target_container + '~ .ui-dialog-buttonpane';
 1716+ $j( buttonPaneSelector ).html (
 1717+ // add the btns to the bottom:
 1718+ $j.btnHtml( gM( 'mwe-do_import_resource' ), 'rsd_import_doimport', 'check' ) +
 1719+ ' ' +
14631720 $j.btnHtml( gM( 'mwe-cancel_import' ), 'rsd_import_acancel', 'close' ) + ' '
14641721 );
1465 -
 1722+
14661723 // add hover:
14671724
1468 - // update video tag (if a video)
1469 - if ( rObj.mime.indexOf( 'video/' ) !== -1 )
 1725+ // update video tag (if a video)
 1726+ if ( resource.mime.indexOf( 'video/' ) !== -1 )
14701727 rewrite_by_id( $j( _this.target_container ).attr( 'id' ) + '_rsd_pv_vid' );
1471 -
 1728+
14721729 // load the preview text:
1473 - _this.getParsedWikiText( wt, _this.cFileNS + ':' + rObj.target_resource_title, function( o ) {
1474 - $j( '#rsd_import_desc' ).html( o );
1475 - } );
 1730+ _this.parse(
 1731+ desc, _this.cFileNS + ':' + resource.target_resource_title,
 1732+ function( descHtml ) {
 1733+ $j( '#rsd_import_desc' ).html( descHtml );
 1734+ }
 1735+ );
14761736 // add bindings:
1477 - $j( _this.target_container + ' .rsd_import_apreview' ).btnBind().click( function() {
1478 - js_log( " Do preview asset update" );
1479 - $j( '#rsd_import_desc' ).html( mv_get_loading_img() );
1480 - // load the preview text:
1481 - _this.getParsedWikiText( $j( '#rsd_import_ta' ).val(), _this.cFileNS + ':' + rObj.target_resource_title, function( o ) {
1482 - js_log( 'got updated preview: ' );
1483 - $j( '#rsd_import_desc' ).html( o );
 1737+ $j( _this.target_container + ' .rsd_import_apreview' )
 1738+ .btnBind()
 1739+ .click( function() {
 1740+ js_log( " Do preview asset update" );
 1741+ $j( '#rsd_import_desc' ).html( mv_get_loading_img() );
 1742+ // load the preview text:
 1743+ _this.parse(
 1744+ $j( '#rsd_import_ta' ).val(),
 1745+ _this.cFileNS + ':' + resource.target_resource_title,
 1746+ function( o ) {
 1747+ js_log( 'got updated preview: ' );
 1748+ $j( '#rsd_import_desc' ).html( o );
 1749+ }
 1750+ );
14841751 } );
1485 - } );
1486 - $j( bPlaneTarget + ' .rsd_import_doimport' ).btnBind().click( function() {
1487 - js_log( "do import asset:" + _this.import_url_mode );
1488 - // check import mode:
1489 - if ( _this.import_url_mode == 'api' ) {
1490 - if ( _this.upload_api_target == 'proxy' ) { ;
1491 - _this.setupProxy( function() {
1492 - _this.doImportAPI( rObj , callback );
1493 - } );
 1752+
 1753+ $j( buttonPaneSelector + ' .rsd_import_doimport' )
 1754+ .btnBind()
 1755+ .click( function() {
 1756+ js_log( "do import asset:" + _this.import_url_mode );
 1757+ // check import mode:
 1758+ if ( _this.import_url_mode == 'api' ) {
 1759+ if ( _this.upload_api_target == 'proxy' ) {
 1760+ _this.setupProxy( function() {
 1761+ _this.doApiImport( resource, callback );
 1762+ } );
 1763+ } else {
 1764+ _this.doApiImport( resource, callback );
 1765+ }
14941766 } else {
1495 - _this.doImportAPI( rObj , callback );
 1767+ js_log( "Error: import mode is not form or API (can not copy asset)" );
14961768 }
1497 - } else {
1498 - js_log( "Error: import mode is not form or API (can not copy asset)" );
1499 - }
1500 - } );
1501 - $j( bPlaneTarget + ' .rsd_import_acancel' ).btnBind().click( function() {
1502 - $j( '#rsd_resource_import' ).fadeOut( "fast", function() {
1503 - $j( this ).remove();
1504 - // restore buttons (from the clipEdit object::)
1505 - _this.cEdit.updateInsertControlActions();
1506 - $j( bPlaneTarget ).removeClass( 'ui-state-error' );
15071769 } );
1508 - } );
 1770+ $j( buttonPaneSelector + ' .rsd_import_acancel' )
 1771+ .btnBind()
 1772+ .click( function() {
 1773+ $j( '#rsd_resource_import' ).fadeOut( "fast", function() {
 1774+ $j( this ).remove();
 1775+ // restore buttons (from the clipEdit object::)
 1776+ _this.clipEdit.updateInsertControlActions();
 1777+ $j( buttonPaneSelector ).removeClass( 'ui-state-error' );
 1778+ } );
 1779+ } );
15091780 },
1510 - /**
 1781+
 1782+ /**
15111783 * Sets up the proxy for the remote inserts
15121784 */
1513 - setupProxy:function( callback ) {
 1785+ setupProxy: function( callback ) {
15141786 var _this = this;
1515 -
 1787+
15161788 if ( _this.proxySetupDone ) {
15171789 if ( callback )
15181790 callback();
1519 - return ;
 1791+ return;
15201792 }
15211793 // setup the the proxy via $j.apiProxy loader:
1522 - if ( ! _this.upload_api_proxy_frame ) {
 1794+ if ( !_this.upload_api_proxy_frame ) {
15231795 js_log( "Error:: remote api but no proxy frame target" );
15241796 return false;
15251797 } else {
15261798 $j.apiProxy(
15271799 'client',
15281800 {
1529 - 'server_frame' : _this.upload_api_proxy_frame
 1801+ 'server_frame': _this.upload_api_proxy_frame
15301802 }, function() {
15311803 _this.proxySetupDone = true
15321804 if ( callback )
@@ -1534,31 +1806,35 @@
15351807 );
15361808 }
15371809 },
1538 - checkForFile:function( fName, callback ) {
1539 - js_log( "checkForFile::" + fName );
 1810+
 1811+ findFileInLocalWiki: function( fName, callback ) {
 1812+ js_log( "findFileInLocalWiki::" + fName );
15401813 var _this = this;
15411814 reqObj = {
1542 - 'action':'query',
1543 - 'titles': _this.cFileNS + ':' + fName,
1544 - 'prop' : 'imageinfo',
1545 - 'iiprop' : 'url',
1546 - 'iiurlwidth': '400'
 1815+ 'action': 'query',
 1816+ 'titles': _this.cFileNS + ':' + fName,
 1817+ 'prop': 'imageinfo',
 1818+ 'iiprop': 'url',
 1819+ 'iiurlwidth': '400'
15471820 };
15481821 // first check the api for imagerepository
1549 - do_api_req( {
1550 - 'data':reqObj,
1551 - 'url':this.local_wiki_api_url
 1822+ do_api_req(
 1823+ {
 1824+ 'data': reqObj,
 1825+ 'url': this.local_wiki_api_url
15521826 }, function( data ) {
15531827 if ( data.query.pages ) {
15541828 for ( var i in data.query.pages ) {
15551829 for ( var j in data.query.pages[i] ) {
1556 - if ( j == 'missing' && data.query.pages[i].imagerepository != 'shared' ) {
 1830+ if ( j == 'missing'
 1831+ && data.query.pages[i].imagerepository != 'shared' )
 1832+ {
15571833 js_log( fName + " not found" );
15581834 callback( false );
1559 - return ;
 1835+ return;
15601836 }
15611837 }
1562 - // else page is found:
 1838+ // else page is found:
15631839 js_log( fName + " found" );
15641840 callback( data.query.pages[i] );
15651841 }
@@ -1566,54 +1842,57 @@
15671843 }
15681844 );
15691845 },
1570 - doImportAPI:function( rObj, cir_callback ) {
 1846+
 1847+ doApiImport: function( resource, callback ) {
15711848 var _this = this;
1572 - js_log( ":doImportAPI:" );
 1849+ js_log( ":doApiImport:" );
15731850 $j.addLoaderDialog( gM( 'mwe-importing_asset' ) );
15741851 // baseUploadInterface
1575 - mvJsLoader.doLoad( [
1576 - 'mvBaseUploadInterface',
1577 - '$j.ui.progressbar'
1578 - ], function() {
1579 - js_log( 'mvBaseUploadInterface ready' );
1580 - // initiate a upload object ( similar to url copy ):
1581 - myUp = new mvBaseUploadInterface( {
1582 - 'api_url' : _this.upload_api_target,
1583 - 'done_upload_cb':function() {
1584 - js_log( 'doImportAPI:: run callback::' );
1585 - // we have finished the upload:
 1852+ mvJsLoader.doLoad(
 1853+ [
 1854+ 'mvBaseUploadInterface',
 1855+ '$j.ui.progressbar'
 1856+ ],
 1857+ function() {
 1858+ js_log( 'mvBaseUploadInterface ready' );
 1859+ // initiate a upload object ( similar to url copy ):
 1860+ var uploader = new mvBaseUploadInterface( {
 1861+ 'api_url' : _this.upload_api_target,
 1862+ 'done_upload_cb':function() {
 1863+ js_log( 'doApiImport:: run callback::' );
 1864+ // we have finished the upload:
15861865
1587 - // close up the rsd_resource_import
1588 - $j( '#rsd_resource_import' ).remove();
1589 - // return the parent callback:
1590 - return cir_callback();
1591 - }
1592 - } );
1593 - // get the edit token if we have it handy
1594 - _this.getEditToken( function( token ) {
1595 - myUp.etoken = token;
1596 -
1597 - // close the loader now that we are ready to present the progress dialog::
1598 - $j.closeLoaderDialog();
1599 -
1600 - myUp.doHttpUpload( {
1601 - 'url' : rObj.src,
1602 - 'filename' : rObj.target_resource_title,
1603 - 'comment' : $j( '#rsd_import_ta' ).val()
 1866+ // close up the rsd_resource_import
 1867+ $j( '#rsd_resource_import' ).remove();
 1868+ // return the parent callback:
 1869+ return callback();
 1870+ }
16041871 } );
1605 - } )
 1872+ // get the edit token if we have it handy
 1873+ _this.getEditToken( function( token ) {
 1874+ uploader.editToken = token;
16061875
 1876+ // close the loader now that we are ready to present the progress dialog::
 1877+ $j.closeLoaderDialog();
16071878
1608 - } );
 1879+ uploader.doHttpUpload( {
 1880+ 'url': resource.src,
 1881+ 'filename': resource.target_resource_title,
 1882+ 'comment': $j( '#rsd_import_ta' ).val()
 1883+ } );
 1884+ } )
 1885+ }
 1886+ );
16091887 },
1610 - getEditToken:function( callback ) {
 1888+
 1889+ getEditToken: function( callback ) {
16111890 var _this = this;
16121891 if ( _this.upload_api_target != 'proxy' ) {
16131892 // (if not a proxy) first try to get the token from the page:
1614 - var etoken = $j( "input[name='wpEditToken']" ).val();
1615 - if ( etoken ) {
1616 - callback( etoken );
1617 - return ;
 1893+ var editToken = $j( "input[name='wpEditToken']" ).val();
 1894+ if ( editToken ) {
 1895+ callback( editToken );
 1896+ return;
16181897 }
16191898 }
16201899 // @@todo try to load over ajax if( _this.local_wiki_api_url ) is set
@@ -1622,41 +1901,54 @@
16231902 callback( token );
16241903 } );
16251904 },
1626 - previewResource:function( rObj ) {
 1905+
 1906+ showPreview: function( resource ) {
16271907 var _this = this;
1628 - this.checkImportResource( rObj, function() {
 1908+ this.isFileLocallyAvailable( resource, function( newRes, status ) {
 1909+ if ( status === 'missing' ) {
 1910+ _this.showImportUI( resource, callback );
 1911+ return;
 1912+ }
 1913+
16291914 // put another window ontop:
1630 - $j( _this.target_container ).append( '<div id="rsd_preview_display"' +
1631 - 'style="position:absolute;overflow:hidden;z-index:4;top:0px;bottom:0px;right:0px;left:0px;background-color:#FFF;">' +
1632 - mv_get_loading_img( 'top:30px;left:30px' ) +
1633 - '</div>' );
 1915+ $j( _this.target_container ).append(
 1916+ '<div id="rsd_preview_display"' +
 1917+ 'style="position:absolute;overflow:hidden;z-index:4;' +
 1918+ 'top:0px;bottom:0px;right:0px;left:0px;background-color:#FFF;">' +
 1919+ mv_get_loading_img( 'top:30px;left:30px' ) +
 1920+ '</div>' );
16341921
1635 - var bPlaneTarget = _this.target_container + '~ .ui-dialog-buttonpane';
1636 - var pTitle = $j( _this.target_container ).dialog( 'option', 'title' );
 1922+ var buttonPaneSelector = _this.target_container + '~ .ui-dialog-buttonpane';
 1923+ var origTitle = $j( _this.target_container ).dialog( 'option', 'title' );
16371924
16381925 // update title:
1639 - $j( _this.target_container ).dialog( 'option', 'title', gM( 'mwe-preview_insert_resource', rObj.title ) );
 1926+ $j( _this.target_container ).dialog( 'option', 'title',
 1927+ gM( 'mwe-preview_insert_resource', newRes.title ) );
16401928
16411929 // update buttons preview:
1642 - $j( bPlaneTarget ).html( $j.btnHtml( gM( 'rsd_do_insert' ), 'preview_do_insert', 'check' ) + ' ' )
 1930+ $j( buttonPaneSelector )
 1931+ .html(
 1932+ $j.btnHtml( gM( 'rsd_do_insert' ), 'preview_do_insert', 'check' ) + ' ' )
16431933 .children( '.preview_do_insert' )
16441934 .click( function() {
1645 - _this.insertResource( rObj );
 1935+ _this.insertResource( newRes );
16461936 } );
16471937 // update cancel button
1648 - $j( bPlaneTarget ).append( '<a href="#" class="preview_close">Do More Modification</a>' )
 1938+ $j( buttonPaneSelector )
 1939+ .append( '<a href="#" class="preview_close">Do More Modification</a>' )
16491940 .children( '.preview_close' )
16501941 .click( function() {
16511942 $j( '#rsd_preview_display' ).remove();
16521943 // restore title:
1653 - $j( _this.target_container ).dialog( 'option', 'title', pTitle );
 1944+ $j( _this.target_container ).dialog( 'option', 'title', origTitle );
16541945 // restore buttons (from the clipEdit object::)
1655 - _this.cEdit.updateInsertControlActions();
 1946+ _this.clipEdit.updateInsertControlActions();
16561947 } );
16571948
1658 - // update the preview_wtext
1659 - _this.updatePreviewText( rObj );
1660 - _this.getParsedWikiText( _this.preview_wtext, _this.target_title,
 1949+ // Get the preview wikitext
 1950+ _this.parse(
 1951+ _this.getPreviewText( newRes ),
 1952+ _this.target_title,
16611953 function( phtml ) {
16621954 $j( '#rsd_preview_display' ).html( phtml );
16631955 // update the display of video tag items (if any)
@@ -1665,58 +1957,79 @@
16661958 );
16671959 } );
16681960 },
1669 - updatePreviewText:function( rObj ) {
1670 - var _this = this;
16711961
1672 - if ( _this.import_url_mode == 'remote_link' ) {
1673 - _this.cur_embed_code = rObj.pSobj.getEmbedHTML( rObj );
 1962+ getEmbedCode: function( resource ) {
 1963+ if ( this.import_url_mode == 'remote_link' ) {
 1964+ return resource.pSobj.getEmbedHTML( resource );
16741965 } else {
1675 - _this.cur_embed_code = rObj.pSobj.getEmbedWikiCode( rObj );
 1966+ return resource.pSobj.getEmbedWikiCode( resource );
16761967 }
 1968+ },
16771969
 1970+ getPreviewText: function( resource ) {
 1971+ var _this = this;
 1972+ var text;
 1973+
16781974 // insert at start if textInput cursor has not been set (ie == length)
1679 - if ( _this.caret_pos && _this.caret_pos.text ) {
1680 - if ( _this.caret_pos.text.length == _this.caret_pos.s )
1681 - _this.caret_pos.s = 0;
1682 - _this.preview_wtext = _this.caret_pos.text.substring( 0, _this.caret_pos.s ) +
1683 - _this.cur_embed_code +
1684 - _this.caret_pos.text.substring( _this.caret_pos.s );
 1975+ var insertPos = _this.getCaretPos();
 1976+ var originalText = _this.getTextboxValue();
 1977+ var embedCode = _this.getEmbedCode( resource );
 1978+ if ( insertPos !== false && originalText ) {
 1979+ if ( originalText.length == insertPos ) {
 1980+ insertPos = 0;
 1981+ }
 1982+ text = originalText.substring( 0, insertPos ) +
 1983+ embedCode + originalText.substring( insertPos );
16851984 } else {
1686 - _this.preview_wtext = $j( _this.target_textbox ).val() + _this.cur_embed_code;
 1985+ text = $j( _this.target_textbox ).val() + embedCode;
16871986 }
1688 - // check for missing </refrences>
1689 - if ( _this.preview_wtext.indexOf( '<references/>' ) == -1 && _this.preview_wtext.indexOf( '<ref>' ) != -1 )
1690 - _this.preview_wtext = _this.preview_wtext + '<references/>';
 1987+ // check for missing </references>
 1988+ if ( text.indexOf( '<references/>' ) == -1 && text.indexOf( '<ref>' ) != -1 ) {
 1989+ text = text + '<references/>';
 1990+ }
 1991+ return text;
16911992 },
1692 - getParsedWikiText:function( wikitext, title, callback ) {
1693 - do_api_req( {
1694 - 'data': { 'action':'parse',
1695 - 'text':wikitext
1696 - },
1697 - 'url':this.local_wiki_api_url
 1993+
 1994+ parse: function( wikitext, title, callback ) {
 1995+ do_api_req(
 1996+ {
 1997+ 'data': {
 1998+ 'action': 'parse',
 1999+ 'text': wikitext
 2000+ },
 2001+ 'url': this.local_wiki_api_url
16982002 }, function( data ) {
16992003 callback( data.parse.text['*'] );
17002004 }
17012005 );
17022006 },
1703 - insertResource:function( rObj ) {
1704 - js_log( 'insertResource: ' + rObj.title );
1705 -
1706 - var _this = this
1707 - // dobule check that the resource is present:
1708 - this.checkImportResource( rObj, function() {
1709 - _this.updatePreviewText( rObj );
1710 - $j( _this.target_textbox ).val( _this.preview_wtext );
17112007
 2008+ insertResource: function( resource ) {
 2009+ js_log( 'insertResource: ' + resource.title );
 2010+
 2011+ var _this = this;
 2012+ // double check that the resource is present:
 2013+ this.isFileLocallyAvailable( resource, function( newRes, status ) {
 2014+ if ( status === 'missing' ) {
 2015+ _this.showImportUI( resource, callback );
 2016+ return;
 2017+ }
 2018+
 2019+ $j( _this.target_textbox ).val( _this.getPreviewText( newRes ) );
 2020+ _this.clearTextboxCache();
 2021+
17122022 // update the render area (if present)
1713 - if ( _this.target_render_area && _this.cur_embed_code ) {
 2023+ var embedCode = _this.getEmbedCode( newRes );
 2024+ if ( _this.target_render_area && embedCode ) {
17142025 // output with some padding:
1715 - $j( _this.target_render_area ).append( _this.cur_embed_code + '<div style="clear:both;height:10px">' )
1716 -
 2026+ $j( _this.target_render_area )
 2027+ .append( embedCode + '<div style="clear:both;height:10px">' )
 2028+
17172029 // update the player if video or audio:
1718 - if ( rObj.mime.indexOf( 'audio' ) != -1 ||
1719 - rObj.mime.indexOf( 'video' ) != -1 ||
1720 - rObj.mime.indexOf( '/ogg' ) != -1 ) {
 2030+ if ( newRes.mime.indexOf( 'audio' ) != -1 ||
 2031+ newRes.mime.indexOf( 'video' ) != -1 ||
 2032+ newRes.mime.indexOf( '/ogg' ) != -1 )
 2033+ {
17212034 mvJsLoader.embedVideoCheck( function() {
17222035 mv_video_embed();
17232036 } );
@@ -1725,131 +2038,159 @@
17262039 _this.closeAll();
17272040 } );
17282041 },
1729 - closeAll:function() {
1730 - var _this = this;
1731 - js_log( "close all:: " + _this.target_container );
1732 - _this.cancelClipEditCB();
1733 - // Give a chance for the events to complete
1734 - // (somehow at least in firefox a rare condition occurs where
1735 - // the modal of the edit-box stick around even after the
1736 - // close request has been issued. )
1737 - setTimeout(function(){
1738 - $j( _this.target_container ).dialog( 'close' );
1739 - },10);
 2042+
 2043+ closeAll: function() {
 2044+ var _this = this;
 2045+ js_log( "close all:: " + _this.target_container );
 2046+ _this.onCancelClipEdit();
 2047+ // Give a chance for the events to complete
 2048+ // (somehow at least in firefox a rare condition occurs where
 2049+ // the modal of the edit-box stick around even after the
 2050+ // close request has been issued. )
 2051+ setTimeout(
 2052+ function() {
 2053+ $j( _this.target_container ).dialog( 'close' );
 2054+ }, 10
 2055+ );
17402056 },
1741 - setResultBarControl:function( ) {
 2057+
 2058+ showResultsHeader: function() {
17422059 var _this = this;
1743 - var box_dark_url = mv_skin_img_path + 'box_layout_icon_dark.png';
1744 - var box_light_url = mv_skin_img_path + 'box_layout_icon.png';
1745 - var list_dark_url = mv_skin_img_path + 'list_layout_icon_dark.png';
1746 - var list_light_url = mv_skin_img_path + 'list_layout_icon.png';
 2060+ var darkBoxUrl = mv_skin_img_path + 'box_layout_icon_dark.png';
 2061+ var lightBoxUrl = mv_skin_img_path + 'box_layout_icon.png';
 2062+ var darkListUrl = mv_skin_img_path + 'list_layout_icon_dark.png';
 2063+ var lightListUrl = mv_skin_img_path + 'list_layout_icon.png';
17472064
1748 - var about_desc = '';
1749 - if ( this.content_providers[ this.disp_item ] ) {
1750 - var cp = this.content_providers[this.disp_item];
1751 - about_desc = '<span style="position:relative;top:0px;font-style:italic;">' +
1752 - '<i>' + gM( 'mwe-results_from', [ cp.homepage, gM( 'rsd-' + this.disp_item + '-title' ) ] ) + '</i></span>';
1753 - $j( '#tab-' + this.disp_item ).append( '<div id="rds_results_bar">' +
1754 - '<span style="float:left;top:0px;font-style:italic;">' +
1755 - gM( 'rsd_layout' ) + ' ' +
1756 - '<img id="msc_box_layout" ' +
1757 - 'title = "' + gM( 'rsd_box_layout' ) + '" ' +
1758 - 'src = "' + ( ( _this.result_display_mode == 'box' ) ? box_dark_url:box_light_url ) + '" ' +
1759 - 'style="width:20px;height:20px;cursor:pointer;"> ' +
1760 - '<img id="msc_list_layout" ' +
1761 - 'title = "' + gM( 'rsd_list_layout' ) + '" ' +
1762 - 'src = "' + ( ( _this.result_display_mode == 'list' ) ? list_dark_url:list_light_url ) + '" ' +
1763 - 'style="width:20px;height:20px;cursor:pointer;">' +
1764 - about_desc +
1765 - '</span>' +
1766 - '<span id="rsd_paging_ctrl" style="float:right;"></span>' +
1767 - '</div>'
1768 - );
1769 - // Get paging with bindings:
1770 - this.getPaging( '#rsd_paging_ctrl' );
 2065+ if ( !this.content_providers[ this.currentProvider ] ) {
 2066+ return;
 2067+ }
 2068+ var cp = this.content_providers[this.currentProvider];
 2069+ var resultsFromMsg = gM( 'mwe-results_from',
 2070+ [ cp.homepage, gM( 'rsd-' + this.currentProvider + '-title' ) ] );
 2071+ var defaultBoxUrl, defaultListUrl;
 2072+ if ( _this.displayMode == 'box' ) {
 2073+ defaultBoxUrl = darkBoxUrl;
 2074+ defaultListUrl = lightListUrl;
 2075+ } else {
 2076+ defaultBoxUrl = lightBoxUrl;
 2077+ defaultListUrl = darkListUrl;
 2078+ }
17712079
1772 - $j( '#msc_box_layout' ).hover( function() {
1773 - $j( this ).attr( "src", box_dark_url );
1774 - }, function() {
1775 - $j( this ).attr( "src", ( ( _this.result_display_mode == 'box' ) ? box_dark_url:box_light_url ) );
1776 - } ).click( function() {
1777 - $j( this ).attr( "src", box_dark_url );
1778 - $j( '#msc_list_layout' ).attr( "src", list_light_url );
1779 - _this.setDispMode( 'box' );
 2080+ var about_desc = '<span style="position:relative;top:0px;font-style:italic;">' +
 2081+ '<i>' + resultsFromMsg + '</i></span>';
 2082+
 2083+ $j( '#tab-' + this.currentProvider ).append( '<div id="rds_results_bar">' +
 2084+ '<span style="float:left;top:0px;font-style:italic;">' +
 2085+ gM( 'rsd_layout' ) + ' ' +
 2086+ '<img id="msc_box_layout" ' +
 2087+ 'title = "' + gM( 'rsd_box_layout' ) + '" ' +
 2088+ 'src = "' + defaultBoxUrl + '" ' +
 2089+ 'style="width:20px;height:20px;cursor:pointer;"> ' +
 2090+ '<img id="msc_list_layout" ' +
 2091+ 'title = "' + gM( 'rsd_list_layout' ) + '" ' +
 2092+ 'src = "' + defaultListUrl + '" ' +
 2093+ 'style="width:20px;height:20px;cursor:pointer;">' +
 2094+ about_desc +
 2095+ '</span>' +
 2096+ '<span id="rsd_paging_ctrl" style="float:right;"></span>' +
 2097+ '</div>'
 2098+ );
 2099+
 2100+ // Get paging with bindings:
 2101+ this.showPagingHeader( '#rsd_paging_ctrl' );
 2102+
 2103+ $j( '#msc_box_layout' )
 2104+ .hover(
 2105+ function() {
 2106+ $j( this ).attr( "src", darkBoxUrl );
 2107+ },
 2108+ function() {
 2109+ $j( this ).attr( "src", defaultBoxUrl );
 2110+ } )
 2111+ .click( function() {
 2112+ $j( this ).attr( "src", darkBoxUrl );
 2113+ $j( '#msc_list_layout' ).attr( "src", lightListUrl );
 2114+ _this.setDisplayMode( 'box' );
17802115 } );
17812116
1782 - $j( '#msc_list_layout' ).hover( function() {
1783 - $j( this ).attr( "src", list_dark_url );
1784 - }, function() {
1785 - $j( this ).attr( "src", ( ( _this.result_display_mode == 'list' ) ? list_dark_url:list_light_url ) );
1786 - } ).click( function() {
1787 - $j( this ).attr( "src", list_dark_url );
1788 - $j( '#msc_box_layout' ).attr( "src", box_light_url );
1789 - _this.setDispMode( 'list' );
 2117+ $j( '#msc_list_layout' )
 2118+ .hover(
 2119+ function() {
 2120+ $j( this ).attr( "src", darkListUrl );
 2121+ },
 2122+ function() {
 2123+ $j( this ).attr( "src", defaultListUrl );
 2124+ } )
 2125+ .click( function() {
 2126+ $j( this ).attr( "src", darkListUrl );
 2127+ $j( '#msc_box_layout' ).attr( "src", lightBoxUrl );
 2128+ _this.setDisplayMode( 'list' );
17902129 } );
1791 - }
17922130 },
1793 - getPaging:function( target ) {
 2131+
 2132+ showPagingHeader: function( target ) {
17942133 var _this = this;
1795 - var cp_id = this.disp_item;
1796 - if ( this.disp_item == 'upload' ) {
1797 - var cp = _this.content_providers['this_wiki'];
 2134+ if ( _this.currentProvider == 'upload' ) {
 2135+ var provider = _this.content_providers['this_wiki'];
17982136 } else {
1799 - var cp = this.content_providers[ this.disp_item ];
 2137+ var provider = _this.content_providers[ _this.currentProvider ];
18002138 }
1801 - js_log( 'getPaging:' + cp_id + ' len: ' + cp.sObj.num_results );
1802 - var to_num = ( cp.limit > cp.sObj.num_results ) ?
1803 - ( parseInt( cp.offset ) + parseInt( cp.sObj.num_results ) ):
1804 - ( parseInt( cp.offset ) + parseInt( cp.limit ) );
 2139+ var search = provider.sObj;
 2140+ js_log( 'showPagingHeader:' + _this.currentProvider + ' len: ' + search.num_results );
 2141+ var to_num = ( provider.limit > search.num_results ) ?
 2142+ ( parseInt( provider.offset ) + parseInt( search.num_results ) ) :
 2143+ ( parseInt( provider.offset ) + parseInt( provider.limit ) );
18052144 var out = '';
1806 -
 2145+
18072146 // @@todo we should instead support the wiki number format template system instead of inline calls
1808 - if ( cp.sObj.num_results != 0 ) {
1809 - if ( cp.sObj.num_results > cp.limit ) {
1810 - out += gM( 'rsd_results_desc_total', [( cp.offset + 1 ), to_num, mw.lang.formatNumber( cp.sObj.num_results )] );
 2147+ if ( search.num_results != 0 ) {
 2148+ if ( search.num_results > provider.limit ) {
 2149+ out += gM( 'rsd_results_desc_total', [( provider.offset + 1 ), to_num,
 2150+ mw.lang.formatNumber( search.num_results )] );
18112151 } else {
1812 - out += gM( 'rsd_results_desc', [( cp.offset + 1 ), to_num] );
 2152+ out += gM( 'rsd_results_desc', [( provider.offset + 1 ), to_num] );
18132153 }
18142154 }
18152155 // check if we have more results (next prev link)
1816 - if ( cp.offset >= cp.limit )
1817 - out += ' <a href="#" id="rsd_pprev">' + gM( 'rsd_results_prev' ) + ' ' + cp.limit + '</a>';
 2156+ if ( provider.offset >= provider.limit ) {
 2157+ out += ' <a href="#" id="rsd_pprev">' + gM( 'rsd_results_prev' ) + ' ' + provider.limit + '</a>';
 2158+ }
18182159
1819 - if ( cp.sObj.more_results )
1820 - out += ' <a href="#" id="rsd_pnext">' + gM( 'rsd_results_next' ) + ' ' + cp.limit + '</a>';
 2160+ if ( search.more_results ) {
 2161+ out += ' <a href="#" id="rsd_pnext">' + gM( 'rsd_results_next' ) + ' ' + provider.limit + '</a>';
 2162+ }
18212163
18222164 $j( target ).html( out );
1823 -
 2165+
18242166 // set bindings
18252167 $j( '#rsd_pnext' ).click( function() {
1826 - cp.offset += cp.limit;
1827 - _this.runSearch( false );
 2168+ provider.offset += provider.limit;
 2169+ _this.showCurrentTab();
18282170 } );
1829 -
 2171+
18302172 $j( '#rsd_pprev' ).click( function() {
1831 - cp.offset -= cp.limit;
1832 - if ( cp.offset < 0 )
1833 - cp.offset = 0;
1834 - _this.runSearch( false );
 2173+ provider.offset -= provider.limit;
 2174+ if ( provider.offset < 0 )
 2175+ provider.offset = 0;
 2176+ _this.showCurrentTab();
18352177 } );
 2178+ },
18362179
1837 - return;
1838 -
1839 - },
1840 - selectTab:function( selected_cp_id ) {
1841 - js_log( 'select tab: ' + selected_cp_id );
1842 - this.disp_item = selected_cp_id;
1843 - if ( this.disp_item == 'upload' ) {
1844 - this.doUploadInteface();
 2180+ selectTab: function( provider ) {
 2181+ js_log( 'select tab: ' + provider );
 2182+ this.currentProvider = provider;
 2183+ if ( this.currentProvider == 'upload' ) {
 2184+ this.showUploadTab();
18452185 } else {
18462186 // update the search results:
1847 - this.runSearch();
 2187+ this.showCurrentTab();
18482188 }
18492189 },
1850 - setDispMode:function( mode ) {
1851 - js_log( 'setDispMode:' + mode );
1852 - this.result_display_mode = mode;
 2190+
 2191+ setDisplayMode: function( mode ) {
 2192+ js_log( 'setDisplayMode:' + mode );
 2193+ this.displayMode = mode;
18532194 // run /update search display:
1854 - this.drawOutputResults();
 2195+ this.showResults();
18552196 }
18562197 };
Index: trunk/phase3/js2/mwEmbed/libAddMedia/simpleUploadForm.js
@@ -6,9 +6,9 @@
77
88 loadGM( {
99 "mwe-select_file" : "Select file",
10 - "mwe-more_licence_options" : "For more licence options, view the <a href=\"$1\">normal upload page<\/a>",
 10+ "mwe-more_license_options" : "For more license options, view the <a href=\"$1\">normal upload page<\/a>",
1111 "mwe-select_ownwork" : "I am uploading entirely my own work, and licencing it under:",
12 - "mwe-licence_cc-by-sa" : "Creative Commons Share Alike (3.0)",
 12+ "mwe-license_cc-by-sa" : "Creative Commons Share Alike (3.0)",
1313 "mwe-upload" : "Upload file",
1414 "mwe-destfilename" : "Destination filename:",
1515 "mwe-summary" : "Summary",
@@ -19,7 +19,7 @@
2020
2121 var default_form_options = {
2222 'enable_fogg' : true,
23 - 'licence_options' : ['cc-by-sa'],
 23+ 'license_options': ['cc-by-sa'],
2424 'api_target' : false,
2525 'ondone_cb' : null
2626 };
@@ -75,7 +75,7 @@
7676 '<div style="clear:both;"></div>' + '<p>' +
7777
7878 gM( 'mwe-select_ownwork' ) + '<br>' +
79 - '<input type="checkbox" id="wpLicence" name="wpLicence" value="cc-by-sa">' + gM( 'mwe-licence_cc-by-sa' ) + '</p>' +
 79+ '<input type="checkbox" id="wpLicence" name="wpLicence" value="cc-by-sa">' + gM( 'mwe-license_cc-by-sa' ) + '</p>' +
8080
8181 '<input type="submit" accesskey="s" value="' + gM( 'mwe-upload' ) + '" name="wpUploadBtn" id="wpUploadBtn" tabindex="9"/>' +
8282 // close the form and div
@@ -87,7 +87,7 @@
8888 // by default dissable:
8989 $j( '#wpUploadBtn' ).attr( 'disabled', 'disabled' );
9090
91 - // set up basic licence binding:
 91+ // set up basic license binding:
9292 $j( '#wpLicence' ).click( function() {
9393 if ( $j( this ).is( ':checked' ) ) {
9494 $j( '#wpUploadBtn' ).removeAttr( 'disabled' );
Index: trunk/phase3/js2/mwEmbed/libSequencer/mvSequencer.js
@@ -160,7 +160,7 @@
161161 'seqRemoteSearchDriver'
162162 ], function() {
163163 this_seq.mySearch = new seqRemoteSearchDriver( this_seq );
164 - this_seq.mySearch.doInitDisplay();
 164+ this_seq.mySearch.createUI();
165165 } );
166166 }
167167 },
Index: trunk/phase3/js2/mwEmbed/mv_embed.js
@@ -1355,7 +1355,7 @@
13561356 js_log( ".addMediaWiz call" );
13571357 // check if already loaded:
13581358 if ( _global['rsdMVRS'] ) {
1359 - _global['rsdMVRS'].doReDisplay();
 1359+ _global['rsdMVRS'].showDialog();
13601360 if ( callback )
13611361 callback( _global['rsdMVRS'] );
13621362 return ;
@@ -1367,7 +1367,7 @@
13681368 // close the dialog
13691369 $.closeLoaderDialog();
13701370 // do the add-media-wizard display
1371 - amwObj.doInitDisplay();
 1371+ amwObj.createUI();
13721372 // call the parent callback:
13731373 if ( callback )
13741374 callback( _global['rsdMVRS'] );
@@ -1378,7 +1378,7 @@
13791379 // First set the cursor for the button to "loading"
13801380 $j( this.selector ).css( 'cursor', 'wait' ).attr( 'title', gM( 'mwe-loading_txt' ) );
13811381 // set the target:
1382 - iObj['target_invocation'] = this.selector;
 1382+ iObj['target_invoke_button'] = this.selector;
13831383 }
13841384
13851385 // Load the mv_embed_base skin:

Follow-up revisions

RevisionCommit summaryAuthorDate
r59643* fixed most of the regressions of r59439 ( probably not all of them as there...dale21:53, 1 December 2009
r59717* moved embedVideo to embedPlayer ( more embedPlayer clean up remains to be ...dale00:40, 4 December 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r59278Rework of libAddMedia. The changes are entirely untested and there may be bug...tstarling07:23, 20 November 2009

Comments

#Comment by Mdale (talk | contribs)   23:08, 1 December 2009

fixed most of the re factor regressions in r59643

Status & tagging log