2012-03-01 12:47:05 +00:00
|
|
|
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 () {
|
2012-03-01 13:51:53 +00:00
|
|
|
// XXX: links always point to the canonical namespace name.
|
|
|
|
if ( false && this.nskey ) {
|
2012-03-06 18:02:35 +00:00
|
|
|
return this.env.sanitizeURI( this.env.wgScriptPath + '/' +
|
|
|
|
this.nskey + ':' + this.key );
|
2012-03-01 12:47:05 +00:00
|
|
|
} else {
|
2012-03-06 18:02:35 +00:00
|
|
|
var l = this.env.wgScriptPath + '/',
|
2012-03-05 12:00:38 +00:00
|
|
|
ns = this.ns.getDefaultName();
|
|
|
|
|
|
|
|
if ( ns ) {
|
|
|
|
l += ns + ':';
|
|
|
|
}
|
2012-03-06 13:49:37 +00:00
|
|
|
return this.env.sanitizeURI( l + this.key );
|
2012-03-01 12:47:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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 {
|
2012-03-01 13:51:53 +00:00
|
|
|
return this._defaultNamespaceNames[this.id.toString()];
|
2012-03-01 12:47:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof module == "object") {
|
|
|
|
module.exports.Title = Title;
|
|
|
|
module.exports.Namespace = Namespace;
|
|
|
|
}
|