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