SpecialWantedfiles.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /*
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. /**
  7. * Querypage that lists the most wanted files - implements Special:Wantedfiles
  8. *
  9. * @ingroup SpecialPage
  10. *
  11. * @author Soxred93 <soxred93@gmail.com>
  12. * @copyright Copyright © 2008, Soxred93
  13. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  14. */
  15. class WantedFilesPage extends QueryPage {
  16. function getName() {
  17. return 'Wantedfiles';
  18. }
  19. function isExpensive() {
  20. return true;
  21. }
  22. function isSyndicated() {
  23. return false;
  24. }
  25. function getSQL() {
  26. $dbr = wfGetDB( DB_SLAVE );
  27. list( $imagelinks, $page ) = $dbr->tableNamesN( 'imagelinks', 'page' );
  28. $name = $dbr->addQuotes( $this->getName() );
  29. return
  30. "
  31. SELECT
  32. $name as type,
  33. " . NS_FILE . " as namespace,
  34. il_to as title,
  35. COUNT(*) as value
  36. FROM $imagelinks
  37. LEFT JOIN $page ON il_to = page_title AND page_namespace = ". NS_FILE ."
  38. WHERE page_title IS NULL
  39. GROUP BY il_to
  40. ";
  41. }
  42. function sortDescending() { return true; }
  43. /**
  44. * Fetch user page links and cache their existence
  45. */
  46. function preprocessResults( $db, $res ) {
  47. $batch = new LinkBatch;
  48. while ( $row = $db->fetchObject( $res ) )
  49. $batch->add( $row->namespace, $row->title );
  50. $batch->execute();
  51. // Back to start for display
  52. if ( $db->numRows( $res ) > 0 )
  53. // If there are no rows we get an error seeking.
  54. $db->dataSeek( $res, 0 );
  55. }
  56. function formatResult( $skin, $result ) {
  57. global $wgLang, $wgContLang;
  58. $nt = Title::makeTitle( $result->namespace, $result->title );
  59. $text = $wgContLang->convert( $nt->getText() );
  60. $plink = $this->isCached() ?
  61. $skin->makeLinkObj( $nt, htmlspecialchars( $text ) ) :
  62. $skin->makeBrokenLinkObj( $nt, htmlspecialchars( $text ) );
  63. return wfSpecialList(
  64. $plink,
  65. $this->makeWlhLink( $nt, $skin, $result )
  66. );
  67. }
  68. /**
  69. * Make a "what links here" link for a given title
  70. *
  71. * @param Title $title Title to make the link for
  72. * @param Skin $skin Skin to use
  73. * @param object $result Result row
  74. * @return string
  75. */
  76. private function makeWlhLink( $title, $skin, $result ) {
  77. global $wgLang;
  78. $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
  79. $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
  80. $wgLang->formatNum( $result->value ) );
  81. return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
  82. }
  83. }
  84. /**
  85. * constructor
  86. */
  87. function wfSpecialWantedFiles() {
  88. list( $limit, $offset ) = wfCheckLimits();
  89. $wpp = new WantedFilesPage();
  90. $wpp->doQuery( $offset, $limit );
  91. }