Index: trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js |
— | — | @@ -5,11 +5,13 @@ |
6 | 6 | */ |
7 | 7 | |
8 | 8 | function QuoteTransformer ( ) { |
9 | | - this.quoteAndNewlineRank = 2.1; |
10 | | - this.anyRank = 2.101; // Just after regular quote and newline |
11 | 9 | this.reset(); |
12 | 10 | } |
13 | 11 | |
| 12 | +// constants |
| 13 | +QuoteTransformer.prototype.quoteAndNewlineRank = 2.1; |
| 14 | +QuoteTransformer.prototype.anyRank = 2.101; // Just after regular quote and newline |
| 15 | + |
14 | 16 | QuoteTransformer.prototype.reset = function ( ) { |
15 | 17 | // A chunk starts with a token context around a quote token and is |
16 | 18 | // (optionally) followed by non-quote tokens. The quote token and its |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js |
— | — | @@ -29,6 +29,8 @@ |
30 | 30 | this.parser = PEG.buildParser(this.src); |
31 | 31 | // add reference to this for event emission |
32 | 32 | this.parser._tokenizer = this; |
| 33 | + // Print the generated parser source |
| 34 | + //console.log(this.parser.toSource()); |
33 | 35 | } |
34 | 36 | |
35 | 37 | // some normalization |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js |
— | — | @@ -2,8 +2,11 @@ |
3 | 3 | * Template and template argument handling. |
4 | 4 | * |
5 | 5 | * @author Gabriel Wicke <gwicke@wikimedia.org> |
| 6 | + * @author Brion Vibber <brion@wikimedia.org> |
6 | 7 | */ |
| 8 | +var $ = require('jquery'); |
7 | 9 | |
| 10 | + |
8 | 11 | function TemplateHandler () { |
9 | 12 | this.reset(); |
10 | 13 | } |
— | — | @@ -129,14 +132,62 @@ |
130 | 133 | }; |
131 | 134 | |
132 | 135 | |
| 136 | +/** |
| 137 | + * Fetch a template |
| 138 | + */ |
| 139 | +TemplateHandler.prototype._fetchTemplateAndTitle = function( title, frame, callback ) { |
| 140 | + // @fixme normalize name? |
| 141 | + if (title in this.pageCache) { |
| 142 | + // @fixme should this be forced to run on next event? |
| 143 | + callback( this.pageCache[title], title ); |
| 144 | + } else { |
| 145 | + // whee fun hack! |
| 146 | + console.log(title); |
| 147 | + console.log(this.pageCache); |
| 148 | + $.ajax({ |
| 149 | + url: frame.env.wgScriptPath + '/api' + frame.env.wgScriptExtension, |
| 150 | + data: { |
| 151 | + format: 'json', |
| 152 | + action: 'query', |
| 153 | + prop: 'revisions', |
| 154 | + rvprop: 'content', |
| 155 | + titles: name |
| 156 | + }, |
| 157 | + success: function(data, xhr) { |
| 158 | + var src = null, title = null; |
| 159 | + $.each(data.query.pages, function(i, page) { |
| 160 | + if (page.revisions && page.revisions.length) { |
| 161 | + src = page.revisions[0]['*']; |
| 162 | + title = page.title; |
| 163 | + } |
| 164 | + }); |
| 165 | + if (typeof src !== 'string') { |
| 166 | + callback(null, null, 'Page not found'); |
| 167 | + } else { |
| 168 | + callback(src, title); |
| 169 | + } |
| 170 | + }, |
| 171 | + error: function(msg) { |
| 172 | + callback(null, null, 'Page/template fetch failure'); |
| 173 | + }, |
| 174 | + dataType: 'json', |
| 175 | + cache: false // @fixme caching, versions etc? |
| 176 | + }, 'json'); |
| 177 | + } |
| 178 | +}; |
| 179 | + |
| 180 | + |
133 | 181 | TemplateHandler.prototype.onTemplateArg = function ( token, cb, frame ) { |
134 | 182 | var argName = token.attribs[0][1]; // XXX: do this properly! |
135 | 183 | if ( argName in frame.args ) { |
136 | 184 | // return tokens for argument |
137 | 185 | return { tokens: frame.args[argName] }; |
138 | 186 | } else { |
139 | | - // FIXME: support default value! |
140 | | - return { token: { type: 'TEXT', value: '' } }; |
| 187 | + if ( token.attribs.length > 1 ) { |
| 188 | + return token.attribs[1][1]; // default value, XXX: use key |
| 189 | + } else { |
| 190 | + return { token: { type: 'TEXT', value: '{{{' + argName + '}}}' } }; |
| 191 | + } |
141 | 192 | } |
142 | 193 | }; |
143 | 194 | |
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt |
— | — | @@ -405,7 +405,7 @@ |
406 | 406 | //b.push({type: 'NEWLINE'}); |
407 | 407 | // Move this to a token stream transform! |
408 | 408 | //console.log('about to emit' + pp(self)); |
409 | | - console.log( pp( result._tokenizer )); |
| 409 | + //console.log( pp( result._tokenizer )); |
410 | 410 | //console.log('emitted chunk' + pp(b)); |
411 | 411 | //return []; |
412 | 412 | return b; |
— | — | @@ -738,6 +738,7 @@ |
739 | 739 | }; |
740 | 740 | if (params && params.length) { |
741 | 741 | // HACK, not final. |
| 742 | + obj.attribs.push(['data-defaultvalue', params[0][1]]); |
742 | 743 | obj.attribs.push(['data-json-args', JSON.stringify(params)]); |
743 | 744 | } |
744 | 745 | return obj; |