Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
FlaggedRevsReviewLogFormatter | |
0.00% |
0 / 40 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getMessageKey | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
getActionLinks | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
42 |
1 | <?php |
2 | |
3 | use MediaWiki\Logging\LogEntry; |
4 | use MediaWiki\Logging\LogFormatter; |
5 | use MediaWiki\Revision\RevisionLookup; |
6 | |
7 | class FlaggedRevsReviewLogFormatter extends LogFormatter { |
8 | private bool $isDeapproval = false; |
9 | private RevisionLookup $revisionLookup; |
10 | |
11 | public function __construct( |
12 | LogEntry $entry, |
13 | RevisionLookup $revisionLookup |
14 | ) { |
15 | parent::__construct( $entry ); |
16 | $this->revisionLookup = $revisionLookup; |
17 | } |
18 | |
19 | /** |
20 | * @inheritDoc |
21 | */ |
22 | protected function getMessageKey(): string { |
23 | $rawAction = $this->entry->getSubtype(); |
24 | if ( !str_starts_with( $rawAction, 'a' ) ) { |
25 | // unapprove, unapprove2 |
26 | $this->isDeapproval = true; |
27 | return 'logentry-review-unapprove'; |
28 | } elseif ( str_ends_with( $rawAction, 'a' ) ) { |
29 | // approve-a, approve2-a, approve-ia, approve2-ia |
30 | return 'logentry-review-approve-auto'; |
31 | } else { |
32 | // approve, approve2, approve-i, approve2-i |
33 | return 'logentry-review-approve'; |
34 | } |
35 | } |
36 | |
37 | /** |
38 | * @inheritDoc |
39 | */ |
40 | public function getActionLinks(): string { |
41 | $title = $this->entry->getTarget(); |
42 | $params = $this->entry->getParameters(); |
43 | $links = ''; |
44 | # Show link to page with oldid=x as well as the diff to the former stable rev. |
45 | # Param format is <rev id, last stable id, rev timestamp>. |
46 | if ( isset( $params[0] ) ) { |
47 | $revId = (int)$params[0]; // the revision reviewed |
48 | $oldStable = (int)( $params[1] ?? 0 ); |
49 | # Show diff to changes since the prior stable version |
50 | if ( $oldStable && $revId > $oldStable ) { |
51 | $msg = $this->isDeapproval |
52 | ? 'review-logentry-diff2' // unreviewed |
53 | : 'review-logentry-diff'; // reviewed |
54 | $links .= '('; |
55 | $links .= $this->getLinkRenderer()->makeKnownLink( |
56 | $title, |
57 | $this->msg( $msg )->text(), |
58 | [], |
59 | [ 'oldid' => $oldStable, 'diff' => $revId ] |
60 | ); |
61 | $links .= ')'; |
62 | } |
63 | # Show a diff link to this revision |
64 | $ts = empty( $params[2] ) |
65 | ? $this->revisionLookup->getTimestampFromId( $revId ) |
66 | : $params[2]; |
67 | $time = $this->context->getLanguage()->timeanddate( $ts, true ); |
68 | $links .= ' ('; |
69 | $links .= $this->getLinkRenderer()->makeKnownLink( |
70 | $title, |
71 | $this->msg( 'review-logentry-id', $revId, $time )->text(), |
72 | [], |
73 | [ 'oldid' => $revId, 'diff' => 'prev' ] |
74 | ); |
75 | $links .= ')'; |
76 | } |
77 | return $links; |
78 | } |
79 | } |