Remove ?>'s from files. They're pointless, and just asking for people to mess with...
[lhc/web/wiklou.git] / includes / ImageQueryPage.php
1 <?php
2
3 /**
4 * Variant of QueryPage which uses a gallery to output results, thus
5 * suited for reports generating images
6 *
7 * @package MediaWiki
8 * @addtogroup SpecialPage
9 * @author Rob Church <robchur@gmail.com>
10 */
11 class ImageQueryPage extends QueryPage {
12
13 /**
14 * Format and output report results using the given information plus
15 * OutputPage
16 *
17 * @param OutputPage $out OutputPage to print to
18 * @param Skin $skin User skin to use
19 * @param Database $dbr Database (read) connection to use
20 * @param int $res Result pointer
21 * @param int $num Number of available result rows
22 * @param int $offset Paging offset
23 */
24 protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
25 if( $num > 0 ) {
26 $gallery = new ImageGallery();
27 $gallery->useSkin( $skin );
28
29 # $res might contain the whole 1,000 rows, so we read up to
30 # $num [should update this to use a Pager]
31 for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
32 $image = $this->prepareImage( $row );
33 if( $image ) {
34 $gallery->add( $image->getTitle(), $this->getCellHtml( $row ) );
35 }
36 }
37
38 $out->addHtml( $gallery->toHtml() );
39 }
40 }
41
42 /**
43 * Prepare an image object given a result row
44 *
45 * @param object $row Result row
46 * @return Image
47 */
48 private function prepareImage( $row ) {
49 $namespace = isset( $row->namespace ) ? $row->namespace : NS_IMAGE;
50 $title = Title::makeTitleSafe( $namespace, $row->title );
51 return ( $title instanceof Title && $title->getNamespace() == NS_IMAGE )
52 ? wfFindFile( $title )
53 : null;
54 }
55
56 /**
57 * Get additional HTML to be shown in a results' cell
58 *
59 * @param object $row Result row
60 * @return string
61 */
62 protected function getCellHtml( $row ) {
63 return '';
64 }
65
66 }
67
68