ImageQueryPage.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Variant of QueryPage which uses a gallery to output results.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup SpecialPage
  22. */
  23. use Wikimedia\Rdbms\IResultWrapper;
  24. use Wikimedia\Rdbms\IDatabase;
  25. /**
  26. * Variant of QueryPage which uses a gallery to output results, thus
  27. * suited for reports generating images
  28. *
  29. * @ingroup SpecialPage
  30. * @author Rob Church <robchur@gmail.com>
  31. */
  32. abstract class ImageQueryPage extends QueryPage {
  33. /**
  34. * Format and output report results using the given information plus
  35. * OutputPage
  36. *
  37. * @param OutputPage $out OutputPage to print to
  38. * @param Skin $skin User skin to use [unused]
  39. * @param IDatabase $dbr (read) connection to use
  40. * @param IResultWrapper $res Result pointer
  41. * @param int $num Number of available result rows
  42. * @param int $offset Paging offset
  43. */
  44. protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
  45. if ( $num > 0 ) {
  46. $gallery = ImageGalleryBase::factory( false, $this->getContext() );
  47. # $res might contain the whole 1,000 rows, so we read up to
  48. # $num [should update this to use a Pager]
  49. $i = 0;
  50. foreach ( $res as $row ) {
  51. $i++;
  52. $namespace = isset( $row->namespace ) ? $row->namespace : NS_FILE;
  53. $title = Title::makeTitleSafe( $namespace, $row->title );
  54. if ( $title instanceof Title && $title->getNamespace() == NS_FILE ) {
  55. $gallery->add( $title, $this->getCellHtml( $row ) );
  56. }
  57. if ( $i === $num ) {
  58. break;
  59. }
  60. }
  61. $out->addHTML( $gallery->toHTML() );
  62. }
  63. }
  64. // Gotta override this since it's abstract
  65. function formatResult( $skin, $result ) {
  66. }
  67. /**
  68. * Get additional HTML to be shown in a results' cell
  69. *
  70. * @param object $row Result row
  71. * @return string
  72. */
  73. protected function getCellHtml( $row ) {
  74. return '';
  75. }
  76. }