Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
OAuthLogFormatter | |
0.00% |
0 / 38 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getMessageParameters | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getConsumerLink | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
makeUserLink | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
42 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\OAuth\Frontend; |
4 | |
5 | use LogEntry; |
6 | use LogFormatter; |
7 | use MediaWiki\Linker\Linker; |
8 | use MediaWiki\Linker\LinkRenderer; |
9 | use MediaWiki\Message\Message; |
10 | use MediaWiki\Registration\ExtensionRegistry; |
11 | use MediaWiki\Title\Title; |
12 | use MediaWiki\Title\TitleFactory; |
13 | use MediaWiki\User\UserEditTracker; |
14 | use MediaWiki\User\UserIdentity; |
15 | |
16 | /** |
17 | * Formatter for OAuth log events |
18 | */ |
19 | class OAuthLogFormatter extends LogFormatter { |
20 | protected ExtensionRegistry $extensionRegistry; |
21 | protected LinkRenderer $linkRenderer; |
22 | protected TitleFactory $titleFactory; |
23 | protected UserEditTracker $userEditTracker; |
24 | |
25 | public function __construct( |
26 | LogEntry $entry, |
27 | LinkRenderer $linkRenderer, |
28 | TitleFactory $titleFactory, |
29 | UserEditTracker $userEditTracker |
30 | ) { |
31 | parent::__construct( $entry ); |
32 | $this->extensionRegistry = ExtensionRegistry::getInstance(); |
33 | $this->linkRenderer = $linkRenderer; |
34 | $this->titleFactory = $titleFactory; |
35 | $this->userEditTracker = $userEditTracker; |
36 | } |
37 | |
38 | protected function getMessageParameters() { |
39 | $params = parent::getMessageParameters(); |
40 | if ( isset( $params[3] ) ) { |
41 | $params[3] = $this->getConsumerLink( $params[3] ); |
42 | } |
43 | return $params; |
44 | } |
45 | |
46 | protected function getConsumerLink( $consumerKey ) { |
47 | $title = Title::newFromText( 'Special:OAuthListConsumers/view/' . $consumerKey ); |
48 | if ( $this->plaintext ) { |
49 | return '[[' . $title->getPrefixedText() . '|' . $consumerKey . ']]'; |
50 | } else { |
51 | return Message::rawParam( $this->linkRenderer->makeLink( $title, $consumerKey ) ); |
52 | } |
53 | } |
54 | |
55 | /** |
56 | * Add a link to the user's global account list to make review more convenient. |
57 | * @param UserIdentity $user |
58 | * @param int $toolFlags |
59 | * @return string |
60 | */ |
61 | protected function makeUserLink( UserIdentity $user, $toolFlags = 0 ) { |
62 | // Only add custom links if a new consumer is being proposed and we can show tool links. |
63 | if ( $this->entry->getSubtype() !== 'propose' |
64 | || $this->plaintext |
65 | || !$this->linkFlood |
66 | || !$this->extensionRegistry->isLoaded( 'CentralAuth' ) |
67 | ) { |
68 | return parent::makeUserLink( $user, $toolFlags ); |
69 | } |
70 | |
71 | $userLink = Linker::userLink( |
72 | $user->getId(), |
73 | $user->getName() |
74 | ); |
75 | $editCount = $user->getId() |
76 | ? $this->userEditTracker->getUserEditCount( $user ) |
77 | : null; |
78 | |
79 | $toolLinkArray = Linker::userToolLinkArray( |
80 | $user->getId(), |
81 | $user->getName(), |
82 | true, |
83 | $toolFlags, |
84 | $editCount |
85 | ); |
86 | $toolLinkArray[] = $this->linkRenderer->makePreloadedLink( |
87 | $this->titleFactory->newFromTextThrow( 'Special:CentralAuth/' . $user->getName() ), |
88 | wfMessage( 'mwoauth-centralauth-account-link' )->text(), |
89 | 'mw-usertoollinks-oauth-globalaccount' |
90 | ); |
91 | |
92 | return $userLink . Linker::renderUserToolLinksArray( $toolLinkArray, false ); |
93 | } |
94 | |
95 | } |