Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4129637
index.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
index.js
View Options
/**
* @module gateway
* @private
*/
/**
* The interface implemented by all preview gateways.
*
* @typedef Gateway
* @property {function(string): JQuery.jqXHR} fetch
* @property {FetchPreviewForTitle} fetchPreviewForTitle
* @property {ConvertPageToModel} convertPageToModel
*/
/**
* A Promise, usually for a long running or costly task such as an HTTP request,
* that is abortable.
*
* @template T
* @typedef {Promise<T>} AbortPromise
* @property {function(): void} abort
*/
/**
* @stable this function is available to 3rd parties. Any breaking changes must
* go through the MediaWiki deprecation process.
* @param {Promise|jQuery.Promise<T>} promise
* @param {function(): void} [abort]
* @return {AbortPromise}
*/
export
function
abortablePromise
(
promise
,
abort
=
()
=>
{}
)
{
// JQuery provided.
if
(
promise
.
promise
)
{
return
promise
.
promise
(
{
abort
}
);
}
promise
.
abort
=
abort
;
return
promise
;
}
/**
* Fetches a preview for a page or reference.
*
* If the underlying request is successful and contains data for the requested title,
* then the resulting promise will resolve. If not, then it will reject.
*
* @typedef {function(mw.Title, HTMLAnchorElement): AbortPromise<PreviewModel>} FetchPreviewForTitle
*/
/**
* Converts the API response to a preview model. Exposed for testing only.
*
* @typedef {function(Object, ...any): PagePreviewModel} ConvertPageToModel
*/
const
gatewayMap
=
{};
/**
* @param {string} type Type of preview we are handling
* @return {Gateway|undefined}
*/
export
function
getGatewayForPreviewType
(
type
)
{
return
gatewayMap
[
type
];
}
/**
* Register a gateway for a given preview type.
*
* @param {string} type preview type
* @param {Gateway} gateway
*/
export
function
registerGatewayForPreviewType
(
type
,
gateway
)
{
gatewayMap
[
type
]
=
gateway
;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Aug 19, 10:00 (2 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
7c/d8/636542b02804151bfd8d67cb622f
Default Alt Text
index.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment