Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
NewsletterLogFormatter | |
0.00% |
0 / 24 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
getMessageParameters | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
42 | |||
formatParameterValue | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Newsletter\Logging; |
4 | |
5 | use LogFormatter; |
6 | use MediaWiki\Message\Message; |
7 | use MediaWiki\SpecialPage\SpecialPage; |
8 | use MediaWiki\Title\Title; |
9 | use MediaWiki\User\User; |
10 | |
11 | /** |
12 | * Log formatter for Extension:Newsletter log messages |
13 | * |
14 | * @license GPL-2.0-or-later |
15 | * @author Tyler Romeo |
16 | */ |
17 | class NewsletterLogFormatter extends LogFormatter { |
18 | |
19 | /** |
20 | * Reformat the target as a user link if the target was a user |
21 | * @return array |
22 | */ |
23 | public function getMessageParameters() { |
24 | if ( $this->parsedParameters !== null ) { |
25 | return $this->parsedParameters; |
26 | } |
27 | |
28 | $params = parent::getMessageParameters(); |
29 | if ( $this->entry->getTarget()->inNamespace( NS_USER ) ) { |
30 | $user = User::newFromName( $this->entry->getTarget()->getText() ); |
31 | if ( $user ) { |
32 | $params[2] = Message::rawParam( $this->makeUserLink( $user ) ); |
33 | $params[6] = $user->getName(); |
34 | } |
35 | } |
36 | |
37 | if ( $this->entry->getSubtype() === 'issue-added' && isset( $params[5] ) ) { |
38 | $params[5] = Message::rawParam( $this->makePageLink( Title::newFromText( $params[5] ) ) ); |
39 | } |
40 | |
41 | ksort( $params ); |
42 | $this->parsedParameters = $params; |
43 | return $params; |
44 | } |
45 | |
46 | /** |
47 | * Format an additional parameter type "newsletter-link", whose value is a |
48 | * newsletter ID and name separated by a colon, into a link |
49 | * @param string $type |
50 | * @param string $value |
51 | * @return mixed |
52 | */ |
53 | public function formatParameterValue( $type, $value ) { |
54 | if ( $type !== 'newsletter-link' ) { |
55 | return parent::formatParameterValue( $type, $value ); |
56 | } |
57 | |
58 | [ $id, $name ] = explode( ':', $value, 2 ); |
59 | $title = SpecialPage::getTitleFor( 'Newsletter', $id ); |
60 | if ( !$this->plaintext ) { |
61 | return Message::rawParam( $this->getLinkRenderer()->makeLink( |
62 | $title, |
63 | $name, |
64 | [] |
65 | ) ); |
66 | } else { |
67 | return "[[{$title->getPrefixedText()}|$name]]"; |
68 | } |
69 | } |
70 | |
71 | } |