Extension:BetaFeatures

From MediaWiki.org
Jump to: navigation, search
This page is a translated version of the page Extension:BetaFeatures and the translation is 36% complete.

Other languages:
العربية • ‎български • ‎català • ‎Deutsch • ‎English • ‎español • ‎suomi • ‎français • ‎עברית • ‎Հայերեն • ‎Bahasa Indonesia • ‎italiano • ‎日本語 • ‎한국어 • ‎polski • ‎português • ‎português do Brasil • ‎русский • ‎sicilianu • ‎سنڌي • ‎中文
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
BetaFeatures

Release status:Extension status estable

BetaFeatures 2013-09-06.png
ImplementaciónTemplate:Extension#type Media, Hook, Database
DescripciónTemplate:Extension#description Permite a otras extensiones registrar sus funcionalidades beta en las preferencias del usuario
Autor(es)Template:Extension#username Mark Holmquist (MarkTraceurtalk)
Latest versionTemplate:Extension#version 0.1 (Continous updates)
MediaWikiTemplate:Extension#mediawiki 1.25+
PHPTemplate:Extension#php 5.4+
Cambios de la base de datosTemplate:Extension#needs-updatephp
LicenciaTemplate:Extension#license GNU General Public License 2.0 or later
Descarga Template:WikimediaDownload/gerritonly
EjemploTemplate:Extension#example Multimedia Alpha site
Espacio de nombresTemplate:Extension#namespace Special
ParámetrosTemplate:Extension#parameters
  • $wgBetaFeaturesWhitelist
  • $wgBeatFeatures
Hooks que usaTemplate:Extension#hook
UserSaveOptionsManual:Hooks/UserSaveOptions
GetPreferencesManual:Hooks/GetPreferences
PersonalUrlsManual:Hooks/PersonalUrls
LoadExtensionSchemaUpdatesManual:Hooks/LoadExtensionSchemaUpdates
MakeGlobalVariablesScriptManual:Hooks/MakeGlobalVariablesScript
ExtensionTypesManual:Hooks/ExtensionTypes

Translate the BetaFeatures extension if it is available at translatewiki.net

Verificar uso y versión de la matriz.

AsuntosPhabricator

Tareas abiertas · Reportar un bug

The BetaFeatures extension allows other MediaWiki extensions to register beta features with the list of user preferences on the wiki. It uses the existing user preferences architecture and a few special pages to accomplish its function.

Instalación[edit]

  • Descarga y extrae los archivos en el directorio «BetaFeatures» dentro del directorio extensions/ existente.
  • Añade el siguiente código a tu LocalSettings.php (preferiblemente al final):
    wfLoadExtension( 'BetaFeatures' );
    
  • Ejecuta el script de actualización, que creará automáticamente las tablas que necesita esta extensión en la base de datos.
  • YesY Listo - Navega a Special:Version en tu wiki para verificar que la apariencia se haya instalado correctamente.

Para quienes usan MediaWiki 1.24 o versiones anteriores:

Estas instrucciones describen la nueva forma de instalar extensiones usando wfLoadExtension(). Si necesitas instalar esta extensión en versiones anteriores (MediaWiki 1.24 y anteriores), debes usar lo siguiente en lugar de wfLoadExtension( 'BetaFeatures' );:

require_once "$IP/extensions/BetaFeatures/BetaFeatures.php";

Using the new hooks in your extension[edit]

Using this extension to support your beta feature is easy. Register a hook of type "GetBetaFeaturePreferences" in your extension's main file - the syntax is almost identical to the GetPreferences hook, with small changes to support the type of preference we need in this case.

// MyExtension.php
$wgAutoloadClasses['MyExtensionHooks'] = __DIR__ . '/MyExtensionHooks.php';
$wgHooks['GetBetaFeaturePreferences'][] = 'MyExtensionHooks::getPreferences';
For now, 'label-message', 'desc-message', 'info-link', and 'discussion-link' are required. Please be sure you use all of them!
// 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',
            // Paths to images that represents the feature.
            // The image is usually different for ltr and rtl languages.
            // Images for specific languages can also specified using the language code.
            'screenshot' => array(
                'ru' => "$wgExtensionAssetsPath/MyExtension/images/screenshot-ru.png",
                'ltr' => "$wgExtensionAssetsPath/MyExtension/images/screenshot-ltr.png",
                'rtl' => "$wgExtensionAssetsPath/MyExtension/images/screenshot-rtl.png",
            ),
            // Link to information on the feature - use subpages on mw.org, maybe?
            'info-link' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/MyFeature',
            // Link to discussion about the feature - talk pages might work
            'discussion-link' => 'https://www.mediawiki.org/wiki/Talk:MyFeature',
        );
    }
}

Then, you can use the convenience function provided by BetaFeatures to check whether the feature is enabled.

// SpecialMyExtension.php
class SpecialMyExtension extends SpecialPage {

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

You can also use a normal preference check, but don't check against truthy or falsy values - use the values from the HTMLFeatureField class.

// SpecialMyExtension.php
class SpecialMyExtension extends SpecialPage {

    public function execute() {
        if ( $this->getUser()->getOption( 'my-awesome-feature' ) === HTMLFeatureField::OPTION_ENABLED ) {
            // Implement the feature!
        }
    }
}

Because the BetaFeatures class should be present everywhere, you could use the convenience function in any hook, special page, or anything else you wanted. Just be aware of potential performance or caching issues you may introduce with those changes.

Uso avanzado[edit]

Want to see something really cool?

Auto-enroll groups[edit]

With this example, we register a preference that's an "auto-enroll" one - if a user checks this, and new features come out that are in a particular group, the user will be automatically enrolled in those features.

// MyExtensionHooks.php
class MyExtensionHooks {

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

        $prefs['my-awesome-feature-auto-enroll'] = array(
            // The first two are message keys
            'label-message' => 'beta-feature-autoenroll-message',
            'desc-message' => 'beta-feature-autoenroll-description',
            // Link to information on the feature - use subpages on mw.org, maybe?
            'info-link' => 'https://wwww.mediawiki.org/wiki/Special:MyLanguage/MyFeature',
            // Link to discussion about the feature - talk pages might work
            'discussion-link' => 'https://www.mediawiki.org/wiki/Talk:MyFeature',
            // Enable auto-enroll for this group
            'auto-enrollment' => 'my-awesome-feature-group',
        );

        $prefs['my-awesome-feature'] = array(
            // The first two are message keys
            'label-message' => 'beta-feature-message',
            'desc-message' => 'beta-feature-description',
            // Paths to images that represents the feature.
            // The image is usually different for ltr and rtl languages.
            // Images for specific languages can also specified using the language code.
            'screenshot' => array(
                'ru' => "$wgExtensionAssetsPath/MyExtension/images/screenshot-ru.png",
                'ltr' => "$wgExtensionAssetsPath/MyExtension/images/screenshot-ltr.png",
                'rtl' => "$wgExtensionAssetsPath/MyExtension/images/screenshot-rtl.png",
            ),
            // Link to information on the feature - use subpages on mw.org, maybe?
            'info-link' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:MyExtension/SomeFeature',
            // Link to discussion about the feature - talk pages might work
            'discussion-link' => 'https://www.mediawiki.org/wiki/Extension_talk:MyExtension/SomeFeature',
            // Add feature to this group
            'group' => 'my-awesome-feature-group',
        );
    }
}

Administración de dependencias[edit]

Next up, we can actually define dependency management per-feature. To do this we first register the name of a hook that we want to use for this with the hook "GetBetaFeatureDependencyHooks", then we register a hook of that type that checks some dependency, and returns true if it's met or false if not.

// MyExtension.php
$wgAutoloadClasses['MyExtensionHooks'] = __DIR__ . '/MyExtensionHooks.php';
Hooks::register( 'GetBetaFeaturePreferences', 'MyExtensionHooks::getPreferences' );
Hooks::register( 'GetBetaFeatureDependencyHooks', 'MyExtensionHooks::getDependencyCallbacks' );
Hooks::register( 'CheckDependenciesForMyExtensionFeature', 'MyExtensionHooks::checkDependencies' );
// 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',
            // Paths to images that represents the feature.
            // The image is usually different for ltr and rtl languages.
            // Images for specific languages can also specified using the language code.
            'screenshot' => array(
                'ru' => "$wgExtensionAssetsPath/MyExtension/images/screenshot-ru.png",
                'ltr' => "$wgExtensionAssetsPath/MyExtension/images/screenshot-ltr.png",
                'rtl' => "$wgExtensionAssetsPath/MyExtension/images/screenshot-rtl.png",
            ),
            // Link to information on the feature - use subpages on mw.org, maybe?
            'info-link' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:MyExtension/SomeFeature',
            // Link to discussion about the feature - talk pages might work
            'discussion-link' => 'https://www.mediawiki.org/wiki/Extension_talk:MyExtension/SomeFeature',
            // Mark as dependent on something
            'dependent' => true,
        );
    }

    static function getDependencyCallbacks( &$depHooks ) {
        $depHooks['my-awesome-feature'] = 'CheckDependenciesForMyExtensionFeature';
        return true;
    }

    static function checkDependencies() {
        $dependenciesMet = false;
        // Do some fancy checking and return the result
        return $dependenciesMet;
    }
}

You can abuse use this feature to do per-wiki disabling of features, if they're marked as dependent. But that sounds really hacky. You probably shouldn't. I can hear you thinking about it right now, just stop it.

Consideraciones sobre la base de datos[edit]

There's a database table (betafeatures_user_counts) defined, and used, by BetaFeatures. But you might get confused by it if you try to use it locally.

We use the job queue to run updates for this table, when the cache expires (30 minutes TTL). If your wiki is configured to run jobs on each request, this will make about one request every 30 minutes reeeeeeally slow, but the rest will be relatively fast. If you configure your wiki to run jobs via cron, things will work much better.

Véase también[edit]