SpecialUnusedimages.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. /**
  7. * implements Special:Unusedimages
  8. * @ingroup SpecialPage
  9. */
  10. class UnusedimagesPage extends ImageQueryPage {
  11. function isExpensive() { return true; }
  12. function getName() {
  13. return 'Unusedimages';
  14. }
  15. function sortDescending() {
  16. return false;
  17. }
  18. function isSyndicated() { return false; }
  19. function getSQL() {
  20. global $wgCountCategorizedImagesAsUsed, $wgDBtype;
  21. $dbr = wfGetDB( DB_SLAVE );
  22. $epoch = $wgDBtype == 'mysql' ?
  23. 'UNIX_TIMESTAMP(img_timestamp)' :
  24. 'EXTRACT(epoch FROM img_timestamp)';
  25. if ( $wgCountCategorizedImagesAsUsed ) {
  26. list( $page, $image, $imagelinks, $categorylinks ) = $dbr->tableNamesN( 'page', 'image', 'imagelinks', 'categorylinks' );
  27. return "SELECT 'Unusedimages' as type, 6 as namespace, img_name as title, $epoch as value,
  28. img_user, img_user_text, img_description
  29. FROM ((($page AS I LEFT JOIN $categorylinks AS L ON I.page_id = L.cl_from)
  30. LEFT JOIN $imagelinks AS P ON I.page_title = P.il_to)
  31. INNER JOIN $image AS G ON I.page_title = G.img_name)
  32. WHERE I.page_namespace = ".NS_FILE." AND L.cl_from IS NULL AND P.il_to IS NULL";
  33. } else {
  34. list( $image, $imagelinks ) = $dbr->tableNamesN( 'image','imagelinks' );
  35. return "SELECT 'Unusedimages' as type, 6 as namespace, img_name as title, $epoch as value,
  36. img_user, img_user_text, img_description
  37. FROM $image LEFT JOIN $imagelinks ON img_name=il_to WHERE il_to IS NULL ";
  38. }
  39. }
  40. function getPageHeader() {
  41. return wfMsgExt( 'unusedimagestext', array( 'parse' ) );
  42. }
  43. }
  44. /**
  45. * Entry point
  46. */
  47. function wfSpecialUnusedimages() {
  48. list( $limit, $offset ) = wfCheckLimits();
  49. $uip = new UnusedimagesPage();
  50. return $uip->doQuery( $offset, $limit );
  51. }