Skip to content

Commit

Permalink
Add mw.user.clientPrefs
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien LESÉNÉCHAL committed Jan 31, 2024
1 parent 8dc2b41 commit 3710cc8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions mw/user.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,50 @@ interface UserTokens extends Record<string, string> {
}

export interface User {
/**
* Manage client preferences
*
* For skins that enable the `clientPrefEnabled` option (see Skin class in PHP),
* this feature allows you to store preferences in the browser session that will
* switch one or more the classes on the HTML document.
*
* This is only supported for unregistered users. For registered users, skins
* and extensions must use user preferences (e.g. hidden or API-only options)
* and swap class names server-side through the Skin interface.
*
* This feature is limited to page views by unregistered users. For logged-in requests,
* store preferences in the database instead, via UserOptionsManager or mw.Api#saveOption
* (may be hidden or API-only to exclude from Special:Preferences), and then include the
* desired classes directly in Skin::getHtmlElementAttributes.
*
* Classes toggled by this feature must be named as `<feature>-clientpref-<value>`,
* where `value` contains only alphanumerical characters (a-zA-Z0-9), and `feature`
* can also include hyphens.
*/
clientPrefs: {
/**
* Retrieve the current value of the feature from the HTML document element
*
* @param {string} feature
* @return {false|string} returns false if the feature is not recognized.
* returns string if a feature was found.
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.user.clientPrefs-method-get
*/
get(feature: string): false | string;

/**
* Change the class on the HTML document element, and save the value in a cookie
*
* @param {string} feature
* @param {string} value
* @return {boolean} True if feature was stored successfully, false if the value
* uses a forbidden character or the feature is not recognised
* e.g. a matching class was not defined on the HTML document element.
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.user.clientPrefs-method-set
*/
set(feature: string, value: string): boolean;
};

/**
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.user-property-options
*/
Expand Down

0 comments on commit 3710cc8

Please sign in to comment.