r83193 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83192‎ | r83193 | r83194 >
Date:00:39, 4 March 2011
Author:neilk
Status:deferred
Tags:
Comment:
fixed error messages for missing strings
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mediawiki.language.parser.js (modified) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js
@@ -5,6 +5,7 @@
66 "en_empty": "",
77 "en_simple": "Simple message",
88 "en_replace": "Simple $1 replacement",
 9+ "en_replace2": "Simple $1 $2 replacements",
910 "en_link": "Simple [http://example.com link to example].",
1011 "en_link_replace": "Complex [$1 $2] behaviour.",
1112 "en_simple_magic": "Simple {{ALOHOMORA}} message",
@@ -63,6 +64,12 @@
6465 expect( parser.parse( 'en_replace', [ 'foo' ] ).html() ).toEqual( 'Simple foo replacement' );
6566 } );
6667
 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+
6774 } );
6875
6976 describe( "linking", function() {
@@ -157,9 +164,9 @@
158165 } );
159166
160167 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() {
162169 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]' );
164171 } );
165172
166173
Index: trunk/extensions/UploadWizard/resources/mediawiki.language.parser.js
@@ -11,7 +11,7 @@
1212 *
1313 * @param {Integer} first offset where one finds the variadic args
1414 * @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
1616 */
1717 function getVariadicArgs( args, offset ) {
1818 return $j.isArray( args[offset] ) ? args[offset] : $j.makeArray( args ).slice( offset );
@@ -82,7 +82,7 @@
8383 var parser = new mw.language.parser( options );
8484 /**
8585 * 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.
8787 * @param {String} message key
8888 * @param {Array} optional replacements (can also specify variadically)
8989 * @return {jQuery} this
@@ -211,11 +211,14 @@
212212 /**
213213 * Fetch the message string associated with a key, return parsed structure. Memoized.
214214 * @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
216216 */
217217 getAst: function( key ) {
218218 if ( typeof this.astCache[ key ] === 'undefined' ) {
219219 var wikiText = this.settings.messages.get( key );
 220+ if ( wikiText === null ) {
 221+ wikiText = "\\[" + key + "\\]";
 222+ }
220223 this.astCache[ key ] = this.wikiTextToAst( wikiText );
221224 }
222225 return this.astCache[ key ];

Status & tagging log