documentation: Convert mediawiki.api from jsduck to jsdoc

Bug: T352308
Change-Id: Ia9320213e2208bb45a7f162b5b5c385fbed09599
This commit is contained in:
Roan Kattouw 2023-12-13 15:04:32 -08:00 committed by Jdlrobson
parent 3e07889c70
commit e365e22ab7
13 changed files with 121 additions and 191 deletions

View file

@ -19,6 +19,7 @@ module.exports = {
'resources/src/mediawiki.String.js',
'resources/src/jsdoc.types.js',
'resources/src/jquery.lengthLimit.js',
'resources/src/mediawiki.api',
'resources/src/mediawiki.base',
'resources/src/mediawiki.experiments.js',
'resources/src/mediawiki.notification',
@ -60,7 +61,6 @@ module.exports = {
'resources/src/mediawiki.special.changeemail.js',
'resources/src/mediawiki.action.edit',
'resources/src/mediawiki.special.changeslist',
'resources/src/mediawiki.api',
'resources/src/mediawiki.special.changeslist.legend.js',
'resources/src/mediawiki.apipretty',
'resources/src/mediawiki.special.changeslist.watchlistexpiry',
@ -135,6 +135,7 @@ module.exports = {
File: 'https://developer.mozilla.org/en-US/docs/Web/API/File',
HTMLElement: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement',
HTMLInputElement: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement',
'JSON.parse': 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse',
jQuery: 'https://api.jquery.com/jQuery/',
'jQuery.fn': 'https://api.jquery.com/jQuery/',
'jQuery.Event': 'https://api.jquery.com/Types/#Event',

View file

@ -1,16 +1,12 @@
/**
* @class mw.Api.plugin.category
*/
( function () {
Object.assign( mw.Api.prototype, {
Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
/**
* Determine if a category exists.
*
* @param {mw.Title|string} title
* @return {jQuery.Promise}
* @return {Function} return.done
* @return {boolean} return.done.isCategory Whether the category exists.
* @return {jQuery.Promise<boolean>} Promise that resolves with a boolean indicating
* whether the category exists.
*/
isCategory: function ( title ) {
var apiPromise = this.get( {
@ -36,9 +32,7 @@
* E.g. given "Foo", return "Food", "Foolish people", "Foosball tables"...
*
* @param {string} prefix Prefix to match.
* @return {jQuery.Promise}
* @return {Function} return.done
* @return {string[]} return.done.categories Matched categories
* @return {jQuery.Promise<string[]>} Promise that resolves with an array of matched categories
*/
getCategoriesByPrefix: function ( prefix ) {
// Fetch with allpages to only get categories that have a corresponding description page.
@ -62,10 +56,8 @@
* Get the categories that a particular page on the wiki belongs to.
*
* @param {mw.Title|string} title
* @return {jQuery.Promise}
* @return {Function} return.done
* @return {boolean|mw.Title[]} return.done.categories List of category titles or false
* if title was not found.
* @return {jQuery.Promise<mw.Title[]|false>} Promise that resolves with an array of
* category titles, or with false if the title was not found.
*/
getCategories: function ( title ) {
var apiPromise = this.get( {
@ -93,9 +85,4 @@
}
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.category
*/
}() );

View file

@ -1,18 +1,13 @@
/**
* @class mw.Api.plugin.edit
*/
( function () {
Object.assign( mw.Api.prototype, {
Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
/**
* Post to API with csrf token. If we have no token, get one and try to post.
* If we have a cached token try using that, and if it fails, blank out the
* cached token and start over.
* Post to API with `csrf` token. See [#postWithToken]{@link mw.Api#postWithToken}
*
* @param {Object} params API parameters
* @param {Object} [ajaxOptions]
* @return {jQuery.Promise} See #post
* @return {jQuery.Promise} See [#post]{@link mw.Api#post}
*/
postWithEditToken: function ( params, ajaxOptions ) {
return this.postWithToken( 'csrf', params, ajaxOptions );
@ -171,7 +166,7 @@
/**
* Post a new section to the page.
*
* @see #postWithEditToken
* @see mw.Api#postWithEditToken
* @param {mw.Title|string} title Target page
* @param {string} header
* @param {string} message wikitext message
@ -189,9 +184,4 @@
}
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.edit
*/
}() );

View file

@ -1,8 +1,23 @@
( function () {
/**
* @typedef {Object} mw.Api.Options
* @property {Object} [parameters = { action: 'query', format: 'json' }] Default query
* parameters for API requests
* @property {Object} [ajax = { url: mw.util.wikiScript( 'api' ), timeout: 30 * 1000, dataType: 'json' }]
* Default options for jQuery#ajax
* @property {boolean} [useUS] Whether to use U+001F when joining multi-valued
* parameters (since 1.28). Default is true if ajax.url is not set, false otherwise for
* compatibility.
*/
/**
* @private
* @type {mw.Api.Options}
*/
var defaultOptions;
/**
* Client library for the action API. See mw.Rest for the REST API.
* @classdesc Client library for the action API. See mw.Rest for the REST API.
*
* See also <https://www.mediawiki.org/wiki/API:Main_page>.
*
@ -33,8 +48,9 @@
*
* @class mw.Api
* @constructor
* @param {Object} [options] See #defaultOptions documentation above. This can also be overridden for
* each request by passing them to #get or #post (or directly #ajax) later on.
* @param {mw.Api.Options} [options] See {@link mw.Api.Options}. This can also be overridden for
* each request by passing them to [get()]{@link mw.Api#get} or [post()]{@link mw.Api#post} (or directly to
* [ajax()]{@link mw.Api#ajax}) later on.
*/
mw.Api = function ( options ) {
var defaults = $.extend( {}, options ),
@ -57,13 +73,7 @@
/**
* @private
* @property {Object} defaultOptions Default options for #ajax calls. Can be overridden by passing
* `options` to mw.Api constructor.
* @property {Object} defaultOptions.parameters Default query parameters for API requests.
* @property {Object} defaultOptions.ajax Default options for jQuery#ajax.
* @property {boolean} defaultOptions.useUS Whether to use U+001F when joining multi-valued
* parameters (since 1.28). Default is true if ajax.url is not set, false otherwise for
* compatibility.
* @type {mw.Api.Options}
*/
defaultOptions = {
parameters: {
@ -129,7 +139,7 @@
},
/**
* Perform API get request. See #ajax for details.
* Perform API get request. See [ajax()]{@link mw.Api#ajax} for details.
*
* @param {Object} parameters
* @param {Object} [ajaxOptions]
@ -142,7 +152,7 @@
},
/**
* Perform API post request. See #ajax for details.
* Perform API post request. See [ajax()]{@link mw.Api#ajax} for details.
*
* @param {Object} parameters
* @param {Object} [ajaxOptions]
@ -185,9 +195,9 @@
/**
* Perform the API call.
*
* @param {Object} parameters Parameters to the API. See also #defaultOptions.parameters.
* @param {Object} parameters Parameters to the API. See also {@link mw.Api.Options}
* @param {Object} [ajaxOptions] Parameters to pass to jQuery.ajax. See also
* #defaultOptions.ajax.
* {@link mw.Api.Options}
* @return {jQuery.Promise} A promise that settles when the API response is processed.
* Has an 'abort' method which can be used to abort the request.
*
@ -209,7 +219,7 @@
* first line of the server response). For HTTP/2, `exception` is always an empty string.
* - When the response is not valid JSON but the previous error conditions aren't met,
* textStatus is "parsererror" and exception is the exception object thrown by
* `JSON.parse`.
* {@link JSON.parse}.
*/
ajax: function ( parameters, ajaxOptions ) {
var token, requestIndex,
@ -315,8 +325,9 @@
/**
* Post to API with the specified type of token. If we have no token, get one and try to post.
* If we already have a cached token, try using that, and if the request fails using the cached token,
* blank it out and start over. For example, to change a user option, you could do:
* blank it out and start over.
*
* @example <caption>For example, to change a user option, you could do:</caption>
* new mw.Api().postWithToken( 'csrf', {
* action: 'options',
* optionname: 'gender',
@ -326,7 +337,7 @@
* @param {string} tokenType The name of the token, like options or edit.
* @param {Object} params API parameters
* @param {Object} [ajaxOptions]
* @return {jQuery.Promise} See #post
* @return {jQuery.Promise} See [post()]{@link mw.Api#post}
* @since 1.22
*/
postWithToken: function ( tokenType, params, ajaxOptions ) {
@ -387,7 +398,7 @@
* @param {string} type Token type
* @param {Object|string} [additionalParams] Additional parameters for the API (since 1.35).
* When given a string, it's treated as the 'assert' parameter (since 1.25).
* @return {jQuery.Promise} Received token.
* @return {jQuery.Promise<string>} Received token.
*/
getToken: function ( type, additionalParams ) {
var apiPromise, promiseGroup, d, reject;
@ -440,8 +451,8 @@
/**
* Indicate that the cached token for a certain action of the API is bad.
*
* Call this if you get a 'badtoken' error when using the token returned by #getToken.
* You may also want to use #postWithToken instead, which invalidates bad cached tokens
* Call this if you get a 'badtoken' error when using the token returned by [getToken()]{@link mw.Api#getToken}.
* You may also want to use [postWithToken()]{@link mw.Api#postWithToken} instead, which invalidates bad cached tokens
* automatically.
*
* @param {string} type Token type
@ -470,7 +481,7 @@
* Error messages, particularly for editing pages, may consist of multiple paragraphs of text.
* Your user interface should have enough space for that.
*
* Example usage:
* @example
*
* var api = new mw.Api();
* // var title = 'Test valid title';

View file

@ -1,18 +1,11 @@
/**
* Make the two-step login easier.
*
* @author Niklas Laxström
* @class mw.Api.plugin.login
* @since 1.22
*/
( function () {
'use strict';
Object.assign( mw.Api.prototype, {
Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
/**
* @param {string} username
* @param {string} password
* @return {jQuery.Promise} See mw.Api#post
* @return {jQuery.Promise} See [post()]{@link mw.Api#post}
*/
login: function ( username, password ) {
var params, apiPromise, innerPromise,
@ -52,9 +45,4 @@
}
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.login
*/
}() );

View file

@ -1,21 +1,14 @@
/**
* Allows to retrieve a specific or a set of
* messages to be added to mw.messages and returned
* by the Api.
*
* @class mw.Api.plugin.messages
* @since 1.27
*/
( function () {
'use strict';
Object.assign( mw.Api.prototype, {
Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
/**
* Get a set of messages.
*
* @since 1.27
* @param {string|string[]} messages Messages to retrieve
* @param {Object} [options] Additional parameters for the API call
* @return {jQuery.Promise}
* @return {jQuery.Promise<Object.<string, string>>}
*/
getMessages: function ( messages, options ) {
var that = this;
@ -56,7 +49,7 @@
},
/**
* Loads a set of messages and add them to mw.messages.
* Loads a set of messages and add them to {@link mw.messages}.
*
* @param {string|string[]} messages Messages to retrieve
* @param {Object} [options] Additional parameters for the API call
@ -67,9 +60,10 @@
},
/**
* Loads a set of messages and add them to mw.messages. Only messages that are not already known
* Loads a set of messages and add them to {@link mw.messages}. Only messages that are not already known
* are loaded. If all messages are known, the returned promise is resolved immediately.
*
* @since 1.27
* @param {string[]} messages Messages to retrieve
* @param {Object} [options] Additional parameters for the API call
* @return {jQuery.Promise}
@ -88,9 +82,4 @@
}
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.messages
*/
}() );

View file

@ -1,14 +1,12 @@
/**
* @class mw.Api.plugin.options
*/
( function () {
var saveOptionsRequests = {};
Object.assign( mw.Api.prototype, {
Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
/**
* Asynchronously save the value of a single user option using the API. See #saveOptions.
* Asynchronously save the value of a single user option using the API.
* See [saveOptions()]{@link mw.Api#saveOptions}.
*
* @param {string} name
* @param {string|null} value
@ -31,7 +29,7 @@
* If necessary, the options will be saved using several sequential API requests. Only one promise
* is always returned that will be resolved when all requests complete.
*
* If a request from a previous #saveOptions call is still pending, this will wait for it to be
* If a request from a previous `saveOptions()` call is still pending, this will wait for it to be
* completed, otherwise MediaWiki gets sad. No requests are sent for anonymous users, as they
* would fail anyway. See T214963.
*
@ -123,9 +121,4 @@
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.options
*/
}() );

View file

@ -1,19 +1,14 @@
/**
* @class mw.Api.plugin.parse
*/
( function () {
Object.assign( mw.Api.prototype, {
Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
/**
* Convenience method for 'action=parse'.
*
* @param {string|mw.Title} content Content to parse, either as a wikitext string or
* a mw.Title.
* @param {Object} additionalParams Parameters object to set custom settings, e.g.
* redirects, sectionpreview. prop should not be overridden.
* @return {jQuery.Promise}
* @return {Function} return.done
* @return {string} return.done.data Parsed HTML of `wikitext`.
* `redirects`, `sectionpreview`. `prop` should not be overridden.
* @return {jQuery.Promise<string>} Promise that resolves with the parsed HTML of `wikitext`
*/
parse: function ( content, additionalParams ) {
var apiPromise,
@ -43,9 +38,4 @@
}
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.parse
*/
}() );

View file

@ -1,13 +1,14 @@
( function () {
/**
* @class mw.Rest
* @typedef {Object} mw.Rest.Options
* @property {Object} [ajax={ url: mw.util.wikiScript( 'rest' ), timeout: 30 * 1000 }] Default
* options for [ajax()]{@link mw.Rest#ajax} calls. Can be overridden by passing `options` to
* the {@link mw.Rest} constructor.
*/
/**
* @property {Object} defaultOptions Default options for #ajax calls. Can be overridden by passing
* `options` to mw.Rest constructor.
* @property {Object} defaultOptions.ajax Default options for jQuery#ajax.
* @type {mw.Rest.Options}
* @private
*/
var defaultOptions = {
@ -35,6 +36,7 @@
* Constructor to create an object to interact with the REST API of a particular MediaWiki server.
* mw.Rest objects represent the REST API of a particular MediaWiki server.
*
* @example
* var api = new mw.Rest();
* api.get( '/v1/page/Main_Page/html' )
* .done( function ( data ) {
@ -54,7 +56,7 @@
* } );
*
* @constructor
* @param {Object} [options] See #defaultOptions documentation above.
* @param {mw.Rest.Options} [options] See {@link mw.Rest.Options}
*/
mw.Rest = function ( options ) {
var defaults = $.extend( {}, options );
@ -82,7 +84,7 @@
},
/**
* Perform REST API get request
* Perform REST API get request.
*
* @method
* @param {string} path
@ -121,7 +123,7 @@
/**
* Perform REST API PUT request.
*
* Note: only sending application/json is currently supported.
* Note: only sending `application/json` is currently supported.
*
* @method
* @param {string} path
@ -141,7 +143,7 @@
/**
* Perform REST API DELETE request.
*
* Note: only sending application/json is currently supported.
* Note: only sending `application/json` is currently supported.
*
* @method
* @param {string} path

View file

@ -1,13 +1,10 @@
/**
* @class mw.Api.plugin.rollback
* @since 1.28
*/
( function () {
Object.assign( mw.Api.prototype, {
Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
/**
* Convenience method for `action=rollback`.
*
* @since 1.28
* @param {string|mw.Title} page
* @param {string} user
* @param {Object} [params] Additional parameters
@ -25,9 +22,4 @@
}
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.rollback
*/
}() );

View file

@ -1,9 +1,3 @@
/**
* Provides an interface for uploading files to MediaWiki.
*
* @class mw.Api.plugin.upload
* @singleton
*/
( function () {
var
fieldsAllowed = {
@ -31,7 +25,7 @@
return obj[ Object.keys( obj )[ 0 ] ];
}
Object.assign( mw.Api.prototype, {
Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
/**
* Upload a file to MediaWiki.
*
@ -329,11 +323,8 @@
* @private
* @param {jQuery.Promise} uploadPromise
* @param {Object} data
* @return {jQuery.Promise}
* @return {Function} return.finishUpload Call this function to finish the upload.
* @return {Object} return.finishUpload.data Additional data for the upload.
* @return {jQuery.Promise} return.finishUpload.return API promise for the final upload
* @return {Object} return.finishUpload.return.data API return value for the final upload
* @return {jQuery.Promise<function(Object): jQuery.Promise>} Promise that resolves with a
* function that should be called to finish the upload.
*/
finishUploadToStash: function ( uploadPromise, data ) {
var filekey,
@ -368,7 +359,9 @@
*
* This function will return a promise, which when resolved, will pass back a function
* to finish the stash upload. You can call that function with an argument containing
* more, or conflicting, data to pass to the server. For example:
* more, or conflicting, data to pass to the server.
*
* @example
*
* // upload a file to the stash with a placeholder filename
* api.uploadToStash( file, { filename: 'testing.png' } ).done( function ( finish ) {
@ -381,11 +374,8 @@
*
* @param {File|HTMLInputElement} file
* @param {Object} [data]
* @return {jQuery.Promise}
* @return {Function} return.finishUpload Call this function to finish the upload.
* @return {Object} return.finishUpload.data Additional data for the upload.
* @return {jQuery.Promise} return.finishUpload.return API promise for the final upload
* @return {Object} return.finishUpload.return.data API return value for the final upload
* @return {jQuery.Promise<function(Object): jQuery.Promise>} Promise that resolves with a
* function that should be called to finish the upload.
*/
uploadToStash: function ( file, data ) {
var promise;
@ -405,16 +395,13 @@
* This function will return a promise, which when resolved, will pass back a function
* to finish the stash upload.
*
* @see #method-uploadToStash
* @see mw.Api#uploadToStash
* @param {File|HTMLInputElement} file
* @param {Object} [data]
* @param {number} [chunkSize] Size (in bytes) per chunk (default: 5 MiB)
* @param {number} [chunkRetries] Amount of times to retry a failed chunk (default: 1)
* @return {jQuery.Promise}
* @return {Function} return.finishUpload Call this function to finish the upload.
* @return {Object} return.finishUpload.data Additional data for the upload.
* @return {jQuery.Promise} return.finishUpload.return API promise for the final upload
* @return {Object} return.finishUpload.return.data API return value for the final upload
* @return {jQuery.Promise<function(Object): jQuery.Promise>} Promise that resolves with a
* function that should be called to finish the upload.
*/
chunkedUploadToStash: function ( file, data, chunkSize, chunkRetries ) {
var promise;
@ -457,13 +444,13 @@
} );
},
/**
* @private
* @return {boolean}
*/
needToken: function () {
return true;
}
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.upload
*/
}() );

View file

@ -1,19 +1,18 @@
/**
* @class mw.Api.plugin.user
* @since 1.27
*/
( function () {
Object.assign( mw.Api.prototype, {
/**
* @typedef {Object} mw.Api.UserInfo
* @property {string[]} groups User groups that the current user belongs to
* @property {string[]} rights Current user's rights
*/
Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
/**
* Get the current user's groups and rights.
*
* @return {jQuery.Promise}
* @return {Function} return.done
* @return {Object} return.done.userInfo
* @return {string[]} return.done.userInfo.groups User groups that the current user belongs to
* @return {string[]} return.done.userInfo.rights Current user's rights
* @since 1.27
* @return {jQuery.Promise<mw.Api.UserInfo>}
*/
getUserInfo: function () {
return this.get( {
@ -38,8 +37,6 @@
* this method ensures that that won't happen, by checking the user's identity that was
* embedded into the page when it was rendered against the active session on the server.
*
* Use it like this:
* api.postWithToken( 'csrf', api.assertCurrentUser( { action: 'edit', ... } ) )
* When the assertion fails, the API request will fail, with one of the following error codes:
* - apierror-assertanonfailed: when the client-side logic thinks the user is anonymous
* but the server thinks it is logged in;
@ -48,6 +45,10 @@
* - apierror-assertnameduserfailed: when both the client-side logic and the server thinks the
* user is logged in but they see it logged in under a different username.
*
* @example
* api.postWithToken( 'csrf', api.assertCurrentUser( { action: 'edit', ... } ) )
*
* @since 1.27
* @param {Object} query Query parameters. The object will not be changed.
* @return {Object}
*/
@ -67,9 +68,4 @@
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.user
*/
}() );

View file

@ -1,24 +1,19 @@
/**
* @class mw.Api.plugin.watch
* @since 1.19
* @typedef {Object} mw.Api.WatchedPage
* @property {string} title Full page name
* @property {boolean} watched Whether the page is now watched (true) or unwatched (false)
*/
( function () {
/**
* @private
* @static
* @this mw.Api
*
* @param {string|mw.Title|string[]|mw.Title[]} pages Full page name or instance of mw.Title, or an
* array thereof. If an array is passed, the return value passed to the promise will also be an
* array of appropriate objects.
* @param {Object} [addParams]
* @return {jQuery.Promise}
* @return {Function} return.done
* @return {Object|Object[]} return.done.watch Object or list of objects (depends on the `pages`
* parameter)
* @return {string} return.done.watch.title Full pagename
* @return {boolean} return.done.watch.watched Whether the page is now watched or unwatched
* @return {jQuery.Promise<mw.Api.WatchedPage|mw.Api.WatchedPage[]>}
*/
function doWatchInternal( pages, addParams ) {
// XXX: Parameter addParams is undocumented because we inherit this
@ -42,13 +37,21 @@
.promise( { abort: apiPromise.abort } );
}
Object.assign( mw.Api.prototype, {
Object.assign( mw.Api.prototype, /** @lends mw.Api.prototype */ {
/**
* Convenience method for `action=watch`.
*
* @inheritdoc #doWatchInternal
* @method
* @since 1.35 - expiry parameter can be passed when
* Watchlist Expiry is enabled
* @param {string|mw.Title|string[]|mw.Title[]} pages Full page name or instance of mw.Title, or an
* array thereof. If an array is passed, the return value passed to the promise will also be an
* array of appropriate objects.
* @param {string} [expiry] When the page should expire from the watchlist. If omitted, the
* page will not expire.
* @return {jQuery.Promise<mw.Api.WatchedPage|mw.Api.WatchedPage[]>} A promise that resolves
* with an object (or array of objects) describing each page that was passed in and its
* current watched/unwatched status.
*/
watch: function ( pages, expiry ) {
return doWatchInternal.call( this, pages, { expiry: expiry } );
@ -57,16 +60,17 @@
/**
* Convenience method for `action=watch&unwatch=1`.
*
* @inheritdoc #doWatchInternal
* @method
* @param {string|mw.Title|string[]|mw.Title[]} pages Full page name or instance of mw.Title, or an
* array thereof. If an array is passed, the return value passed to the promise will also be an
* array of appropriate objects.
* @return {jQuery.Promise<mw.Api.WatchedPage|mw.Api.WatchedPage[]>} A promise that resolves
* with an object (or array of objects) describing each page that was passed in and its
* current watched/unwatched status.
*/
unwatch: function ( pages ) {
return doWatchInternal.call( this, pages, { unwatch: 1 } );
}
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.watch
*/
}() );