Sync up core repo with Parsoid
[mediawiki.git] / includes / specialpage / ImageQueryPage.php
blobab06779cb8e41d77ba063058b8079d7f275a31b1
1 <?php
2 /**
3 * Variant of QueryPage which uses a gallery to output results.
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.
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.
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
20 * @file
21 * @ingroup SpecialPage
24 use MediaWiki\Title\Title;
25 use Wikimedia\Rdbms\IDatabase;
26 use Wikimedia\Rdbms\IResultWrapper;
28 /**
29 * Variant of QueryPage which uses a gallery to output results, thus
30 * suited for reports generating images
32 * @stable to extend
34 * @ingroup SpecialPage
35 * @author Rob Church <robchur@gmail.com>
37 abstract class ImageQueryPage extends QueryPage {
38 /**
39 * Format and output report results using the given information plus
40 * OutputPage
42 * @stable to override
44 * @param OutputPage $out OutputPage to print to
45 * @param Skin $skin User skin to use [unused]
46 * @param IDatabase $dbr (read) connection to use
47 * @param IResultWrapper $res Result pointer
48 * @param int $num Number of available result rows
49 * @param int $offset Paging offset
51 protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
52 if ( $num > 0 ) {
53 $gallery = ImageGalleryBase::factory( false, $this->getContext() );
55 // $res might contain the whole 1,000 rows, so we read up to
56 // $num [should update this to use a Pager]
57 $i = 0;
58 foreach ( $res as $row ) {
59 $i++;
60 $namespace = $row->namespace ?? NS_FILE;
61 $title = Title::makeTitleSafe( $namespace, $row->title );
62 if ( $title instanceof Title && $title->getNamespace() === NS_FILE ) {
63 $gallery->add( $title, $this->getCellHtml( $row ), '', '', [], ImageGalleryBase::LOADING_LAZY );
65 if ( $i === $num ) {
66 break;
70 $out->addHTML( $gallery->toHTML() );
74 /**
75 * @stable to override
77 * @param Skin $skin
78 * @param stdClass $result
80 * @return bool|string
82 protected function formatResult( $skin, $result ) {
83 return false;
86 /**
87 * Get additional HTML to be shown in a results' cell
89 * @stable to override
91 * @param stdClass $row Result row
92 * @return string
94 protected function getCellHtml( $row ) {
95 return '';