https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113353

Revision: 113353
Author:   gwicke
Date:     2012-03-08 10:03:22 +0000 (Thu, 08 Mar 2012)
Log Message:
-----------
Improvements for image option handling.

Modified Paths:
--------------
    trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
    trunk/extensions/VisualEditor/modules/parser/parse.js

Modified: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js        
2012-03-08 09:46:57 UTC (rev 113352)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js        
2012-03-08 10:03:22 UTC (rev 113353)
@@ -119,17 +119,37 @@
 
        // extract options
        var options = [],
+               oHash = {},
                caption = null;
        for( var i = 0, l = content.length; i<l; i++ ) {
                var oContent = content[i],
-                       oText = manager.env.tokensToString( oContent, true );
+                       oText = manager.env.tokensToString( oContent.v, true );
+               //console.log( JSON.stringify( oText, null, 2 ) );
                if ( oText.constructor === String ) {
                        oText = oText.trim();
                        if ( this._simpleImageOptions[ oText ] ) {
                                options.push( new KV( this._simpleImageOptions[ 
oText ], 
                                                        oText ) );
+                               oHash[ this._simpleImageOptions[ oText ] ] = 
oText;
                                continue;
-                       } 
+                       } else {
+                               var maybeSize = 
oText.match(/^(\d*)(?:x(\d+))?px$/);
+                               //console.log( maybeSize );
+                               if ( maybeSize !== null ) {
+                                       var x = maybeSize[1],
+                                               y = maybeSize[2];
+                                       if ( x !== undefined ) {
+                                               options.push(new KV( 'width', x 
) );
+                                               oHash.width = x;
+                                       }
+                                       if ( y !== undefined ) {
+                                               options.push(new KV( 'height', 
y ) );
+                                               oHash.height = y;
+                                       }
+                                       //console.log( JSON.stringify( oHash ) 
);
+                               }
+                       }
+
                } else {
                        var bits = oText[0].split( '=', 2 );
                        if ( bits.length > 1 && this._prefixImageOptions[ 
bits[0].trim() ] ) {
@@ -153,42 +173,17 @@
        var img = new SelfclosingTagTk( 'img', 
                        [ 
                                // FIXME!
-                               new KV( 'height', options.height || '120' ),
-                               new KV( 'width', options.width || '120' ),
+                               new KV( 'height', oHash.height || '120' ),
+                               new KV( 'width', oHash.width || '120' ),
                                new KV( 'src', path ),
-                               new KV( 'alt', options.alt || title.key )
+                               new KV( 'alt', oHash.alt || title.key )
                        ] );
 
        return { tokens: [ a, img, new EndTagTk( 'a' )] };
 };
 
-WikiLinkHandler.prototype.parseImageOptions = function ( tokens ) {
-       var out = [],
-               s = '';
 
-       for ( var i = 0, l = tokens.length; i < l; i++ ) {
-               var token = tokens[i];
-               if ( token.constructor === String ) {
-                       s += token;
-               } else if ( token.constructor === NlTk ) {
-                       s += '\n'; // XXX: preserve original newline
-               } else if ( token.constructor === CommentTk ) {
-                       // strip it
-               } else {
-                       var res = this.imageParser.processImageOptions( s, 
'img_options' ),
-                               last = res.last();
 
-                       if ( res.last().k !== 'caption' ) {
-                               last.v.push = [last.v, token];
-                       }
-                       out.push( s );
-                       s = '';
-                       out.push(token);
-               }
-       }
-};
-
-
 function ExternalLinkHandler( manager, isInclude ) {
        this.manager = manager;
        this.manager.addTransform( this.onUrlLink.bind( this ), this.rank, 
'tag', 'urllink' );

Modified: trunk/extensions/VisualEditor/modules/parser/parse.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/parse.js       2012-03-08 
09:46:57 UTC (rev 113352)
+++ trunk/extensions/VisualEditor/modules/parser/parse.js       2012-03-08 
10:03:22 UTC (rev 113353)
@@ -50,7 +50,7 @@
                                                wgScriptPath: argv.wgScriptPath,
                                                wgScriptExtension: 
argv.wgScriptExtension,
                                                // XXX: add options for this!
-                                               wgUploadPath: 
'http://upload.wikimedia.org/wikipedia/commons/thumb/',
+                                               wgUploadPath: 
'http://upload.wikimedia.org/wikipedia/commons/thumb',
                                                fetchTemplates: 
argv.fetchTemplates,
                                                // enable/disable debug output 
using this switch        
                                                debug: argv.debug,


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to