r112807 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112806‎ | r112807 | r112808 >
Date:13:51, 1 March 2012
Author:gwicke
Status:deferred
Tags:
Comment:
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 (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
@@ -19,6 +19,8 @@
2020 * + noinclude etc handled automatically by having all tokens on content level
2121 */
2222
 23+var jshashes = require('jshashes');
 24+
2325 function WikiLinkHandler( manager, isInclude ) {
2426 this.manager = manager;
2527 this.manager.addTransform( this.onWikiLink.bind( this ), this.rank, 'tag', 'wikilink' );
@@ -55,10 +57,23 @@
5658 WikiLinkHandler.prototype.renderFile = function ( token, manager, cb, title ) {
5759 // distinguish media types
5860 // if image: parse options
59 - var a = new TagTk( 'a', [ new KV( 'href', title.makeLink() ) ] );
60 - a.attribs.push( new KV('data-mw-type', 'internal') );
61 - var img = new SelfclosingTagTk( 'img', [ new KV( 'src',
62 - title.makeLink() ) ] );
 61+ // XXX: get /wiki from config!
 62+ var a = new TagTk( 'a', [ new KV( 'href', '/wiki' + title.makeLink() ) ] );
 63+
 64+ var MD5 = new jshashes.MD5,
 65+ hash = MD5.hex( title.key ),
 66+ path = 'http://example.com/images/' +
 67+ [ hash[0], hash.substr(0, 2) ].join('/') + '/' + title.key;
 68+
 69+
 70+ var img = new SelfclosingTagTk( 'img',
 71+ [
 72+ new KV( 'height', '220' ),
 73+ new KV( 'width', '1941' ),
 74+ new KV( 'src', path ),
 75+ new KV( 'alt', title.key ),
 76+
 77+ ] );
6378 return { tokens: [ a, img, new EndTagTk( 'a' )] };
6479 };
6580
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js
@@ -8,10 +8,11 @@
99 }
1010
1111 Title.prototype.makeLink = function () {
12 - if ( this.nskey ) {
 12+ // XXX: links always point to the canonical namespace name.
 13+ if ( false && this.nskey ) {
1314 return this.env.wgScriptPath + this.nskey + ':' + this.key;
1415 } else {
15 - return this.env.wgScriptPath + [this.ns.getDefaultName(), this.name].join(':');
 16+ return this.env.wgScriptPath + [this.ns.getDefaultName(), this.key].join(':');
1617 }
1718 };
1819
@@ -46,7 +47,7 @@
4748 if ( this.id == this._defaultNamespaceIDs.main ) {
4849 return '';
4950 } else {
50 - return this._defaultNamespaceNames[this.id];
 51+ return this._defaultNamespaceNames[this.id.toString()];
5152 }
5253 };
5354
Index: trunk/extensions/VisualEditor/modules/parser/README.txt
@@ -11,6 +11,7 @@
1212 pegjs
1313 querystring
1414 html5
 15+jshashes
1516 request (also required and automatically installed by jsdom)
1617 assert
1718
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
@@ -110,7 +110,7 @@
111111 if ( nsText && nsText !== text ) {
112112 var _ns = new Namespace(0);
113113 var ns = _ns._defaultNamespaceIDs[ nsText.toLowerCase() ];
114 - console.warn( JSON.stringify( [ nsText, ns ] ) );
 114+ //console.warn( JSON.stringify( [ nsText, ns ] ) );
115115 if ( ns !== undefined ) {
116116 return new Title( text.substr( nsText.length + 1 ), ns, nsText, this );
117117 } else {

Status & tagging log