Merge "Initial JSDuck implementation"
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.js
index 73d5635..b5b42e1 100644 (file)
@@ -125,7 +125,7 @@ var mw = ( function ( $, undefined ) {
         * @param {Array} [parameters]
         */
        function Message( map, key, parameters ) {
-               this.format = 'plain';
+               this.format = 'text';
                this.map = map;
                this.key = key;
                this.parameters = parameters === undefined ? [] : slice.call( parameters );
@@ -134,9 +134,13 @@ var mw = ( function ( $, undefined ) {
 
        Message.prototype = {
                /**
-                * Simple message parser, does $N replacement and nothing else.
+                * Simple message parser, does $N replacement, HTML-escaping (only for
+                * 'escaped' format), and nothing else.
+                *
                 * This may be overridden to provide a more complex message parser.
                 *
+                * The primary override is in mediawiki.jqueryMsg.
+                *
                 * This function will not be called for nonexistent messages.
                 */
                parser: function () {
@@ -171,18 +175,14 @@ var mw = ( function ( $, undefined ) {
 
                        if ( !this.exists() ) {
                                // Use <key> as text if key does not exist
-                               if ( this.format !== 'plain' ) {
-                                       // format 'escape' and 'parse' need to have the brackets and key html escaped
+                               if ( this.format === 'escaped' || this.format === 'parse' ) {
+                                       // format 'escaped' and 'parse' need to have the brackets and key html escaped
                                        return mw.html.escape( '<' + this.key + '>' );
                                }
                                return '<' + this.key + '>';
                        }
 
-                       if ( this.format === 'plain' ) {
-                               // @todo FIXME: Although not applicable to core Message,
-                               // Plugins like jQueryMsg should be able to distinguish
-                               // between 'plain' (only variable replacement and plural/gender)
-                               // and actually parsing wikitext to HTML.
+                       if ( this.format === 'plain' || this.format === 'text' || this.format === 'parse' ) {
                                text = this.parser();
                        }
 
@@ -191,15 +191,16 @@ var mw = ( function ( $, undefined ) {
                                text = mw.html.escape( text );
                        }
 
-                       if ( this.format === 'parse' ) {
-                               text = this.parser();
-                       }
-
                        return text;
                },
 
                /**
-                * Changes format to parse and converts message to string
+                * Changes format to 'parse' and converts message to string
+                *
+                * If jqueryMsg is loaded, this parses the message text from wikitext
+                * (where supported) to HTML
+                *
+                * Otherwise, it is equivalent to plain.
                 *
                 * @return {string} String form of parsed message
                 */
@@ -209,7 +210,10 @@ var mw = ( function ( $, undefined ) {
                },
 
                /**
-                * Changes format to plain and converts message to string
+                * Changes format to 'plain' and converts message to string
+                *
+                * This substitutes parameters, but otherwise does not change the
+                * message text.
                 *
                 * @return {string} String form of plain message
                 */
@@ -219,7 +223,23 @@ var mw = ( function ( $, undefined ) {
                },
 
                /**
-                * Changes the format to html escaped and converts message to string
+                * Changes format to 'text' and converts message to string
+                *
+                * If jqueryMsg is loaded, {{-transformation is done where supported
+                * (such as {{plural:}}, {{gender:}}, {{int:}}).
+                *
+                * Otherwise, it is equivalent to plain.
+                */
+               text: function () {
+                       this.format = 'text';
+                       return this.toString();
+               },
+
+               /**
+                * Changes the format to 'escaped' and converts message to string
+                *
+                * This is equivalent to using the 'text' format (see text method), then
+                * HTML-escaping the output.
                 *
                 * @return {string} String form of html escaped message
                 */