r57627 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57626‎ | r57627 | r57628 >
Date:21:00, 10 October 2009
Author:dale
Status:deferred
Tags:
Comment:
* added in regExp for grabbing user-language initial in-line description from commons templates
Modified paths:
  • /trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js (modified) (history)

Diff [purge]

Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js
@@ -175,12 +175,39 @@
176176 'meta':{
177177 'categories':page.categories
178178 }
179 - };
180 - //attempt to parse out some stuff from the template:
181 - var desc = rObj.desc.match(/\|Description\s*=\s*(([^\n]*\n)*)\|Source=/)
 179+ };
 180+ /*
 181+ //to use once we get the wiki-text parser in shape
 182+ var pObj = $mw.parser.pNew( rObj.desc );
 183+ //structured data on commons is based on the "information" template:
 184+ var tmplInfo = pObj.templates( 'information' );
 185+ */
 186+
 187+ //attempt to parse out the description current user desc from the commons template:
 188+ //@@todo these could be combined to a single regEx
 189+ // or better improve the wiki-text parsing and use above
 190+ var desc = rObj.desc.match(/\|\s*description\s*=\s*(([^\n]*\n)*)\|\s*source=/i);
182191 if( desc && desc[1] ){
183192 rObj.desc = $j.trim( desc[1] );
184 - }
 193+ var cat = wgUserLanguage;
 194+ //attempt to get the user language if set:
 195+ if( wgUserLanguage ){
 196+ //for some reason the RegExp object is not happy:
 197+ var reg = new RegExp( '\{\{\s*' + wgUserLanguage + '([^=]*)=([^\}]*)\}\}', 'gim' );
 198+ var langMatch = reg.exec( rObj.desc );
 199+ if(langMatch && langMatch[2]){
 200+ rObj.desc = langMatch[2];
 201+ }else{
 202+ //try simple lang template form:
 203+ var reg = new RegExp( '\{\{\s*' + wgUserLanguage + '\\|([^\}]*)\}\}', 'gim' );
 204+ var langMatch = reg.exec( rObj.desc );
 205+ if(langMatch && langMatch[1]){
 206+ rObj.desc = langMatch[1];
 207+ }
 208+ }
 209+ }
 210+ }
 211+
185212 //likely a audio clip if no poster and type application/ogg
186213 //@@todo we should return audio/ogg for the mime type or some other way to specify its "audio"
187214 if( ! rObj.poster && rObj.mime == 'application/ogg' ){

Status & tagging log