2012-07-24 18:07:53 +00:00
|
|
|
var Util = require('./mediawiki.Util.js').Util;
|
2012-07-18 20:23:12 +00:00
|
|
|
|
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-07-18 20:23:12 +00:00
|
|
|
return Util.sanitizeURI( this.env.wgScriptPath +
|
2012-03-06 18:02:35 +00:00
|
|
|
this.nskey + ':' + this.key );
|
2012-03-01 12:47:05 +00:00
|
|
|
} else {
|
2012-06-05 09:19:58 +00:00
|
|
|
var l = this.env.wgScriptPath,
|
2012-03-05 12:00:38 +00:00
|
|
|
ns = this.ns.getDefaultName();
|
|
|
|
|
|
|
|
if ( ns ) {
|
|
|
|
l += ns + ':';
|
|
|
|
}
|
2012-07-18 20:23:12 +00:00
|
|
|
return Util.sanitizeURI( l + this.key );
|
2012-03-01 12:47:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-09 20:58:55 +00:00
|
|
|
Title.prototype.getPrefixedText = function () {
|
|
|
|
// XXX: links always point to the canonical namespace name.
|
|
|
|
if ( this.nskey ) {
|
2012-07-18 20:23:12 +00:00
|
|
|
return Util.sanitizeURI( this.nskey + ':' + this.key );
|
2012-04-09 20:58:55 +00:00
|
|
|
} else {
|
|
|
|
var ns = this.ns.getDefaultName();
|
|
|
|
|
|
|
|
if ( ns ) {
|
|
|
|
ns += ':';
|
|
|
|
}
|
2012-07-18 20:23:12 +00:00
|
|
|
return Util.sanitizeURI( ns + this.key );
|
2012-04-09 20:58:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|