mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
f87ed719e6
* Copied over utility methods from mediawiki.parser.environment.js to ext.Util.js. * Moved over utility method from mediawiki.parser.defines.js to ext.Util.js. * Converted Util to be a singleton object rather than an allocatable class. There is no reason to allocate a new utility class everywhere since this utility object has no useful state. * Fixed up use of utility methods to use Util rather than env. Change-Id: Ib81f96b894f6528f2ccbe36e1fd4c3d50cd1f6b7
82 lines
1.7 KiB
JavaScript
82 lines
1.7 KiB
JavaScript
var Util = require('./ext.Util.js').Util;
|
|
|
|
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 Util.sanitizeURI( this.env.wgScriptPath +
|
|
this.nskey + ':' + this.key );
|
|
} else {
|
|
var l = this.env.wgScriptPath,
|
|
ns = this.ns.getDefaultName();
|
|
|
|
if ( ns ) {
|
|
l += ns + ':';
|
|
}
|
|
return Util.sanitizeURI( l + this.key );
|
|
}
|
|
};
|
|
|
|
Title.prototype.getPrefixedText = function () {
|
|
// XXX: links always point to the canonical namespace name.
|
|
if ( this.nskey ) {
|
|
return Util.sanitizeURI( this.nskey + ':' + this.key );
|
|
} else {
|
|
var ns = this.ns.getDefaultName();
|
|
|
|
if ( ns ) {
|
|
ns += ':';
|
|
}
|
|
return Util.sanitizeURI( ns + 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;
|
|
}
|