Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| ContributionsSegment | |
100.00% |
13 / 13 |
|
100.00% |
8 / 8 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| getTagsForRevision | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRevisions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getBefore | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAfter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDeltaForRevision | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isNewest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isOldest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Revision; |
| 4 | |
| 5 | use MediaWiki\Message\Message; |
| 6 | |
| 7 | /** |
| 8 | * @newable |
| 9 | * @since 1.35 |
| 10 | */ |
| 11 | class ContributionsSegment { |
| 12 | |
| 13 | /** |
| 14 | * @var RevisionRecord[] |
| 15 | */ |
| 16 | private $revisions; |
| 17 | |
| 18 | /** |
| 19 | * @var string[][] |
| 20 | */ |
| 21 | private $tags; |
| 22 | |
| 23 | /** |
| 24 | * @var string|null |
| 25 | */ |
| 26 | private $before; |
| 27 | |
| 28 | /** |
| 29 | * @var string|null |
| 30 | */ |
| 31 | private $after; |
| 32 | |
| 33 | /** |
| 34 | * @var array |
| 35 | */ |
| 36 | private $deltas; |
| 37 | |
| 38 | /** |
| 39 | * @var array |
| 40 | */ |
| 41 | private $flags; |
| 42 | |
| 43 | /** |
| 44 | * @param RevisionRecord[] $revisions |
| 45 | * @param string[][] $tags Associative array mapping revision IDs to a map of tag names to Message objects |
| 46 | * @param string|null $before |
| 47 | * @param string|null $after |
| 48 | * @param int[] $deltas An associative array mapping a revision Id to the difference in size of this revision |
| 49 | * and its parent revision. Values may be null if the size difference is unknown. |
| 50 | * @param array $flags Is an associative array, known fields are: |
| 51 | * - newest: bool indicating whether this segment is the newest in time |
| 52 | * - oldest: bool indicating whether this segment is the oldest in time |
| 53 | */ |
| 54 | public function __construct( |
| 55 | array $revisions, |
| 56 | array $tags, |
| 57 | ?string $before, |
| 58 | ?string $after, |
| 59 | array $deltas = [], |
| 60 | array $flags = [] |
| 61 | ) { |
| 62 | $this->revisions = $revisions; |
| 63 | $this->tags = $tags; |
| 64 | $this->before = $before; |
| 65 | $this->after = $after; |
| 66 | $this->deltas = $deltas; |
| 67 | $this->flags = $flags; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get tags and associated metadata for a given revision |
| 72 | * |
| 73 | * @param int $revId a revision ID |
| 74 | * |
| 75 | * @return Message[] Associative array mapping tag name to a Message object storing tag display data |
| 76 | */ |
| 77 | public function getTagsForRevision( $revId ): array { |
| 78 | return $this->tags[$revId] ?? []; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @return RevisionRecord[] |
| 83 | */ |
| 84 | public function getRevisions(): array { |
| 85 | return $this->revisions; |
| 86 | } |
| 87 | |
| 88 | public function getBefore(): ?string { |
| 89 | return $this->before; |
| 90 | } |
| 91 | |
| 92 | public function getAfter(): ?string { |
| 93 | return $this->after; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Returns the difference in size of the given revision and its parent revision. |
| 98 | * Returns null if the size difference is unknown. |
| 99 | * @param int $revid Revision id |
| 100 | * @return int|null |
| 101 | */ |
| 102 | public function getDeltaForRevision( int $revid ): ?int { |
| 103 | return $this->deltas[$revid] ?? null; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * The value of the 'newest' field of the flags passed to the constructor, or false |
| 108 | * if that field was not set. |
| 109 | */ |
| 110 | public function isNewest(): bool { |
| 111 | return $this->flags['newest'] ?? false; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * The value of the 'oldest' field of the flags passed to the constructor, or false |
| 116 | * if that field was not set. |
| 117 | */ |
| 118 | public function isOldest(): bool { |
| 119 | return $this->flags['oldest'] ?? false; |
| 120 | } |
| 121 | |
| 122 | } |