ImageQueryPage.php 1.7 KB

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