Jump to content

Manual:Hooks/ContributeCards

From mediawiki.org
ContributeCards
Available from version 1.40.0
Fired on Special:Contribute page to allow extensions to add "card" entry points.
Define function:
public static function onContributeCards( MediaWiki\Specials\Contribute\Card\ContributeCard[] $cards ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"ContributeCards": "MediaWiki\\Extension\\MyExtension\\Hooks::onContributeCards"
	}
}
Called from: File(s): includes/specials/Contribute/ContributeFactory.php
Interface: ContributeCardsHook.php

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


Summary

[edit]

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).