4 * Variant of QueryPage which uses a gallery to output results, thus
5 * suited for reports generating images
8 * @author Rob Church <robchur@gmail.com>
10 class ImageQueryPage
extends QueryPage
{
12 var $mIsGallery = true;
15 * Format and output report results using the given information plus
18 * @param OutputPage $out OutputPage to print to
19 * @param Skin $skin User skin to use
20 * @param Database $dbr Database (read) connection to use
21 * @param int $res Result pointer
22 * @param int $num Number of available result rows
23 * @param int $offset Paging offset
25 protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
27 if ( $this->mIsGallery
) {
28 $gallery = new ImageGallery();
29 $gallery->useSkin( $skin );
31 # $res might contain the whole 1,000 rows, so we read up to
32 # $num [should update this to use a Pager]
33 for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++
) {
34 $image = $this->prepareImage( $row );
36 $gallery->add( $image->getTitle(), $this->getCellHtml( $row ) );
39 $html = $gallery->toHtml();
42 global $wgUser, $wgLang;
43 $sk = $wgUser->getSkin();
45 for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++
) {
46 $image = $this->prepareImage( $row );
48 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'), $wgLang->formatNum( $image->getSize() ) );
49 $html .= "<li>" . $sk->makeKnownLinkObj( $image->getTitle(), $image->getTitle()->getText() ) .
50 " (" . $bytes . ")</li>\n";
56 $out->addHtml( $html );
61 * Prepare an image object given a result row
63 * @param object $row Result row
66 private function prepareImage( $row ) {
67 $namespace = isset( $row->namespace ) ?
$row->namespace : NS_IMAGE
;
68 $title = Title
::makeTitleSafe( $namespace, $row->title
);
69 return ( $title instanceof Title
&& $title->getNamespace() == NS_IMAGE
)
70 ?
wfFindFile( $title )
75 * Get additional HTML to be shown in a results' cell
77 * @param object $row Result row
80 protected function getCellHtml( $row ) {
85 * Is this to be output as a gallery?
87 public function setGallery( $val ) {
88 $this->mIsGallery
= $val;