Index: branches/MwEmbedStandAlone/modules/AddMedia/searchLibs/mediaWikiSearch.js |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | /** |
27 | 27 | * Adds a resource by its Title |
28 | 28 | * |
29 | | - * @param {String} title Title of the resource to be added |
| 29 | + * @param {String} title Title of the resource to be added (in the form of a wgPageName) |
30 | 30 | * @param {Function} callback Function called once title resource acquired |
31 | 31 | */ |
32 | 32 | getByTitle:function( title , callback ) { |
— | — | @@ -47,7 +47,13 @@ |
48 | 48 | callback( _this.addSingleResult( data ) ); |
49 | 49 | }); |
50 | 50 | }, |
51 | | - |
| 51 | + |
| 52 | + /** |
| 53 | + * Add a resource by its Url |
| 54 | + * |
| 55 | + * @param {String} url The url of the resource to be added |
| 56 | + * @param {Function} callback Function called once the resource is acquired |
| 57 | + */ |
52 | 58 | getResourceFromUrl: function( url, callback ){ |
53 | 59 | var title = this.getTitleKeyFromMwUrl( url ); |
54 | 60 | if( !title) { |
— | — | @@ -56,21 +62,25 @@ |
57 | 63 | } |
58 | 64 | this.getByTitle(title , callback ); |
59 | 65 | }, |
| 66 | + |
60 | 67 | /** |
61 | | - * Does best effort to get the title key from a mediawiki url |
| 68 | + * Does best effort to get the title key from a mediawiki url |
| 69 | + * |
| 70 | + * @param {String} url The url for which we want to find the title |
| 71 | + * @return {String} The title in a form that should mirror wgPageName |
62 | 72 | */ |
63 | 73 | getTitleKeyFromMwUrl: function( url ){ |
64 | 74 | // try for title key param |
65 | 75 | var titleKey = mw.parseUri( url ).queryKey['title']; |
66 | 76 | if( titleKey ){ |
67 | | - return titleKey; |
| 77 | + return decodeURIComponent( titleKey ).replace( / /g, "_"); |
68 | 78 | } |
69 | 79 | // else try for title url map |
70 | 80 | titleKey = url.replace( this.provider.detailsUrl.replace( '$1', ''), '' ); |
71 | 81 | if( titleKey != url ){ |
72 | | - return titleKey; |
| 82 | + return decodeURI(titleKey).replace( / /g, "_" );; |
73 | 83 | } |
74 | | - mw.log("Error: mediaWikiSearch:: getResourceFromUrl could not get title form url: " + url ); |
| 84 | + mw.log("Error: mediaWikiSearch:: getResourceFromUrl could not get title from url: " + url ); |
75 | 85 | return false; |
76 | 86 | }, |
77 | 87 | |
— | — | @@ -184,35 +194,30 @@ |
185 | 195 | if ( data.query && data.query.pages ) { |
186 | 196 | for ( var page_id in data.query.pages ) { |
187 | 197 | var page = data.query.pages[ page_id ]; |
188 | | - |
| 198 | + |
189 | 199 | // Make sure the repo is shared (don't show for now it confusing things) |
190 | 200 | // @@todo support remote repository better |
191 | 201 | if ( page.imagerepository == 'shared' ) { |
192 | 202 | continue; |
193 | 203 | } |
194 | | - |
| 204 | + |
195 | 205 | // Skip if its an empty or missing imageinfo: |
196 | 206 | if ( !page.imageinfo ){ |
197 | 207 | continue; |
198 | 208 | } |
199 | | - |
| 209 | + |
200 | 210 | // Get the url safe titleKey from the descriptionurl |
201 | | - var titleKey = page.imageinfo[0].descriptionurl.split( '/' ) |
202 | | - ; |
203 | | - titleKey = unescape( |
204 | | - titleKey[ titleKey.length - 1 ] |
205 | | - .replace( 'index.php?title=', '') |
206 | | - ); |
207 | | - |
| 211 | + var titleKey = page.title.replace( / /g, "_" ); |
| 212 | + |
208 | 213 | var resource = { |
209 | 214 | 'id' : page_id, |
210 | 215 | 'titleKey' : titleKey, |
211 | 216 | 'link' : page.imageinfo[0].descriptionurl, |
212 | 217 | 'title' : page.title.replace(/Image:|File:|.jpg|.png|.svg|.ogg|.ogv|.oga/ig, ''), |
213 | 218 | 'poster' : page.imageinfo[0].thumburl, |
214 | | - 'thumbwidth' : page.imageinfo[0].thumbwidth, |
215 | | - 'thumbheight': page.imageinfo[0].thumbheight, |
216 | | - 'width' : page.imageinfo[0].width, |
| 219 | + 'thumbwidth' : page.imageinfo[0].thumbwidth, |
| 220 | + 'thumbheight' : page.imageinfo[0].thumbheight, |
| 221 | + 'width' : page.imageinfo[0].width, |
217 | 222 | 'height' : page.imageinfo[0].height, |
218 | 223 | 'mime' : page.imageinfo[0].mime, |
219 | 224 | 'src' : page.imageinfo[0].url, |