Manual:Hooks/GetBetaFeaturePreferences

From MediaWiki.org
Jump to: navigation, search
GetBetaFeaturePreferences
Available from version 1.22.0
Register preferences that enable experimental features. Only available with Extension:BetaFeatures.
Define function:
public static function onGetBetaFeaturePreferences( User $user, array &$betaPrefs ) { ... }
Attach hook:
$wgHooks['GetBetaFeaturePreferences'][] = 'MyExtensionHooks::onGetBetaFeaturePreferences';
Called from: File(s): BetaFeatures / BetaFeaturesHooks.php

For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:GetBetaFeaturePreferences extensions.

Details[edit]

  • $user: User whose preferences are being modified.
  • &$betaPrefs: Array of beta features. Each key is the identifier of the feature and the associated value is an array with the keys:
    • label-message: (required) message key for the title of the feature
    • desc-message: (required) message key for the description of the feature
    • screenshot: (optional) either the path to an image representing the feature, either an array whose the keys are language codes or 'rtl' or 'ltr' for language-specific or language-direction-specific images; it can be used the global variable $wgExtensionAssetsPath
    • requirements: (optional) array with keys:
      • betafeatures: array of required preferences before activating this feature
      • blacklist: array of user agents blacklisted by this feature, this is only added in JavaScript variables
      • skins: array of skins supported by the feature
    • info-link: (optional) URL pointing to the description of the feature
    • info-message: (optional) message key containing an URL pointing to the description of the feature
    • discussion-link: (optional) URL pointing to a discussion page of the feature
    • discussion-message: (optional) message key containing an URL pointing to the description of the feature
    • auto-enrollment: (optional) when this feature is enabled, enable other features whose the group value is given by this auto-enrollment value
    • group: (optional) this feature can be enabled when the "parent" feature with a corresponding auto-enrollment name is enabled
    • dependent: (optional) if true, run for this feature the hook registered by the GetBetaFeatureDependencyHooks hook

Example[edit]

// MyExtension.php
$wgAutoloadClasses['MyExtensionHooks'] = __DIR__ . '/MyExtensionHooks.php';
$wgHooks['GetBetaFeaturePreferences'][] = 'MyExtensionHooks::getPreferences';
// MyExtensionHooks.php
class MyExtensionHooks {

    static function getPreferences( $user, &$prefs ) {
        global $wgExtensionAssetsPath;

        $prefs['my-awesome-feature'] = array(
            // The first two are message keys
            'label-message' => 'beta-feature-message',
            'desc-message' => 'beta-feature-description',
            // Path to an image that represents the feature
            'screenshot' => $wgExtensionAssetsPath . '/MyExtension/images/screenshot.png',
            // Link to information on the feature - use subpages on mw.org, maybe?
            'info-link' => 'https://mediawiki.org/wiki/Extension:MyExtension',
            // Link to discussion about the feature - talk pages might work
            'discussion-link' => 'https://mediawiki.org/wiki/Extension_talk:MyExtension',
        );
    }
}
// SpecialMyExtension.php
class SpecialMyExtension extends SpecialPage {

    public function execute() {
        if ( BetaFeatures::isFeatureEnabled( $this->getUser(), 'my-awesome-feature' ) ) {
            // Implement the feature!
        }
    }
}