]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/ImageQueryPage.php
MediaWiki 1.16.0
[autoinstallsdev/mediawiki.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  * @ingroup SpecialPage
8  * @author Rob Church <robchur@gmail.com>
9  */
10 class ImageQueryPage extends QueryPage {
11
12         /**
13          * Format and output report results using the given information plus
14          * OutputPage
15          *
16          * @param $out OutputPage to print to
17          * @param $skin Skin: user skin to use
18          * @param $dbr Database (read) connection to use
19          * @param $res Integer: result pointer
20          * @param $num Integer: number of available result rows
21          * @param $offset Integer: paging offset
22          */
23         protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
24                 if( $num > 0 ) {
25                         $gallery = new ImageGallery();
26                         $gallery->useSkin( $skin );
27
28                         # $res might contain the whole 1,000 rows, so we read up to
29                         # $num [should update this to use a Pager]
30                         for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
31                                 $image = $this->prepareImage( $row );
32                                 if( $image ) {
33                                         $gallery->add( $image->getTitle(), $this->getCellHtml( $row ) );
34                                 }
35                         }
36
37                         $out->addHTML( $gallery->toHtml() );
38                 }
39         }
40
41         /**
42          * Prepare an image object given a result row
43          *
44          * @param $row Object: result row
45          * @return Image
46          */
47         private function prepareImage( $row ) {
48                 $namespace = isset( $row->namespace ) ? $row->namespace : NS_FILE;
49                 $title = Title::makeTitleSafe( $namespace, $row->title );
50                 return ( $title instanceof Title && $title->getNamespace() == NS_FILE )
51                         ? wfFindFile( $title )
52                         : null;
53         }
54
55         /**
56          * Get additional HTML to be shown in a results' cell
57          *
58          * @param $row Object: result row
59          * @return String
60          */
61         protected function getCellHtml( $row ) {
62                 return '';
63         }
64
65 }