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