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 Wikimedia\Rdbms\ResultWrapper
;
24 use Wikimedia\Rdbms\IDatabase
;
27 * List for revision table items for a single page
29 abstract class RevisionListBase
extends ContextSource
implements Iterator
{
36 /** @var ResultWrapper|bool */
39 /** @var bool|Revision */
43 * Construct a revision list for a given title
44 * @param IContextSource $context
47 function __construct( IContextSource
$context, Title
$title ) {
48 $this->setContext( $context );
49 $this->title
= $title;
53 * Select items only where the ID is any of the specified values
56 function filterByIds( array $ids ) {
61 * Get the internal type name of this list. Equal to the table name.
62 * Override this function.
65 public function getType() {
70 * Initialise the current iteration pointer
72 protected function initCurrent() {
73 $row = $this->res
->current();
75 $this->current
= $this->newItem( $row );
77 $this->current
= false;
82 * Start iteration. This must be called before current() or next().
83 * @return Revision First list item
85 public function reset() {
87 $this->res
= $this->doQuery( wfGetDB( DB_REPLICA
) );
92 return $this->current
;
95 public function rewind() {
100 * Get the current list item, or false if we are at the end
103 public function current() {
104 return $this->current
;
108 * Move the iteration pointer to the next list item, and return it.
110 * @suppress PhanParamSignatureMismatchInternal
112 public function next() {
114 $this->initCurrent();
115 return $this->current
;
118 public function key() {
119 return $this->res ?
$this->res
->key() : 0;
122 public function valid() {
123 return $this->res ?
$this->res
->valid() : false;
127 * Get the number of items in the list.
130 public function length() {
134 return $this->res
->numRows();
139 * Do the DB query to iterate through the objects.
140 * @param IDatabase $db DB object to use for the query
142 abstract public function doQuery( $db );
145 * Create an item object from a DB result row
148 abstract public function newItem( $row );