3 * Holders of revision list for a single page
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 use MediaWiki\Page\PageIdentity
;
24 use MediaWiki\Title\Title
;
25 use Wikimedia\Rdbms\IDatabase
;
26 use Wikimedia\Rdbms\IResultWrapper
;
29 * List for revision table items for a single page
31 abstract class RevisionListBase
extends ContextSource
implements Iterator
{
32 use DeprecationHelper
;
34 /** @var PageIdentity */
37 /** @var int[]|null */
40 /** @var IResultWrapper|false */
43 /** @var RevisionItemBase|false */
47 * Construct a revision list for a given page identity
48 * @param IContextSource $context
49 * @param PageIdentity $page
51 public function __construct( IContextSource
$context, PageIdentity
$page ) {
52 $this->setContext( $context );
55 $this->deprecatePublicPropertyFallback(
59 return Title
::newFromPageIdentity( $this->page
);
61 function ( PageIdentity
$page ) {
68 * @return PageIdentity
70 public function getPage(): PageIdentity
{
75 * @internal for use by RevDelItems
78 public function getPageName(): string {
79 return Title
::newFromPageIdentity( $this->page
)->getPrefixedText();
83 * Select items only where the ID is any of the specified values
86 public function filterByIds( array $ids ) {
91 * Get the internal type name of this list. Equal to the table name.
92 * Override this function.
95 public function getType() {
100 * Initialise the current iteration pointer
102 protected function initCurrent() {
103 $row = $this->res
->current();
105 $this->current
= $this->newItem( $row );
107 $this->current
= false;
112 * Start iteration. This must be called before current() or next().
113 * @return RevisionItemBase First list item
115 public function reset() {
117 $this->res
= $this->doQuery( wfGetDB( DB_REPLICA
) );
119 $this->res
->rewind();
121 $this->initCurrent();
122 return $this->current
;
125 public function rewind(): void
{
130 * Get the current list item, or false if we are at the end
131 * @return RevisionItemBase|false
133 #[\ReturnTypeWillChange]
134 public function current() {
135 return $this->current
;
139 * Move the iteration pointer to the next list item, and return it.
140 * @return RevisionItemBase
141 * @suppress PhanParamSignatureMismatchInternal
143 #[\ReturnTypeWillChange]
144 public function next() {
146 $this->initCurrent();
147 return $this->current
;
150 public function key(): int {
151 return $this->res ?
$this->res
->key() : 0;
154 public function valid(): bool {
155 return $this->res
&& $this->res
->valid();
159 * Get the number of items in the list.
162 public function length() {
166 return $this->res
->numRows();
171 * Do the DB query to iterate through the objects.
172 * @param IDatabase $db DB object to use for the query
173 * @return IResultWrapper
175 abstract public function doQuery( $db );
178 * Create an item object from a DB result row
179 * @param stdClass $row
180 * @return RevisionItemBase
182 abstract public function newItem( $row );