Skip to content

Commit

Permalink
move mw.config to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed May 31, 2021
1 parent e2f9631 commit 9ee28bb
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 79 deletions.
72 changes: 72 additions & 0 deletions mw/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
declare global {
namespace mw {

/**
* Map of configuration values.
*
* Check out [the complete list of configuration values](https://www.mediawiki.org/wiki/Manual:Interface/JavaScript#mw.config)
* on mediawiki.org.
*
* If `$wgLegacyJavaScriptGlobals` is true, this Map will add its values to the
* global `window` object.
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw-property-config
*/
const config: mw.Map<{
debug: boolean;
skin: string;
stylepath: string;
wgArticlePath: string;
wgCaseSensitiveNamespaces: string[];
wgContentLanguage: string;
wgContentNamespaces: number[];
wgDBname: string;
wgEnableAPI: boolean;
wgEnableWriteAPI: boolean;
wgExtensionAssetsPath: string;
wgFormattedNamespaces: Record<number, string>;
wgNamespaceIds: Record<string, number>;
wgScript: string;
wgScriptPath: string;
wgServer: string;
wgSiteName: string;
wgVariantArticlePath: string | false;
wgVersion: string;
wgAction: string;
wgArticleId: number;
wgCanonicalNamespace: string;
wgCanonicalSpecialPageName: string | false;
wgCategories: string[];
wgCurRevisionId: number;
wgIsArticle: boolean;
wgIsProbablyEditable: boolean;
wgNamespaceNumber: number;
wgPageContentLanguage: string;
wgPageContentModel: string;
wgPageName: string;
wgRedirectedFrom: string;
wgRelevantPageName: string;
wgRelevantUserName: string;
wgRelevantPageIsProbablyEditable: boolean;
wgRestrictionEdit: string[];
wgRestrictionMove: string[];
wgRevisionId: number;
wgSearchType: string;
wgTitle: string;
wgUserEditCount: number;
wgUserGroups: string[];
wgUserId: number;
wgUserLanguage: string;
wgUserName: string;
wgUserRegistration: number;
wgIsMainPage: boolean;
wgUserVariant: string;
wgPostEdit: string;
wgDiffOldId: number | false;
wgDiffNewId: number;
wgWikibaseItemId: string;
[key: string]: unknown; // more config keys can be added by extensions
}>;
}
}

export {};
94 changes: 15 additions & 79 deletions mw/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "./Api";
import "./config";
import "./cookie";
import "./ForeignApi";
import "./hook";
Expand All @@ -24,87 +25,22 @@ declare global {
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw
*/
namespace mw {
/**
* Map of configuration values.
*
* Check out [the complete list of configuration values](https://www.mediawiki.org/wiki/Manual:Interface/JavaScript#mw.config)
* on mediawiki.org.
*
* If `$wgLegacyJavaScriptGlobals` is true, this Map will add its values to the
* global `window` object.
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw-property-config
*/
const config: mw.Map<{
debug: boolean;
skin: string;
stylepath: string;
wgArticlePath: string;
wgCaseSensitiveNamespaces: string[];
wgContentLanguage: string;
wgContentNamespaces: number[];
wgDBname: string;
wgEnableAPI: boolean;
wgEnableWriteAPI: boolean;
wgExtensionAssetsPath: string;
wgFormattedNamespaces: Record<number, string>;
wgNamespaceIds: Record<string, number>;
wgScript: string;
wgScriptPath: string;
wgServer: string;
wgSiteName: string;
wgVariantArticlePath: string | false;
wgVersion: string;
wgAction: string;
wgArticleId: number;
wgCanonicalNamespace: string;
wgCanonicalSpecialPageName: string | false;
wgCategories: string[];
wgCurRevisionId: number;
wgIsArticle: boolean;
wgIsProbablyEditable: boolean;
wgNamespaceNumber: number;
wgPageContentLanguage: string;
wgPageContentModel: string;
wgPageName: string;
wgRedirectedFrom: string;
wgRelevantPageName: string;
wgRelevantUserName: string;
wgRelevantPageIsProbablyEditable: boolean;
wgRestrictionEdit: string[];
wgRestrictionMove: string[];
wgRevisionId: number;
wgSearchType: string;
wgTitle: string;
wgUserEditCount: number;
wgUserGroups: string[];
wgUserId: number;
wgUserLanguage: string;
wgUserName: string;
wgUserRegistration: number;
wgIsMainPage: boolean;
wgUserVariant: string;
wgPostEdit: string;
wgDiffOldId: number | false;
wgDiffNewId: number;
wgWikibaseItemId: string;
[key: string]: unknown; // more config keys can be added by extensions
}>;

// types for mw.widgets are out of scope!
const widgets: any;
/**
* Format a string. Replace $1, $2 ... $N with positional arguments.
*
* Used by Message#parser().
*
* @since 1.25
* @param {string} formatString Format string
* @param {...Mixed} parameters Values for $N replacements
* @return {string} Formatted string
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw-method-format
*/
function format(formatString: string, ...parameters: unknown[]): string;

/**
* Format a string. Replace $1, $2 ... $N with positional arguments.
*
* Used by Message#parser().
*
* @since 1.25
* @param {string} formatString Format string
* @param {...Mixed} parameters Values for $N replacements
* @return {string} Formatted string
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw-method-format
*/
function format(formatString: string, ...parameters: unknown[]): string;
// types for mw.widgets are out of scope!
const widgets: any;
}
}

Expand Down
1 change: 1 addition & 0 deletions mw/user.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare global {
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.user
*/
namespace user {
// TODO: add types for items in the options map
const options: mw.Map;

const tokens: mw.Map<{
Expand Down

0 comments on commit 9ee28bb

Please sign in to comment.