MediaWiki REL1_39
RowCommentIterator.php
Go to the documentation of this file.
1<?php
2
4
5use ArrayIterator;
7use IteratorIterator;
8use TitleValue;
9use Traversable;
10
24class RowCommentIterator extends IteratorIterator {
26 private $commentStore;
28 private $commentKey;
30 private $namespaceField;
32 private $titleField;
34 private $indexField;
35
41 public function __construct( CommentStore $commentStore, $rows ) {
42 if ( is_array( $rows ) ) {
43 parent::__construct( new ArrayIterator( $rows ) );
44 } else {
45 parent::__construct( $rows );
46 }
47
48 $this->commentStore = $commentStore;
49 }
50
59 public function commentKey( $key ) {
60 $this->commentKey = $key;
61 return $this;
62 }
63
71 public function namespaceField( $field ) {
72 $this->namespaceField = $field;
73 return $this;
74 }
75
83 public function titleField( $field ) {
84 $this->titleField = $field;
85 return $this;
86 }
87
96 public function indexField( $field ) {
97 $this->indexField = $field;
98 return $this;
99 }
100
101 public function key(): string {
102 if ( $this->indexField ) {
103 return parent::current()->{$this->indexField};
104 } else {
105 return parent::key();
106 }
107 }
108
109 public function current(): CommentItem {
110 if ( $this->commentKey === null ) {
111 throw new \RuntimeException( __METHOD__ . ': commentKey must be specified' );
112 }
113 $row = parent::current();
114 $comment = $this->commentStore->getComment( $this->commentKey, $row );
115 $item = new CommentItem( (string)$comment->text );
116 if ( $this->namespaceField && $this->titleField ) {
117 $item->selfLinkTarget( new TitleValue(
118 (int)$row->{$this->namespaceField},
119 (string)$row->{$this->titleField}
120 ) );
121 }
122 return $item;
123 }
124}
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition WebStart.php:82
Handle database storage of comments such as edit summaries and log reasons.
An object to represent one of the inputs to a batch formatting operation.
An adaptor which converts a row iterator into a CommentItem iterator for batch formatting.
namespaceField( $field)
Set the namespace field.
__construct(CommentStore $commentStore, $rows)
commentKey( $key)
Set what CommentStore calls the key – typically a legacy field name which once held a comment.
Represents a page (or page fragment) title within MediaWiki.