Manual:Hooks/ContributeCards
From Linux Web Expert
ContributeCards | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> Fired on Special:Contribute page to allow extensions to add "card" entry points. | |
<translate> Define function:</translate> | public static function onContributeCards( MediaWiki\Specials\Contribute\Card\ContributeCard[] $cards ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"ContributeCards": "MediaWiki\\Extension\\MyExtension\\Hooks::onContributeCards"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> includes/specials/Contribute/ContributeFactory.php |
<translate> Interface:</translate> | ContributeCardsHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:ContributeCards extensions</tvar>.</translate>
Summary
Add/Edit cards with onContributeCards hook. These are examples (without i18n):
"Hooks": {
"ContributeCards": "MediaWiki\\Extension\\ExtensionName\\Hooks::onContributeCards"
}
And in ExtensionName/includes/Hooks.php
:
namespace MediaWiki\Extension\ExtensionName;
use MediaWiki\Specials\Contribute\Card\ContributeCard;
use MediaWiki\Specials\Contribute\Card\ContributeCardActionLink;
class Hooks {
public static function onContributeCards( ContributeCard[] $cards ) {
$cards[] = ( new ContributeCard(
'Translation',
'Translate one section or a whole article. Make more content available in more languages.',
'language',
new ContributeCardActionLink(
SpecialPage::getTitleFor( 'ContentTranslation' )->getLocalUrl(),
'Start a translation'
)
) )->toArray();
$cards[] = ( new ContributeCard(
'Suggested edits',
'Contribute to MediaWiki',
'lightbulb',
new ContributeCardActionLink(
SpecialPage::getTitleFor( 'Homepage' )->getLocalUrl( [ 'namespace' => -1 ] ) . '#/homepage/suggested-edits',
'View suggested edits'
)
) )->toArray();
$cards[] = ( new ContributeCard(
'Upload media',
'Share educational images, videos, and other media files with a free license.',
'upload',
new ContributeCardActionLink(
SpecialPage::getTitleFor( 'UploadWizard' )->getLocalUrl(),
'Upload a file'
)
) )->toArray();
}
}
The code of the hook callback is the same as for earlier versions (see below).