-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ContributeFactory.php
87 lines (75 loc) 路 2.09 KB
/
ContributeFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace MediaWiki\Specials\Contribute;
use MediaWiki\HookContainer\HookRunner;
use MediaWiki\SpecialPage\SpecialPage;
use MediaWiki\Specials\Contribute\Card\ContributeCard;
use MediaWiki\Specials\Contribute\Card\ContributeCardActionLink;
use MediaWiki\User\UserIdentity;
use MessageLocalizer;
use Skin;
class ContributeFactory {
private MessageLocalizer $localizer;
private HookRunner $hookRunner;
/**
* @param MessageLocalizer $localizer
* @param HookRunner $hookRunner
*/
public function __construct( MessageLocalizer $localizer, HookRunner $hookRunner ) {
$this->localizer = $localizer;
$this->hookRunner = $hookRunner;
}
/**
* @return array
*/
public function getCards(): array {
$cards = [];
$this->hookRunner->onContributeCards( $cards );
$cards[] = ( new ContributeCard(
$this->localizer->msg( 'newpage' )->text(),
$this->localizer->msg( 'newpage-desc' )->text(),
'article',
new ContributeCardActionLink(
SpecialPage::getTitleFor( 'Wantedpages' )->getLocalURL(),
$this->localizer->msg( 'view-missing-pages' )->text()
)
) )->toArray();
return $cards;
}
/**
* Check if the Special:Contribute page is enabled for the current skin
* This can be removed when T323083 is resolved ie. the Special:Contribute feature
* has been shipped by the WMF Language Team.
*
* @param Skin $skin
* @param array $specialContributeSkinsEnabled
*
* @return bool
*/
public static function isEnabledOnCurrentSkin(
Skin $skin,
array $specialContributeSkinsEnabled = []
): bool {
return in_array(
$skin->getSkinName(),
$specialContributeSkinsEnabled
);
}
/**
* @param UserIdentity $viewingUser
* @param ?UserIdentity $targetUser
*
* @return array
*/
public static function getAssociatedNavigationLinks(
UserIdentity $viewingUser,
?UserIdentity $targetUser
): array {
if ( $targetUser === null || !$viewingUser->equals( $targetUser ) ) {
return [];
}
return [
SpecialPage::getTitleFor( 'Contribute' )->getFullText(),
SpecialPage::getTitleFor( 'Contributions', $targetUser->getName() )->getFullText(),
];
}
}