From 45b004133b925ea51de055cf8777e9be2474c2b5 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Sat, 10 Oct 2009 21:00:55 +0000 Subject: [PATCH] * added in regExp for grabbing user-language initial in-line description from commons templates --- .../libAddMedia/searchLibs/mediaWikiSearch.js | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js b/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js index 5fbbca36a2..489dbea308 100644 --- a/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js +++ b/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js @@ -175,12 +175,39 @@ mediaWikiSearch.prototype = { 'meta':{ 'categories':page.categories } - }; - //attempt to parse out some stuff from the template: - var desc = rObj.desc.match(/\|Description\s*=\s*(([^\n]*\n)*)\|Source=/) + }; + /* + //to use once we get the wiki-text parser in shape + var pObj = $mw.parser.pNew( rObj.desc ); + //structured data on commons is based on the "information" template: + var tmplInfo = pObj.templates( 'information' ); + */ + + //attempt to parse out the description current user desc from the commons template: + //@@todo these could be combined to a single regEx + // or better improve the wiki-text parsing and use above + var desc = rObj.desc.match(/\|\s*description\s*=\s*(([^\n]*\n)*)\|\s*source=/i); if( desc && desc[1] ){ rObj.desc = $j.trim( desc[1] ); - } + var cat = wgUserLanguage; + //attempt to get the user language if set: + if( wgUserLanguage ){ + //for some reason the RegExp object is not happy: + var reg = new RegExp( '\{\{\s*' + wgUserLanguage + '([^=]*)=([^\}]*)\}\}', 'gim' ); + var langMatch = reg.exec( rObj.desc ); + if(langMatch && langMatch[2]){ + rObj.desc = langMatch[2]; + }else{ + //try simple lang template form: + var reg = new RegExp( '\{\{\s*' + wgUserLanguage + '\\|([^\}]*)\}\}', 'gim' ); + var langMatch = reg.exec( rObj.desc ); + if(langMatch && langMatch[1]){ + rObj.desc = langMatch[1]; + } + } + } + } + //likely a audio clip if no poster and type application/ogg //@@todo we should return audio/ogg for the mime type or some other way to specify its "audio" if( ! rObj.poster && rObj.mime == 'application/ogg' ){ -- 2.20.1