Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to MediaWiki 1.44 #53

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions mw/Api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ declare global {
* api.get( {
* action: 'query',
* meta: 'userinfo'
* } ).then( function ( data ) {
* } ).then( ( data ) => {
* console.log( data );
* } );
* ```
Expand All @@ -117,7 +117,7 @@ declare global {
* api.get( {
* action: 'query',
* meta: [ 'userinfo', 'siteinfo' ] // same effect as 'userinfo|siteinfo'
* } ).then( function ( data ) {
* } ).then( ( data ) => {
* console.log( data );
* } );
* ```
Expand Down Expand Up @@ -410,9 +410,9 @@ declare global {
* api.postWithToken( 'watch', {
* action: 'watch',
* title: title
* } ).then( function ( data ) {
* } ).then( ( data ) => {
* mw.notify( 'Success!' );
* }, function ( code, data ) {
* }, ( code, data ) => {
* mw.notify( api.getErrorMessage( data ), { type: 'error' } );
* } );
* ```
Expand Down Expand Up @@ -606,6 +606,42 @@ declare global {
ajaxOptions?: JQuery.AjaxSettings
): Api.Promise;

/**
* Prepare an extensible API request.
*
* This is a utility method to allow mw.hook implementations to add data to params sent
* with an API request.
*
* For example usage, see mediawiki.ready/index.js#logoutViaPost:
*
* ```js
* api.prepareExtensibleApiRequest( 'extendLogout' ).then( ( params ) => { ... } )
* ```
*
* Implementations of `hookName` should do something like the following, where `hookName`
* is `extendLogout` in this example:
*
* ```js
* mw.hook( 'extendLogout' ).add( ( data ) => {
* data.promise = data.promise.then( () => {
* // Return a promise
* return collectClientHintsData().then( ( userAgentHighEntropyValues ) => {
* // Set the data.params.{yourUniqueKey} that will be included in the API
* // request
* data.params.customData = { clientHints: userAgentHighEntropyValues };
* } );
* } );
* } );
* ```
*
* @since 1.44
* @param {string} hookName Name of the hook to use with mw.hook().fire()
* @return {JQuery.Promise<Object>} Updated parameter data from implementations
* of `hookName` to include with the API request.
*@see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Api.html#prepareExtensibleApiRequest
*/
prepareExtensibleApiRequest<T extends {} = {}>(hookName: string): JQuery.Promise<T>;

/**
* Convenience method for `action=rollback`.
*
Expand Down
8 changes: 4 additions & 4 deletions mw/Upload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare global {
* button = new OO.ui.ButtonWidget( { label: 'Save' } ),
* upload = new mw.Upload;
*
* button.on( 'click', function () {
* button.on( 'click', () => {
* upload.setFile( file.getValue() );
* upload.setFilename( file.getValue().name );
* upload.upload();
Expand All @@ -32,14 +32,14 @@ declare global {
* stashPromise = $.Deferred();
*
* upload.setFile( file );
* upload.uploadToStash().then( function () {
* upload.uploadToStash().then( () => {
* stashPromise.resolve();
* } );
*
* stashPromise.then( function () {
* stashPromise.then( () => {
* upload.setFilename( 'foo' );
* upload.setText( 'bar' );
* upload.finishStashUpload().then( function () {
* upload.finishStashUpload().then( () => {
* console.log( 'Done!' );
* } );
* } );
Expand Down
23 changes: 18 additions & 5 deletions mw/deflate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@ declare global {
namespace mw {
/**
* Convert a byte stream to base64 text.
* Before using load the `mediawiki.deflate` ResourceLoader module.
*
* @example
* ```js
* mw.loader.using( 'mediawiki.deflate' ).then( function () {
* return mw.deflate( html );
* } );
* return mw.loader.using( 'mediawiki.deflate' ).then( () => mw.deflate( html ) );
* ```
* @deprecated Use {@link mw.deflateAsync}
* @param {string|ArrayBuffer} data Undeflated data
* @returns {string} Deflated data
* @returns {string} Compressed data
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.html#.deflate
*/
function deflate(data: string | ArrayBuffer): `rawdeflate,${string}`;

/**
* Convert a byte stream to base64 text.
*
* Uses browser native CompressionStream if available.
*
* @example
* ```js
* return mw.loader.using( 'mediawiki.deflate' ).then( () => mw.deflateAsync( html ) );
* ```
* @param {string|ArrayBuffer} data Undeflated data
* @return {Promise<string>} Compressed data
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.html#.deflateAsync
*/
function deflateAsync(data: string | ArrayBuffer): Promise<`rawdeflate,${string}`>;
}
}

Expand Down
13 changes: 7 additions & 6 deletions mw/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface AnalyticEvent {
}

interface AnalyticEventCallback {
(topic: string, data: AnalyticEventData): void;
(topic: string, ...data: AnalyticEventData[]): void;
}

declare global {
Expand Down Expand Up @@ -186,11 +186,12 @@ declare global {
* events that match their subscription, including buffered events that fired before the handler
* was subscribed.
*
* @since 1.44 - multiple data arguments can be passed.
* @param {string} topic Topic name
* @param {AnalyticEventData} [data] Data describing the event.
* @param {...AnalyticEventData} [data] Data describing the event.
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.html#.track
*/
function track(topic: string, data?: AnalyticEventData): void;
function track(topic: string, ...data: AnalyticEventData[]): void;

/**
* Track `'resourceloader.exception'` event and send it to the window console.
Expand All @@ -209,8 +210,7 @@ declare global {
*
* Handlers will be called once for each tracked event, including for any buffered events that
* fired before the handler was subscribed. The callback is passed a `topic` string, and optional
* `data` event object. The `this` value for the callback is a plain object with `topic` and
* `data` properties set to those same values.
* `data` argument(s).
*
* @example
* ```js
Expand All @@ -222,8 +222,9 @@ declare global {
* // To subscribe to any of `foo.*`, e.g. both `foo.bar` and `foo.quux`
* mw.trackSubscribe( 'foo.', console.log );
* ```
* @since 1.44 - multiple data arguments can be passed.
* @param {string} topic Handle events whose name starts with this string prefix
* @param {function(string, AnalyticEventData): void} callback Handler to call for each matching tracked event
* @param {AnalyticEventCallback} callback Handler to call for each matching tracked event
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.html#.trackSubscribe
*/
function trackSubscribe(topic: string, callback: AnalyticEventCallback): void;
Expand Down
Loading