확장 기능:베타기능
BetaFeatures 출시 상태: 안정 |
|
---|---|
구현 | 미디어, 훅 , 데이터베이스 |
설명 | Allows other extensions to register their beta features in the user preferences |
만든 이 | Mark Holmquist (MarkTraceur토론) |
최신 버전 | 0.1 (Continous updates) |
호환성 정책 | 스냅샷은 미디어위키와 함께 릴리스됩니다. Master is not backward compatible. |
MediaWiki | 1.25+ |
PHP | 5.4+ |
데이터베이스 변경 | 예 |
테이블 | betafeatures_user_counts |
라이선스 | GNU General Public License 2.0 or later |
다운로드 | |
예제 | Special:Preferences#mw-prefsection-betafeatures |
Special |
|
|
|
Quarterly downloads | 36 (Ranked 88th) |
Public wikis using | 1,031 (Ranked 249th) |
BetaFeatures 확장 기능 번역 (translatewiki.net에서 가능한 경우) | |
이슈 | 미해결 작업 · 버그 보고 |
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.
설치
- 파일을 다운로드하고
BetaFeatures
폴더를extensions/
디렉토리에 넣어 주세요.
개발자와 코딩 기여자는 Git을 이용해 확장기능을 다운받는 것이 좋습니다.cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/BetaFeatures - 아래의 코드를 LocalSettings.php 코드의 마지막에 추가합니다.
wfLoadExtension( 'BetaFeatures' );
- 갱신 스크립트를 실행합니다. 이 스크립트는 이 확장기능을 필요로 하는 데이터 베이스 테이블을 자동적으로 작성합니다.
- Configure as required.
- 완료 – 위키의 ‘Special:Version’에 이동해서, 확장기능이 올바르게 설치된 것을 확인합니다.
새 훅을 당신의 확장 기능에 사용하기
Using this extension to support your beta feature is easy. Register a hook of type GetBetaFeaturePreferences
in your extension.json
file — the syntax is almost identical to the GetPreferences
hook, with small changes to support the type of preference we need in this case.
In extension.json
:
"Hooks": {
"GetBetaFeaturePreferences": "MediaWiki\\Extension\\MyExtension\\Hooks::onGetBetaFeaturePreferences"
},
In MyExtension/includes/Hooks.php
:
namespace MediaWiki\Extension\MyExtension;
class Hooks {
public static function onGetBetaFeaturePreferences( User $user, array &$betaPrefs ) {
$extensionAssetsPath = MediaWikiServices::getInstance()
->getMainConfig()
->get( 'ExtensionAssetsPath' );
$betaPrefs['myextension-awesome-feature'] = [
// The first two are message keys
'label-message' => 'myextension-awesome-feature-message',
'desc-message' => 'myextension-awesome-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' => "$extensionAssetsPath/MyExtension/images/screenshot-ru.png",
'ltr' => "$extensionAssetsPath/MyExtension/images/screenshot-ltr.png",
'rtl' => "$extensionAssetsPath/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/MyFeature',
// Link to discussion about the feature - talk pages might work
'discussion-link' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help_talk:Extension:MyExtension/MyFeature',
];
}
}
'label-message'
, 'desc-message'
, 'info-link'
, and 'discussion-link'
are required. Please be sure you use all of them!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.
If you want to also use your extension without BetaFeatures, you should also check for its existence, e.g.:
if (
!ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' )
|| \BetaFeatures::isFeatureEnabled( $user, 'my-awesome-feature' )
) {
// Implement the feature!
}
설정
The $wgBetaFeaturesWhitelist
config variable can be used to limit which beta features are shown in preferences.
By default it is empty, and all beta features are shown.
If it is used then in order for a beta feature to show up in the preferences it needs to be listed in the whitelist.
This config variable accepts an array of strings.
Each string should be the name of a beta feature as specified in the preference definition passed to onGetBetaFeaturePreferences()
.
For example, in the code given above, the name of the beta feature is myextension-awesome-feature
, so you would need to add that string to the $wgBetaFeaturesWhitelist
array in your wiki's configuration:
$wgBetaFeaturesWhitelist = [
'myextension-awesome-feature'
];
고급 사용
정말 멋진 것을 보고 싶으신가요?
Auto-enroll groups
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',
);
}
}
Dependency management
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.
Database stuff
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.
Troubleshootings
Usage counts
The usage counts might not reflect exactly the number of users having some beta features activated at this precise moment. These should be interpreted as approximate numbers.
This number is computed by a job, which could be delayed or long-running. In the past, there was also a 30-minutes cache on these figures.
같이 보기
이 확장 기능은 하나 이상의 위키미디어 프로젝트에서 사용 중입니다. 이것은 아마도 이 확장 기능이 안정적이고 트래픽이 많은 웹 사이트에서 사용할 수 있을 만큼 충분히 잘 작동한다는 것을 의미합니다. 설치된 위치를 확인하려면 위키미디어의 CommonSettings.php 및 InitialiseSettings.php 구성 파일에서 이 확장 기능의 이름을 찾습니다. 특정 위키에 설치된 확장 기능의 전체 목록은 위키의 Special:Version 문서에서 볼 수 있습니다. |
This extension is included in the following wiki farms/hosts and/or packages: This is not an authoritative list. Some wiki farms/hosts and/or packages may contain this extension even if they are not listed here. Always check with your wiki farms/hosts or bundle to confirm. |
- Stable extensions/ko
- Media handling extensions/ko
- Hook extensions/ko
- Database extensions/ko
- GPL licensed extensions/ko
- Extensions in Wikimedia version control/ko
- ExtensionTypes extensions/ko
- GetPreferences extensions/ko
- LoadExtensionSchemaUpdates extensions/ko
- MakeGlobalVariablesScript extensions/ko
- PreferencesGetIcon extensions/ko
- SaveUserOptions extensions/ko
- SkinTemplateNavigation::Universal extensions/ko
- UserGetDefaultOptions extensions/ko
- All extensions/ko
- Extensions used on Wikimedia/ko
- Extensions included in Canasta/ko
- Extensions included in Miraheze/ko
- Extensions included in WikiForge/ko
- Beta Features/ko