mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-04 12:08:47 +00:00
8305eb8634
Pretty much all usages of this function do *not* use the second parameter to pass a page name prefixed with a namespace, but pass the page name only. This patch here removes the redundancy. The namespace prefix is now a generated one, saying "Namespace <number>:…". It turns out no test relies on this so far. Bug: T220097 Change-Id: Ibd45d49c91e86a2647afe676a5e3bb07dfeab6ed
83 lines
1.7 KiB
JavaScript
83 lines
1.7 KiB
JavaScript
/**
|
|
* Creates a **minimal** stub that can be used in place of an `mw.User`
|
|
* instance.
|
|
*
|
|
* @param {boolean} isAnon The return value of the `#isAnon`.
|
|
* @return {Object}
|
|
*/
|
|
export function createStubUser( isAnon ) {
|
|
return {
|
|
getPageviewToken() {
|
|
return '9876543210';
|
|
},
|
|
isAnon() {
|
|
return isAnon;
|
|
},
|
|
sessionId() {
|
|
return '0123456789';
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a **minimal** stub that can be used in place of an `mw.Map`
|
|
* instance.
|
|
*
|
|
* @return {mw.Map}
|
|
*/
|
|
export function createStubMap() {
|
|
const m = new Map(); /* global Map */
|
|
m.get = function ( key, fallback ) {
|
|
fallback = arguments.length > 1 ? fallback : null;
|
|
if ( typeof key === 'string' ) {
|
|
return m.has( key ) ? Map.prototype.get.call( m, key ) : fallback;
|
|
}
|
|
// Invalid selection key
|
|
return null;
|
|
};
|
|
return m;
|
|
}
|
|
|
|
/**
|
|
* Creates a stub that can be used as a replacement to mw.experiements
|
|
* @param {string} bucket getBucket will respond with this bucket.
|
|
* @return {Object}
|
|
*/
|
|
export function createStubExperiments( bucket ) {
|
|
return {
|
|
getBucket() {
|
|
return bucket;
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a **minimal** stub that can be used in place of an instance of
|
|
* `mw.Title`.
|
|
*
|
|
* @param {number} namespace
|
|
* @param {string} name Page name without namespace prefix
|
|
* @param {string|null} [fragment]
|
|
* @return {Object}
|
|
*/
|
|
export function createStubTitle( namespace, name, fragment = null ) {
|
|
return {
|
|
namespace,
|
|
getPrefixedDb() {
|
|
return ( namespace ? `Namespace ${ namespace }:` : '' ) + name;
|
|
},
|
|
getNameText() {
|
|
return name;
|
|
},
|
|
getNamespaceId() {
|
|
return namespace;
|
|
},
|
|
getUrl() {
|
|
return `/wiki/${ this.getPrefixedDb() }`;
|
|
},
|
|
getFragment() {
|
|
return fragment;
|
|
}
|
|
};
|
|
}
|