Skip to content

Commit

Permalink
Add types for mediawiki.ForeignUpload
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien LESÉNÉCHAL committed Mar 9, 2024
1 parent 158b2e4 commit df556ce
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mw/ForeignApi.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiOptions } from "./Api";

interface ForeignApiOptions extends ApiOptions {
export interface ForeignApiOptions extends ApiOptions {
/**
* Whether to perform all requests anonymously. Use this option if the target wiki may otherwise not accept cross-origin requests, or if you don't need to perform write actions or read restricted information and want to avoid the overhead.
*/
Expand Down
59 changes: 59 additions & 0 deletions mw/ForeignUpload.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ApiOptions } from "./Api";
import { ForeignApiOptions } from "./ForeignApi";

declare global {
namespace mw {
/**
* Used to represent an upload in progress on the frontend.
*
* Subclassed to upload to a foreign API, with no other goodies. Use
* this for a generic foreign image repository on your wiki farm.
*
* Note you can provide the {@link target} or not - if the first argument is
* an object, we assume you want the default, and treat it as apiconfig
* instead.
*/
class ForeignUpload extends Upload {
static static: {};
static super: typeof Upload;
/** @deprecated Use `super` instead */
static parent: typeof Upload;

/**
* Used to specify the target repository of the upload.
*
* If you set this to something that isn't 'local', you must be sure to
* add that target to $wgForeignUploadTargets in LocalSettings, and the
* repository must be set up to use CORS and CentralAuth.
*
* Most wikis use "shared" to refer to Wikimedia Commons, we assume that
* in this class and in the messages linked to it.
*
* Defaults to the first available foreign upload target,
* or to local uploads if no foreign target is configured.
*/
target: string;

/**
* Used to represent an upload in progress on the frontend.
*
* Subclassed to upload to a foreign API, with no other goodies. Use
* this for a generic foreign image repository on your wiki farm.
*
* Note you can provide the {@link target} or not - if the first argument is
* an object, we assume you want the default, and treat it as apiconfig
* instead.
*
* @param {string} [target] Used to set up the target
* wiki. If not remote, this class behaves identically to mw.Upload (unless further subclassed)
* Use the same names as set in $wgForeignFileRepos for this. Also,
* make sure there is an entry in the $wgForeignUploadTargets array for this name.
* @param {Partial<ApiOptions>} [apiconfig] Passed to the constructor of mw.ForeignApi or mw.Api, as needed.
*/
constructor(target: string, apiconfig?: Partial<ForeignApiOptions>);
constructor(apiconfig?: Partial<ApiOptions>);
}
}
}

export {};
4 changes: 2 additions & 2 deletions mw/Upload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ declare global {
* } );
* ```
*
* @param {Api|ApiOptions} [apiconfig] A mw.Api object (or subclass), or configuration
* @param {Api|Partial<ApiOptions>} [apiconfig] A mw.Api object (or subclass), or configuration
* to pass to the constructor of mw.Api.
*/
constructor(apiconfig?: Api | ApiOptions);
constructor(apiconfig?: Api | Partial<ApiOptions>);

/**
* Finish a stash upload.
Expand Down

0 comments on commit df556ce

Please sign in to comment.