SpecialUnusedImages.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Implements Special:Unusedimages
  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. /**
  24. * A special page that lists unused images
  25. *
  26. * @ingroup SpecialPage
  27. */
  28. class SpecialUnusedImages extends ImageQueryPage {
  29. function __construct( $name = 'Unusedimages' ) {
  30. parent::__construct( $name );
  31. }
  32. function isExpensive() {
  33. return true;
  34. }
  35. function sortDescending() {
  36. return false;
  37. }
  38. function isSyndicated() {
  39. return false;
  40. }
  41. function getQueryInfo() {
  42. $retval = [
  43. 'tables' => [ 'image', 'imagelinks' ],
  44. 'fields' => [
  45. 'namespace' => NS_FILE,
  46. 'title' => 'img_name',
  47. 'value' => 'img_timestamp',
  48. ],
  49. 'conds' => [ 'il_to IS NULL' ],
  50. 'join_conds' => [ 'imagelinks' => [ 'LEFT JOIN', 'il_to = img_name' ] ]
  51. ];
  52. if ( $this->getConfig()->get( 'CountCategorizedImagesAsUsed' ) ) {
  53. // Order is significant
  54. $retval['tables'] = [ 'image', 'page', 'categorylinks',
  55. 'imagelinks' ];
  56. $retval['conds']['page_namespace'] = NS_FILE;
  57. $retval['conds'][] = 'cl_from IS NULL';
  58. $retval['conds'][] = 'img_name = page_title';
  59. $retval['join_conds']['categorylinks'] = [
  60. 'LEFT JOIN', 'cl_from = page_id' ];
  61. $retval['join_conds']['imagelinks'] = [
  62. 'LEFT JOIN', 'il_to = page_title' ];
  63. }
  64. return $retval;
  65. }
  66. function usesTimestamps() {
  67. return true;
  68. }
  69. function getPageHeader() {
  70. if ( $this->getConfig()->get( 'CountCategorizedImagesAsUsed' ) ) {
  71. return $this->msg(
  72. 'unusedimagestext-categorizedimgisused'
  73. )->parseAsBlock();
  74. }
  75. return $this->msg( 'unusedimagestext' )->parseAsBlock();
  76. }
  77. protected function getGroupName() {
  78. return 'maintenance';
  79. }
  80. }