Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ImageQueryPage | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
| outputResults | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
42 | |||
| formatResult | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCellHtml | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Variant of QueryPage which uses a gallery to output results. |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @ingroup SpecialPage |
| 8 | */ |
| 9 | |
| 10 | namespace MediaWiki\SpecialPage; |
| 11 | |
| 12 | use MediaWiki\Gallery\ImageGalleryBase; |
| 13 | use MediaWiki\Output\OutputPage; |
| 14 | use MediaWiki\Skin\Skin; |
| 15 | use MediaWiki\Title\Title; |
| 16 | use stdClass; |
| 17 | use Wikimedia\Rdbms\IReadableDatabase; |
| 18 | use Wikimedia\Rdbms\IResultWrapper; |
| 19 | |
| 20 | /** |
| 21 | * Variant of QueryPage which uses a gallery to output results, thus |
| 22 | * suited for reports generating images |
| 23 | * |
| 24 | * @stable to extend |
| 25 | * |
| 26 | * @ingroup SpecialPage |
| 27 | * @author Rob Church <robchur@gmail.com> |
| 28 | */ |
| 29 | abstract class ImageQueryPage extends QueryPage { |
| 30 | /** |
| 31 | * Format and output report results using the given information plus |
| 32 | * OutputPage |
| 33 | * |
| 34 | * @stable to override |
| 35 | * |
| 36 | * @param OutputPage $out OutputPage to print to |
| 37 | * @param Skin $skin User skin to use [unused] |
| 38 | * @param IReadableDatabase $dbr (read) connection to use |
| 39 | * @param IResultWrapper $res Result pointer |
| 40 | * @param int $num Number of available result rows |
| 41 | * @param int $offset Paging offset |
| 42 | */ |
| 43 | protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) { |
| 44 | if ( $num > 0 ) { |
| 45 | $gallery = ImageGalleryBase::factory( false, $this->getContext() ); |
| 46 | |
| 47 | // $res might contain the whole 1,000 rows, so we read up to |
| 48 | // $num [should update this to use a Pager] |
| 49 | $i = 0; |
| 50 | foreach ( $res as $row ) { |
| 51 | $i++; |
| 52 | $namespace = $row->namespace ?? NS_FILE; |
| 53 | $title = Title::makeTitleSafe( $namespace, $row->title ); |
| 54 | if ( $title instanceof Title && $title->inNamespace( NS_FILE ) ) { |
| 55 | $gallery->add( $title, $this->getCellHtml( $row ), '', '', [], ImageGalleryBase::LOADING_LAZY ); |
| 56 | } |
| 57 | if ( $i === $num ) { |
| 58 | break; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | $out->addHTML( $gallery->toHTML() ); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @stable to override |
| 68 | * |
| 69 | * @param Skin $skin |
| 70 | * @param stdClass $result |
| 71 | * |
| 72 | * @return bool|string |
| 73 | */ |
| 74 | protected function formatResult( $skin, $result ) { |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get additional HTML to be shown in a results' cell |
| 80 | * |
| 81 | * @stable to override |
| 82 | * |
| 83 | * @param stdClass $row Result row |
| 84 | * @return string |
| 85 | */ |
| 86 | protected function getCellHtml( $row ) { |
| 87 | return ''; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** @deprecated class alias since 1.41 */ |
| 92 | class_alias( ImageQueryPage::class, 'ImageQueryPage' ); |