Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js |
— | — | @@ -175,12 +175,39 @@ |
176 | 176 | 'meta':{ |
177 | 177 | 'categories':page.categories |
178 | 178 | } |
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); |
182 | 191 | if( desc && desc[1] ){ |
183 | 192 | 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 | + |
185 | 212 | //likely a audio clip if no poster and type application/ogg |
186 | 213 | //@@todo we should return audio/ogg for the mime type or some other way to specify its "audio" |
187 | 214 | if( ! rObj.poster && rObj.mime == 'application/ogg' ){ |