Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.95% |
17 / 21 |
|
75.00% |
6 / 8 |
CRAP | |
0.00% |
0 / 1 |
| RevisionCommentBatch | |
80.95% |
17 / 21 |
|
75.00% |
6 / 8 |
8.44 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| authority | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| revisions | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| samePage | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| useParentheses | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| hideIfDeleted | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| indexById | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\CommentFormatter; |
| 4 | |
| 5 | use MediaWiki\Permissions\Authority; |
| 6 | use MediaWiki\Revision\RevisionRecord; |
| 7 | |
| 8 | /** |
| 9 | * Fluent interface for revision comment batch inputs. |
| 10 | * |
| 11 | * @since 1.38 |
| 12 | */ |
| 13 | class RevisionCommentBatch { |
| 14 | /** @var CommentFormatter */ |
| 15 | private $formatter; |
| 16 | /** @var Authority|null */ |
| 17 | private $authority; |
| 18 | /** @var iterable<RevisionRecord> */ |
| 19 | private $revisions; |
| 20 | /** @var bool */ |
| 21 | private $samePage = false; |
| 22 | /** @var bool */ |
| 23 | private $isPublic = false; |
| 24 | /** @var bool */ |
| 25 | private $useParentheses = false; |
| 26 | /** @var bool */ |
| 27 | private $indexById = false; |
| 28 | |
| 29 | public function __construct( CommentFormatter $formatter ) { |
| 30 | $this->formatter = $formatter; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Set the authority to use for permission checks. This must be called |
| 35 | * prior to execute(). |
| 36 | * |
| 37 | * @param Authority $authority |
| 38 | * @return $this |
| 39 | */ |
| 40 | public function authority( Authority $authority ) { |
| 41 | $this->authority = $authority; |
| 42 | return $this; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Set the revisions to extract comments from. |
| 47 | * |
| 48 | * @param iterable<RevisionRecord> $revisions |
| 49 | * @return $this |
| 50 | */ |
| 51 | public function revisions( $revisions ) { |
| 52 | $this->revisions = $revisions; |
| 53 | return $this; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Set the same-page option. If this is true, section links and fragment- |
| 58 | * only wikilinks are rendered with an href that is a fragment-only URL. |
| 59 | * If it is false (the default), such links go to the self link title. |
| 60 | * |
| 61 | * This is equivalent to $local in the old Linker methods. |
| 62 | * |
| 63 | * @param bool $samePage |
| 64 | * @return $this |
| 65 | */ |
| 66 | public function samePage( $samePage = true ) { |
| 67 | $this->samePage = $samePage; |
| 68 | return $this; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Wrap the comment with parentheses. This has no effect if the useBlock |
| 73 | * option is not enabled. |
| 74 | * |
| 75 | * Unlike the legacy Linker::commentBlock(), this option defaults to false |
| 76 | * if this method is not called, since that better preserves the fluent |
| 77 | * style. |
| 78 | * |
| 79 | * @param bool $useParentheses |
| 80 | * @return $this |
| 81 | */ |
| 82 | public function useParentheses( $useParentheses = true ) { |
| 83 | $this->useParentheses = $useParentheses; |
| 84 | return $this; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * If this is true, show the comment only if all users can see it. |
| 89 | * |
| 90 | * We'll call it hideIfDeleted() since public is a keyword and isPublic() |
| 91 | * has an inappropriate verb. |
| 92 | * |
| 93 | * @param bool $isPublic |
| 94 | * @return $this |
| 95 | */ |
| 96 | public function hideIfDeleted( $isPublic = true ) { |
| 97 | $this->isPublic = $isPublic; |
| 98 | return $this; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * If this is true, the array keys in the return value will be the revision |
| 103 | * IDs instead of the keys from the input array. |
| 104 | * |
| 105 | * @param bool $indexById |
| 106 | * @return $this |
| 107 | */ |
| 108 | public function indexById( $indexById = true ) { |
| 109 | $this->indexById = $indexById; |
| 110 | return $this; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Format the comments. |
| 115 | * |
| 116 | * @return string[] Formatted comments. The array key is either the field |
| 117 | * value specified by indexField(), or if that was not called, it is the |
| 118 | * key from the array passed to revisions(). |
| 119 | */ |
| 120 | public function execute() { |
| 121 | return $this->formatter->formatRevisions( |
| 122 | $this->revisions, |
| 123 | $this->authority, |
| 124 | $this->samePage, |
| 125 | $this->isPublic, |
| 126 | $this->useParentheses, |
| 127 | $this->indexById |
| 128 | ); |
| 129 | } |
| 130 | } |