mediawiki-extensions-Visual.../modules/parser/mediawiki.Title.js
Gabriel Wicke 2efcd3cd57 Reworked percent encoding handling for URIs to get closer to the 'url
construction' part of the HTML5 spec:
http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#url-manipulation-and-creation

Removed a few whitelisted test cases that are now passing directly.

The encoding canonicalization could also be moved to the Sanitizer. Doing this
early in token stream processing however has the advantage of providing further
transformations uniform data to work with. We could even consider to move this
even further into the tokenizer.
2012-03-06 13:49:37 +00:00

65 lines
1.3 KiB
JavaScript

function Title ( key, ns, nskey, env ) {
this.key = key;
// Namespace index
this.ns = new Namespace( ns );
// the original ns string
this.nskey = nskey;
this.env = env;
}
Title.prototype.makeLink = function () {
// XXX: links always point to the canonical namespace name.
if ( false && this.nskey ) {
return this.env.sanitizeURI( this.env.wgScriptPath + this.nskey + ':' + this.key );
} else {
var l = this.env.wgScriptPath,
ns = this.ns.getDefaultName();
if ( ns ) {
l += ns + ':';
}
return this.env.sanitizeURI( l + this.key );
}
};
function Namespace ( id ) {
this.id = id;
}
Namespace.prototype._defaultNamespaceIDs = {
file: -2,
image: -2,
special: -1,
main: 0,
category: 14
};
Namespace.prototype._defaultNamespaceNames = {
'-2': 'File',
'-1': 'Special',
'0': '',
'14': 'Category'
};
Namespace.prototype.isFile = function ( ) {
return this.id === this._defaultNamespaceIDs.file;
};
Namespace.prototype.isCategory = function ( ) {
return this.id === this._defaultNamespaceIDs.category;
};
Namespace.prototype.getDefaultName = function ( ) {
if ( this.id == this._defaultNamespaceIDs.main ) {
return '';
} else {
return this._defaultNamespaceNames[this.id.toString()];
}
};
if (typeof module == "object") {
module.exports.Title = Title;
module.exports.Namespace = Namespace;
}