mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-30 18:34:40 +00:00
59c6b8e88f
* Adds a new webpack entry point for references previews * Reference related code in src/index.js is moved to new file resources/ext.popups.referencePreviews/index.js The changes: * References previews now in its own module ext.popups.referencePreviews * Loaded via getCustomPopupTypes * OWNERS.md files make clear which team owns which part of the code. Bug: T326692 Change-Id: Iea8a5b9221c0b1fd41e40bff2cbe01e42124d53f
93 lines
1.8 KiB
JavaScript
93 lines
1.8 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`.
|
|
* @param {Object|mw.Map} [options]
|
|
* @return {Object}
|
|
*/
|
|
export function createStubUser( isAnon, options ) {
|
|
return {
|
|
getPageviewToken() {
|
|
return '9876543210';
|
|
},
|
|
isNamed() {
|
|
return !isAnon;
|
|
},
|
|
isTemp() {
|
|
return false;
|
|
},
|
|
isAnon() {
|
|
return isAnon;
|
|
},
|
|
sessionId() {
|
|
return '0123456789';
|
|
},
|
|
options
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
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;
|
|
};
|
|
m.remove = m.delete;
|
|
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;
|
|
},
|
|
getMainText() {
|
|
return name;
|
|
},
|
|
getNamespaceId() {
|
|
return namespace;
|
|
},
|
|
getUrl() {
|
|
return `/wiki/${ this.getPrefixedDb() }`;
|
|
},
|
|
getFragment() {
|
|
return fragment;
|
|
}
|
|
};
|
|
}
|