2014-01-26 17:49:18 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Class to walk into a list of Title objects.
|
|
|
|
|
*
|
|
|
|
|
* Note: this entire file is a byte-for-byte copy of UserArrayFromResult.php
|
|
|
|
|
* with s/User/Title/. If anyone can figure out how to do this nicely
|
|
|
|
|
* with inheritance or something, please do so.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2018-04-05 22:06:35 +00:00
|
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
2017-02-19 05:03:13 +00:00
|
|
|
|
2020-06-30 10:13:50 +00:00
|
|
|
/**
|
|
|
|
|
* @newable
|
|
|
|
|
* @note marked as newable in 1.35 for lack of a better alternative,
|
|
|
|
|
* but should probably become part of the TitleFactory service.
|
|
|
|
|
*/
|
2014-01-26 17:49:18 +00:00
|
|
|
class TitleArrayFromResult extends TitleArray implements Countable {
|
2018-04-05 22:06:35 +00:00
|
|
|
/** @var IResultWrapper */
|
2014-05-11 15:34:14 +00:00
|
|
|
public $res;
|
2014-01-26 17:49:18 +00:00
|
|
|
|
2021-08-30 20:08:17 +00:00
|
|
|
/** @var int */
|
2014-05-11 15:34:14 +00:00
|
|
|
public $key;
|
|
|
|
|
|
2021-08-30 20:08:17 +00:00
|
|
|
/** @var Title|false */
|
2014-05-11 15:34:14 +00:00
|
|
|
public $current;
|
2014-01-26 17:49:18 +00:00
|
|
|
|
2020-06-30 10:13:50 +00:00
|
|
|
/**
|
2020-07-13 08:53:06 +00:00
|
|
|
* @stable to call
|
2020-06-30 10:13:50 +00:00
|
|
|
*
|
|
|
|
|
* @param IResultWrapper $res
|
|
|
|
|
*/
|
2019-11-30 23:03:59 +00:00
|
|
|
public function __construct( $res ) {
|
2014-01-26 17:49:18 +00:00
|
|
|
$this->res = $res;
|
|
|
|
|
$this->key = 0;
|
|
|
|
|
$this->setCurrent( $this->res->current() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-06-29 16:14:36 +00:00
|
|
|
* @param bool|stdClass $row
|
2014-01-26 17:49:18 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function setCurrent( $row ) {
|
|
|
|
|
if ( $row === false ) {
|
|
|
|
|
$this->current = false;
|
|
|
|
|
} else {
|
|
|
|
|
$this->current = Title::newFromRow( $row );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function count() {
|
|
|
|
|
return $this->res->numRows();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 20:08:17 +00:00
|
|
|
public function current(): Title {
|
2014-01-26 17:49:18 +00:00
|
|
|
return $this->current;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 20:08:17 +00:00
|
|
|
public function key(): int {
|
2014-01-26 17:49:18 +00:00
|
|
|
return $this->key;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 22:44:25 +00:00
|
|
|
public function next() {
|
2014-01-26 17:49:18 +00:00
|
|
|
$row = $this->res->next();
|
|
|
|
|
$this->setCurrent( $row );
|
|
|
|
|
$this->key++;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 22:44:25 +00:00
|
|
|
public function rewind() {
|
2014-01-26 17:49:18 +00:00
|
|
|
$this->res->rewind();
|
|
|
|
|
$this->key = 0;
|
|
|
|
|
$this->setCurrent( $this->res->current() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2020-05-09 22:44:25 +00:00
|
|
|
public function valid() {
|
2014-01-26 17:49:18 +00:00
|
|
|
return $this->current !== false;
|
|
|
|
|
}
|
2014-03-20 18:59:20 +00:00
|
|
|
}
|