r75042 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75041‎ | r75042 | r75043 >
Date:21:24, 19 October 2010
Author:hartman
Status:deferred
Tags:
Comment:
Cleanup some URI encoding issues in the mediawiki search. titleKeys are now always supposed to be in normalize wgPageName form.
Modified paths:
  • /branches/MwEmbedStandAlone/modules/AddMedia/searchLibs/mediaWikiSearch.js (modified) (history)

Diff [purge]

Index: branches/MwEmbedStandAlone/modules/AddMedia/searchLibs/mediaWikiSearch.js
@@ -25,7 +25,7 @@
2626 /**
2727 * Adds a resource by its Title
2828 *
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)
3030 * @param {Function} callback Function called once title resource acquired
3131 */
3232 getByTitle:function( title , callback ) {
@@ -47,7 +47,13 @@
4848 callback( _this.addSingleResult( data ) );
4949 });
5050 },
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+ */
5258 getResourceFromUrl: function( url, callback ){
5359 var title = this.getTitleKeyFromMwUrl( url );
5460 if( !title) {
@@ -56,21 +62,25 @@
5763 }
5864 this.getByTitle(title , callback );
5965 },
 66+
6067 /**
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
6272 */
6373 getTitleKeyFromMwUrl: function( url ){
6474 // try for title key param
6575 var titleKey = mw.parseUri( url ).queryKey['title'];
6676 if( titleKey ){
67 - return titleKey;
 77+ return decodeURIComponent( titleKey ).replace( / /g, "_");
6878 }
6979 // else try for title url map
7080 titleKey = url.replace( this.provider.detailsUrl.replace( '$1', ''), '' );
7181 if( titleKey != url ){
72 - return titleKey;
 82+ return decodeURI(titleKey).replace( / /g, "_" );;
7383 }
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 );
7585 return false;
7686 },
7787
@@ -184,35 +194,30 @@
185195 if ( data.query && data.query.pages ) {
186196 for ( var page_id in data.query.pages ) {
187197 var page = data.query.pages[ page_id ];
188 -
 198+
189199 // Make sure the repo is shared (don't show for now it confusing things)
190200 // @@todo support remote repository better
191201 if ( page.imagerepository == 'shared' ) {
192202 continue;
193203 }
194 -
 204+
195205 // Skip if its an empty or missing imageinfo:
196206 if ( !page.imageinfo ){
197207 continue;
198208 }
199 -
 209+
200210 // 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+
208213 var resource = {
209214 'id' : page_id,
210215 'titleKey' : titleKey,
211216 'link' : page.imageinfo[0].descriptionurl,
212217 'title' : page.title.replace(/Image:|File:|.jpg|.png|.svg|.ogg|.ogv|.oga/ig, ''),
213218 '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,
217222 'height' : page.imageinfo[0].height,
218223 'mime' : page.imageinfo[0].mime,
219224 'src' : page.imageinfo[0].url,

Status & tagging log