Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
NamespaceIterator | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getIterator | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Utils; |
4 | |
5 | use BatchRowIterator; |
6 | use Iterator; |
7 | use IteratorAggregate; |
8 | use MediaWiki\Extension\Notifications\Iterator\CallbackIterator; |
9 | use MediaWiki\Title\Title; |
10 | use RecursiveIteratorIterator; |
11 | use Wikimedia\Rdbms\IReadableDatabase; |
12 | |
13 | /** |
14 | * Iterates over all titles within the specified namespace. Batches |
15 | * queries into 500 titles at a time starting with the lowest page id. |
16 | */ |
17 | class NamespaceIterator implements IteratorAggregate { |
18 | /** |
19 | * @var IReadableDatabase A wiki database to read from |
20 | */ |
21 | protected $db; |
22 | |
23 | /** |
24 | * @var int An NS_* namespace to iterate over |
25 | */ |
26 | protected $namespace; |
27 | |
28 | /** |
29 | * @param IReadableDatabase $db A wiki database to read from |
30 | * @param int $namespace An NS_* namespace to iterate over |
31 | */ |
32 | public function __construct( IReadableDatabase $db, $namespace ) { |
33 | $this->db = $db; |
34 | $this->namespace = $namespace; |
35 | } |
36 | |
37 | /** |
38 | * @return Iterator<Title> |
39 | */ |
40 | public function getIterator() { |
41 | $it = new BatchRowIterator( |
42 | $this->db, |
43 | /* tables */ [ 'page' ], |
44 | /* pk */ 'page_id', |
45 | /* rows per batch */ 500 |
46 | ); |
47 | $it->addConditions( [ |
48 | 'page_namespace' => $this->namespace, |
49 | ] ); |
50 | $it->setFetchColumns( [ 'page_title' ] ); |
51 | $it->setCaller( __METHOD__ ); |
52 | $it = new RecursiveIteratorIterator( $it ); |
53 | |
54 | $namespace = $this->namespace; |
55 | return new CallbackIterator( $it, static function ( $row ) use ( $namespace ) { |
56 | return Title::makeTitle( $namespace, $row->page_title ); |
57 | } ); |
58 | } |
59 | } |