Index: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js |
— | — | @@ -19,6 +19,8 @@ |
20 | 20 | * + noinclude etc handled automatically by having all tokens on content level |
21 | 21 | */ |
22 | 22 | |
| 23 | +var jshashes = require('jshashes'); |
| 24 | + |
23 | 25 | function WikiLinkHandler( manager, isInclude ) { |
24 | 26 | this.manager = manager; |
25 | 27 | this.manager.addTransform( this.onWikiLink.bind( this ), this.rank, 'tag', 'wikilink' ); |
— | — | @@ -55,10 +57,23 @@ |
56 | 58 | WikiLinkHandler.prototype.renderFile = function ( token, manager, cb, title ) { |
57 | 59 | // distinguish media types |
58 | 60 | // 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 | + ] ); |
63 | 78 | return { tokens: [ a, img, new EndTagTk( 'a' )] }; |
64 | 79 | }; |
65 | 80 | |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js |
— | — | @@ -8,10 +8,11 @@ |
9 | 9 | } |
10 | 10 | |
11 | 11 | Title.prototype.makeLink = function () { |
12 | | - if ( this.nskey ) { |
| 12 | + // XXX: links always point to the canonical namespace name. |
| 13 | + if ( false && this.nskey ) { |
13 | 14 | return this.env.wgScriptPath + this.nskey + ':' + this.key; |
14 | 15 | } else { |
15 | | - return this.env.wgScriptPath + [this.ns.getDefaultName(), this.name].join(':'); |
| 16 | + return this.env.wgScriptPath + [this.ns.getDefaultName(), this.key].join(':'); |
16 | 17 | } |
17 | 18 | }; |
18 | 19 | |
— | — | @@ -46,7 +47,7 @@ |
47 | 48 | if ( this.id == this._defaultNamespaceIDs.main ) { |
48 | 49 | return ''; |
49 | 50 | } else { |
50 | | - return this._defaultNamespaceNames[this.id]; |
| 51 | + return this._defaultNamespaceNames[this.id.toString()]; |
51 | 52 | } |
52 | 53 | }; |
53 | 54 | |
Index: trunk/extensions/VisualEditor/modules/parser/README.txt |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | pegjs |
13 | 13 | querystring |
14 | 14 | html5 |
| 15 | +jshashes |
15 | 16 | request (also required and automatically installed by jsdom) |
16 | 17 | assert |
17 | 18 | |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js |
— | — | @@ -110,7 +110,7 @@ |
111 | 111 | if ( nsText && nsText !== text ) { |
112 | 112 | var _ns = new Namespace(0); |
113 | 113 | var ns = _ns._defaultNamespaceIDs[ nsText.toLowerCase() ]; |
114 | | - console.warn( JSON.stringify( [ nsText, ns ] ) ); |
| 114 | + //console.warn( JSON.stringify( [ nsText, ns ] ) ); |
115 | 115 | if ( ns !== undefined ) { |
116 | 116 | return new Title( text.substr( nsText.length + 1 ), ns, nsText, this ); |
117 | 117 | } else { |