Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / title / TitleArrayFromResult.php
blob581e8bd84f29f8e472fa5a7ef1f68193c01ee247
1 <?php
2 /**
3 * Class to walk into a list of Title objects.
5 * Note: this entire file is a byte-for-byte copy of UserArrayFromResult.php
6 * with s/User/Title/. If anyone can figure out how to do this nicely
7 * with inheritance or something, please do so.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @file
27 namespace MediaWiki\Title;
29 use Countable;
30 use Iterator;
31 use Wikimedia\Rdbms\IResultWrapper;
33 /**
34 * @newable
35 * @note marked as newable in 1.35 for lack of a better alternative,
36 * but should probably become part of the TitleFactory service.
38 class TitleArrayFromResult implements Countable, Iterator {
39 /** @var IResultWrapper */
40 public $res;
42 /** @var int */
43 public $key;
45 /** @var Title|false */
46 public $current;
48 /**
49 * @stable to call
51 * @param IResultWrapper $res
53 public function __construct( $res ) {
54 $this->res = $res;
55 $this->key = 0;
56 $this->setCurrent( $this->res->current() );
59 /**
60 * @param \stdClass|false $row
61 * @return void
63 protected function setCurrent( $row ) {
64 if ( $row === false ) {
65 $this->current = false;
66 } else {
67 $this->current = Title::newFromRow( $row );
71 /**
72 * @return int
74 public function count(): int {
75 return $this->res->numRows();
78 public function current(): Title {
79 return $this->current;
82 public function key(): int {
83 return $this->key;
86 public function next(): void {
87 $row = $this->res->fetchObject();
88 $this->setCurrent( $row );
89 $this->key++;
92 public function rewind(): void {
93 $this->res->rewind();
94 $this->key = 0;
95 $this->setCurrent( $this->res->current() );
98 /**
99 * @return bool
101 public function valid(): bool {
102 return $this->current !== false;
106 /** @deprecated class alias since 1.41 */
107 class_alias( TitleArrayFromResult::class, 'TitleArrayFromResult' );