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

Revision: 112807
Author:   gwicke
Date:     2012-03-01 13:51:53 +0000 (Thu, 01 Mar 2012)
Log Message:
-----------
Hack up some rudimentary image rendering. Using jshashes for the md5, and
a few hard-coded image image sizes ;) 262 tests passing.

Modified Paths:
--------------
    trunk/extensions/VisualEditor/modules/parser/README.txt
    trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
    trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js
    trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js

Modified: trunk/extensions/VisualEditor/modules/parser/README.txt
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/README.txt     2012-03-01 
13:39:51 UTC (rev 112806)
+++ trunk/extensions/VisualEditor/modules/parser/README.txt     2012-03-01 
13:51:53 UTC (rev 112807)
@@ -11,6 +11,7 @@
 pegjs
 querystring
 html5
+jshashes
 request (also required and automatically installed by jsdom)
 assert
 

Modified: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js        
2012-03-01 13:39:51 UTC (rev 112806)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js        
2012-03-01 13:51:53 UTC (rev 112807)
@@ -19,6 +19,8 @@
  * + noinclude etc handled automatically by having all tokens on content level
  */
 
+var jshashes = require('jshashes');
+
 function WikiLinkHandler( manager, isInclude ) {
        this.manager = manager;
        this.manager.addTransform( this.onWikiLink.bind( this ), this.rank, 
'tag', 'wikilink' );
@@ -55,10 +57,23 @@
 WikiLinkHandler.prototype.renderFile = function ( token, manager, cb, title ) {
        // distinguish media types
        // if image: parse options
-       var a = new TagTk( 'a', [ new KV( 'href', title.makeLink() ) ] );
-       a.attribs.push( new KV('data-mw-type', 'internal') );
-       var img = new SelfclosingTagTk( 'img', [ new KV( 'src', 
-                               title.makeLink() ) ] );
+       // XXX: get /wiki from config!
+       var a = new TagTk( 'a', [ new KV( 'href', '/wiki' + title.makeLink() ) 
] );
+
+       var MD5 = new jshashes.MD5,
+               hash = MD5.hex( title.key ),
+               path = 'http://example.com/images/' + 
+                       [ hash[0], hash.substr(0, 2) ].join('/') + '/' + 
title.key;
+       
+       
+       var img = new SelfclosingTagTk( 'img', 
+                       [ 
+                               new KV( 'height', '220' ),
+                               new KV( 'width', '1941' ),
+                               new KV( 'src', path ),
+                               new KV( 'alt', title.key ),
+
+                       ] );
        return { tokens: [ a, img, new EndTagTk( 'a' )] };
 };
 

Modified: trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js     
2012-03-01 13:39:51 UTC (rev 112806)
+++ trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js     
2012-03-01 13:51:53 UTC (rev 112807)
@@ -8,10 +8,11 @@
 }
 
 Title.prototype.makeLink = function () {
-       if ( this.nskey ) {
+       // XXX: links always point to the canonical namespace name.
+       if ( false && this.nskey ) {
                return this.env.wgScriptPath + this.nskey + ':' + this.key;
        } else {
-               return this.env.wgScriptPath + [this.ns.getDefaultName(), 
this.name].join(':');
+               return this.env.wgScriptPath + [this.ns.getDefaultName(), 
this.key].join(':');
        }
 };
 
@@ -46,7 +47,7 @@
        if ( this.id == this._defaultNamespaceIDs.main ) {
                return '';
        } else {
-               return this._defaultNamespaceNames[this.id];
+               return this._defaultNamespaceNames[this.id.toString()];
        }
 };
 

Modified: 
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
===================================================================
--- 
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js    
    2012-03-01 13:39:51 UTC (rev 112806)
+++ 
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js    
    2012-03-01 13:51:53 UTC (rev 112807)
@@ -110,7 +110,7 @@
        if ( nsText && nsText !== text ) {
                var _ns = new Namespace(0);
                var ns = _ns._defaultNamespaceIDs[ nsText.toLowerCase() ];
-               console.warn( JSON.stringify( [ nsText, ns ] ) );
+               //console.warn( JSON.stringify( [ nsText, ns ] ) );
                if ( ns !== undefined ) {
                        return new Title( text.substr( nsText.length + 1 ), ns, 
nsText, this );
                } else {


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

Reply via email to