mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Hack up some rudimentary image rendering. Using jshashes for the md5, and
a few hard-coded image image sizes ;) 262 tests passing.
This commit is contained in:
parent
d4faf9eaf4
commit
b1a7119a46
Notes:
Gabriel Wicke
2012-03-01 13:51:53 +00:00
|
@ -11,6 +11,7 @@ optimist
|
||||||
pegjs
|
pegjs
|
||||||
querystring
|
querystring
|
||||||
html5
|
html5
|
||||||
|
jshashes
|
||||||
request (also required and automatically installed by jsdom)
|
request (also required and automatically installed by jsdom)
|
||||||
assert
|
assert
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
* + noinclude etc handled automatically by having all tokens on content level
|
* + noinclude etc handled automatically by having all tokens on content level
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var jshashes = require('jshashes');
|
||||||
|
|
||||||
function WikiLinkHandler( manager, isInclude ) {
|
function WikiLinkHandler( manager, isInclude ) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.manager.addTransform( this.onWikiLink.bind( this ), this.rank, 'tag', 'wikilink' );
|
this.manager.addTransform( this.onWikiLink.bind( this ), this.rank, 'tag', 'wikilink' );
|
||||||
|
@ -55,10 +57,23 @@ WikiLinkHandler.prototype.onWikiLink = function ( token, manager, cb ) {
|
||||||
WikiLinkHandler.prototype.renderFile = function ( token, manager, cb, title ) {
|
WikiLinkHandler.prototype.renderFile = function ( token, manager, cb, title ) {
|
||||||
// distinguish media types
|
// distinguish media types
|
||||||
// if image: parse options
|
// if image: parse options
|
||||||
var a = new TagTk( 'a', [ new KV( 'href', title.makeLink() ) ] );
|
// XXX: get /wiki from config!
|
||||||
a.attribs.push( new KV('data-mw-type', 'internal') );
|
var a = new TagTk( 'a', [ new KV( 'href', '/wiki' + title.makeLink() ) ] );
|
||||||
var img = new SelfclosingTagTk( 'img', [ new KV( 'src',
|
|
||||||
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' )] };
|
return { tokens: [ a, img, new EndTagTk( 'a' )] };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,11 @@ function Title ( key, ns, nskey, env ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Title.prototype.makeLink = function () {
|
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;
|
return this.env.wgScriptPath + this.nskey + ':' + this.key;
|
||||||
} else {
|
} 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 @@ Namespace.prototype.getDefaultName = function ( ) {
|
||||||
if ( this.id == this._defaultNamespaceIDs.main ) {
|
if ( this.id == this._defaultNamespaceIDs.main ) {
|
||||||
return '';
|
return '';
|
||||||
} else {
|
} else {
|
||||||
return this._defaultNamespaceNames[this.id];
|
return this._defaultNamespaceNames[this.id.toString()];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ MWParserEnvironment.prototype.makeTitleFromPrefixedText = function ( text ) {
|
||||||
if ( nsText && nsText !== text ) {
|
if ( nsText && nsText !== text ) {
|
||||||
var _ns = new Namespace(0);
|
var _ns = new Namespace(0);
|
||||||
var ns = _ns._defaultNamespaceIDs[ nsText.toLowerCase() ];
|
var ns = _ns._defaultNamespaceIDs[ nsText.toLowerCase() ];
|
||||||
console.warn( JSON.stringify( [ nsText, ns ] ) );
|
//console.warn( JSON.stringify( [ nsText, ns ] ) );
|
||||||
if ( ns !== undefined ) {
|
if ( ns !== undefined ) {
|
||||||
return new Title( text.substr( nsText.length + 1 ), ns, nsText, this );
|
return new Title( text.substr( nsText.length + 1 ), ns, nsText, this );
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue