Index: trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | "en_empty": "", |
7 | 7 | "en_simple": "Simple message", |
8 | 8 | "en_replace": "Simple $1 replacement", |
| 9 | + "en_replace2": "Simple $1 $2 replacements", |
9 | 10 | "en_link": "Simple [http://example.com link to example].", |
10 | 11 | "en_link_replace": "Complex [$1 $2] behaviour.", |
11 | 12 | "en_simple_magic": "Simple {{ALOHOMORA}} message", |
— | — | @@ -63,6 +64,12 @@ |
64 | 65 | expect( parser.parse( 'en_replace', [ 'foo' ] ).html() ).toEqual( 'Simple foo replacement' ); |
65 | 66 | } ); |
66 | 67 | |
| 68 | + it ( "should return $n if replacement not there", function() { |
| 69 | + var parser = new mediaWiki.language.parser(); |
| 70 | + expect( parser.parse( 'en_replace', [] ).html() ).toEqual( 'Simple $1 replacement' ); |
| 71 | + expect( parser.parse( 'en_replace2', [ 'bar' ] ).html() ).toEqual( 'Simple bar $2 replacements' ); |
| 72 | + } ); |
| 73 | + |
67 | 74 | } ); |
68 | 75 | |
69 | 76 | describe( "linking", function() { |
— | — | @@ -157,9 +164,9 @@ |
158 | 165 | } ); |
159 | 166 | |
160 | 167 | describe( "error conditions", function() { |
161 | | - it( "should return non-existent key in angle brackets", function() { |
| 168 | + it( "should return non-existent key in square brackets", function() { |
162 | 169 | var parser = new mediaWiki.language.parser(); |
163 | | - expect( parser.parse( 'en_does_not_exist' ).html() ).toEqual( '<en_does_not_exist>' ); |
| 170 | + expect( parser.parse( 'en_does_not_exist' ).html() ).toEqual( '[en_does_not_exist]' ); |
164 | 171 | } ); |
165 | 172 | |
166 | 173 | |
Index: trunk/extensions/UploadWizard/resources/mediawiki.language.parser.js |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * |
13 | 13 | * @param {Integer} first offset where one finds the variadic args |
14 | 14 | * @param {Array} all arguments from caller |
15 | | - * @param {Array} array of arguments desired, whether were variadic or not |
| 15 | + * @return {Array} array of arguments desired, whether were variadic or not |
16 | 16 | */ |
17 | 17 | function getVariadicArgs( args, offset ) { |
18 | 18 | return $j.isArray( args[offset] ) ? args[offset] : $j.makeArray( args ).slice( offset ); |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | var parser = new mw.language.parser( options ); |
84 | 84 | /** |
85 | 85 | * Note replacements are gleaned from 2nd parameter, or variadic args starting with 2nd parameter. |
86 | | - * There is no return; we append to 'this', which in a jQuery plugin context will be the selected elements. |
| 86 | + * We append to 'this', which in a jQuery plugin context will be the selected elements. |
87 | 87 | * @param {String} message key |
88 | 88 | * @param {Array} optional replacements (can also specify variadically) |
89 | 89 | * @return {jQuery} this |
— | — | @@ -211,11 +211,14 @@ |
212 | 212 | /** |
213 | 213 | * Fetch the message string associated with a key, return parsed structure. Memoized. |
214 | 214 | * @param {String} key |
215 | | - * @return {Mixed} abstract syntax tree (array of arrays...) |
| 215 | + * @return {String|Array} simple string if message is simple, array of arrays if needs parsing |
216 | 216 | */ |
217 | 217 | getAst: function( key ) { |
218 | 218 | if ( typeof this.astCache[ key ] === 'undefined' ) { |
219 | 219 | var wikiText = this.settings.messages.get( key ); |
| 220 | + if ( wikiText === null ) { |
| 221 | + wikiText = "\\[" + key + "\\]"; |
| 222 | + } |
220 | 223 | this.astCache[ key ] = this.wikiTextToAst( wikiText ); |
221 | 224 | } |
222 | 225 | return this.astCache[ key ]; |