Remove unused $wgServer global.
[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 * @ingroup SpecialPage
8 * @author Rob Church <robchur@gmail.com>
9 */
10 class ImageQueryPage extends QueryPage {
11
12 var $mIsGallery = true;
13
14 /**
15 * Format and output report results using the given information plus
16 * OutputPage
17 *
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
24 */
25 protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
26 if( $num > 0 ) {
27 if ( $this->mIsGallery ) {
28 $gallery = new ImageGallery();
29 $gallery->useSkin( $skin );
30
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 );
35 if( $image ) {
36 $gallery->add( $image->getTitle(), $this->getCellHtml( $row ) );
37 }
38 }
39 $html = $gallery->toHtml();
40 }
41 else {
42 global $wgUser, $wgLang;
43 $sk = $wgUser->getSkin();
44 $html = "<ol>\n";
45 for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
46 $image = $this->prepareImage( $row );
47 if( $image ) {
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";
51 }
52 }
53 $html .= "</ol>\n";
54 }
55
56 $out->addHtml( $html );
57 }
58 }
59
60 /**
61 * Prepare an image object given a result row
62 *
63 * @param object $row Result row
64 * @return Image
65 */
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 )
71 : null;
72 }
73
74 /**
75 * Get additional HTML to be shown in a results' cell
76 *
77 * @param object $row Result row
78 * @return string
79 */
80 protected function getCellHtml( $row ) {
81 return '';
82 }
83
84 /**
85 * Is this to be output as a gallery?
86 */
87 public function setGallery( $val ) {
88 $this->mIsGallery = $val;
89 }
90 }