Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| QueueRecord | |
0.00% |
0 / 25 |
|
0.00% |
0 / 9 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| getLastReviewedByUserId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPageId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getReviewedStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isNominatedForDeletion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCreatedTimestamp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTagsUpdatedTimestamp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getReviewedUpdatedTimestamp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\PageTriage; |
| 4 | |
| 5 | use JsonSerializable; |
| 6 | |
| 7 | /** |
| 8 | * Value object for PageTriage queue items. |
| 9 | */ |
| 10 | class QueueRecord implements JsonSerializable { |
| 11 | |
| 12 | /** |
| 13 | * The article is in an unreviewed state. "Needs review" is probably more accurate, as the |
| 14 | * article can go between reviewed and back to unreviewed state if a PageTriage user marks |
| 15 | * it as "unreviewed". |
| 16 | */ |
| 17 | public const REVIEW_STATUS_UNREVIEWED = 0; |
| 18 | /** |
| 19 | * The article has been reviewed by a Special:NewPagesFeed user. |
| 20 | */ |
| 21 | public const REVIEW_STATUS_REVIEWED = 1; |
| 22 | /** |
| 23 | * Set when an article is added to the page triage queue via the MarkPatrolledComplete hook. |
| 24 | */ |
| 25 | public const REVIEW_STATUS_PATROLLED = 2; |
| 26 | /** |
| 27 | * The article was auto-patrolled. |
| 28 | */ |
| 29 | public const REVIEW_STATUS_AUTOPATROLLED = 3; |
| 30 | |
| 31 | public const VALID_REVIEW_STATUSES = [ |
| 32 | self::REVIEW_STATUS_UNREVIEWED, |
| 33 | self::REVIEW_STATUS_REVIEWED, |
| 34 | self::REVIEW_STATUS_PATROLLED, |
| 35 | self::REVIEW_STATUS_AUTOPATROLLED |
| 36 | ]; |
| 37 | |
| 38 | /** @var int */ |
| 39 | private int $pageId; |
| 40 | /** @var int */ |
| 41 | private int $reviewedStatus; |
| 42 | /** @var bool */ |
| 43 | private bool $isNominatedForDeletion; |
| 44 | /** @var string */ |
| 45 | private string $createdTimestamp; |
| 46 | /** @var null|string */ |
| 47 | private ?string $tagsUpdatedTimestamp; |
| 48 | /** @var string */ |
| 49 | private string $reviewedUpdatedTimestamp; |
| 50 | /** @var int */ |
| 51 | private int $lastReviewedByUserId; |
| 52 | |
| 53 | /** |
| 54 | * @param int $pageId |
| 55 | * @param int $reviewedStatus |
| 56 | * @param bool $isNominatedForDeletion |
| 57 | * @param string $createdTimestamp |
| 58 | * @param null|string $tagsUpdatedTimestamp |
| 59 | * @param string $reviewedUpdatedTimestamp |
| 60 | * @param int $lastReviewedByUserId |
| 61 | */ |
| 62 | public function __construct( |
| 63 | int $pageId, |
| 64 | int $reviewedStatus, |
| 65 | bool $isNominatedForDeletion, |
| 66 | string $createdTimestamp, |
| 67 | ?string $tagsUpdatedTimestamp, |
| 68 | string $reviewedUpdatedTimestamp, |
| 69 | int $lastReviewedByUserId |
| 70 | ) { |
| 71 | $this->pageId = $pageId; |
| 72 | $this->reviewedStatus = $reviewedStatus; |
| 73 | $this->isNominatedForDeletion = $isNominatedForDeletion; |
| 74 | $this->createdTimestamp = $createdTimestamp; |
| 75 | $this->tagsUpdatedTimestamp = $tagsUpdatedTimestamp; |
| 76 | $this->reviewedUpdatedTimestamp = $reviewedUpdatedTimestamp; |
| 77 | $this->lastReviewedByUserId = $lastReviewedByUserId; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @return int The ID of the user who last reviewed the article associated with this item. |
| 82 | */ |
| 83 | public function getLastReviewedByUserId(): int { |
| 84 | return $this->lastReviewedByUserId; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @return int The page ID associated with the queue record's article. |
| 89 | */ |
| 90 | public function getPageId(): int { |
| 91 | return $this->pageId; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @return int An integer reflecting the review status. Valid values are in self::VALID_REVIEW_STATUSES |
| 96 | */ |
| 97 | public function getReviewedStatus(): int { |
| 98 | return $this->reviewedStatus; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @return bool true if the associated page has been nominated for deletion, false otherwise. |
| 103 | */ |
| 104 | public function isNominatedForDeletion(): bool { |
| 105 | return $this->isNominatedForDeletion; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @return string TS_MW timestamp of when the queue record was created. |
| 110 | */ |
| 111 | public function getCreatedTimestamp(): string { |
| 112 | return $this->createdTimestamp; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @return null|string TS_MW timestamp of when the metadata for this record was updated, or null |
| 117 | * if that has not yet occurred. |
| 118 | */ |
| 119 | public function getTagsUpdatedTimestamp(): ?string { |
| 120 | return $this->tagsUpdatedTimestamp; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @return string TW_MW timestamp of when the article was last reviewed. |
| 125 | */ |
| 126 | public function getReviewedUpdatedTimestamp(): string { |
| 127 | return $this->reviewedUpdatedTimestamp; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @return array Returns an array suitable for insertion into the pagetriage_page table. Arguably |
| 132 | * such a mapping shouldn't be defined in this class, but creating e.g. a formatter class for doing |
| 133 | * so seems like unnecessary paperwork. |
| 134 | */ |
| 135 | public function jsonSerialize(): array { |
| 136 | $data = [ |
| 137 | 'ptrp_page_id' => $this->getPageId(), |
| 138 | 'ptrp_reviewed' => $this->getReviewedStatus(), |
| 139 | 'ptrp_deleted' => (int)$this->isNominatedForDeletion(), |
| 140 | 'ptrp_created' => $this->getCreatedTimestamp(), |
| 141 | 'ptrp_tags_updated' => $this->getTagsUpdatedTimestamp(), |
| 142 | 'ptrp_reviewed_updated' => $this->getReviewedUpdatedTimestamp(), |
| 143 | 'ptrp_last_reviewed_by' => $this->getLastReviewedByUserId(), |
| 144 | ]; |
| 145 | // Tags are set separately via ArticleMetadata so exclude this field on insert, as we don't know |
| 146 | // the timestamp value of when the tags will have been updated. |
| 147 | unset( $data['ptrp_tags_updated'] ); |
| 148 | return $data; |
| 149 | } |
| 150 | } |