r113353 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113352‎ | r113353 | r113354 >
Date:10:03, 8 March 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Improvements for image option handling.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/parse.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/parse.js
@@ -50,7 +50,7 @@
5151 wgScriptPath: argv.wgScriptPath,
5252 wgScriptExtension: argv.wgScriptExtension,
5353 // XXX: add options for this!
54 - wgUploadPath: 'http://upload.wikimedia.org/wikipedia/commons/thumb/',
 54+ wgUploadPath: 'http://upload.wikimedia.org/wikipedia/commons/thumb',
5555 fetchTemplates: argv.fetchTemplates,
5656 // enable/disable debug output using this switch
5757 debug: argv.debug,
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
@@ -119,17 +119,37 @@
120120
121121 // extract options
122122 var options = [],
 123+ oHash = {},
123124 caption = null;
124125 for( var i = 0, l = content.length; i<l; i++ ) {
125126 var oContent = content[i],
126 - oText = manager.env.tokensToString( oContent, true );
 127+ oText = manager.env.tokensToString( oContent.v, true );
 128+ //console.log( JSON.stringify( oText, null, 2 ) );
127129 if ( oText.constructor === String ) {
128130 oText = oText.trim();
129131 if ( this._simpleImageOptions[ oText ] ) {
130132 options.push( new KV( this._simpleImageOptions[ oText ],
131133 oText ) );
 134+ oHash[ this._simpleImageOptions[ oText ] ] = oText;
132135 continue;
133 - }
 136+ } else {
 137+ var maybeSize = oText.match(/^(\d*)(?:x(\d+))?px$/);
 138+ //console.log( maybeSize );
 139+ if ( maybeSize !== null ) {
 140+ var x = maybeSize[1],
 141+ y = maybeSize[2];
 142+ if ( x !== undefined ) {
 143+ options.push(new KV( 'width', x ) );
 144+ oHash.width = x;
 145+ }
 146+ if ( y !== undefined ) {
 147+ options.push(new KV( 'height', y ) );
 148+ oHash.height = y;
 149+ }
 150+ //console.log( JSON.stringify( oHash ) );
 151+ }
 152+ }
 153+
134154 } else {
135155 var bits = oText[0].split( '=', 2 );
136156 if ( bits.length > 1 && this._prefixImageOptions[ bits[0].trim() ] ) {
@@ -153,42 +173,17 @@
154174 var img = new SelfclosingTagTk( 'img',
155175 [
156176 // FIXME!
157 - new KV( 'height', options.height || '120' ),
158 - new KV( 'width', options.width || '120' ),
 177+ new KV( 'height', oHash.height || '120' ),
 178+ new KV( 'width', oHash.width || '120' ),
159179 new KV( 'src', path ),
160 - new KV( 'alt', options.alt || title.key )
 180+ new KV( 'alt', oHash.alt || title.key )
161181 ] );
162182
163183 return { tokens: [ a, img, new EndTagTk( 'a' )] };
164184 };
165185
166 -WikiLinkHandler.prototype.parseImageOptions = function ( tokens ) {
167 - var out = [],
168 - s = '';
169186
170 - for ( var i = 0, l = tokens.length; i < l; i++ ) {
171 - var token = tokens[i];
172 - if ( token.constructor === String ) {
173 - s += token;
174 - } else if ( token.constructor === NlTk ) {
175 - s += '\n'; // XXX: preserve original newline
176 - } else if ( token.constructor === CommentTk ) {
177 - // strip it
178 - } else {
179 - var res = this.imageParser.processImageOptions( s, 'img_options' ),
180 - last = res.last();
181187
182 - if ( res.last().k !== 'caption' ) {
183 - last.v.push = [last.v, token];
184 - }
185 - out.push( s );
186 - s = '';
187 - out.push(token);
188 - }
189 - }
190 -};
191 -
192 -
193188 function ExternalLinkHandler( manager, isInclude ) {
194189 this.manager = manager;
195190 this.manager.addTransform( this.onUrlLink.bind( this ), this.rank, 'tag', 'urllink' );

Status & tagging log