SpecialWantedcategories.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. /**
  7. * A querypage to list the most wanted categories - implements Special:Wantedcategories
  8. *
  9. * @ingroup SpecialPage
  10. *
  11. * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
  12. * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
  13. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  14. */
  15. class WantedCategoriesPage extends QueryPage {
  16. function getName() {
  17. return 'Wantedcategories';
  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( $categorylinks, $page ) = $dbr->tableNamesN( 'categorylinks', 'page' );
  28. $name = $dbr->addQuotes( $this->getName() );
  29. return
  30. "
  31. SELECT
  32. $name as type,
  33. " . NS_CATEGORY . " as namespace,
  34. cl_to as title,
  35. COUNT(*) as value
  36. FROM $categorylinks
  37. LEFT JOIN $page ON cl_to = page_title AND page_namespace = ". NS_CATEGORY ."
  38. WHERE page_title IS NULL
  39. GROUP BY cl_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. $nlinks = wfMsgExt( 'nmembers', array( 'parsemag', 'escape'),
  64. $wgLang->formatNum( $result->value ) );
  65. return wfSpecialList($plink, $nlinks);
  66. }
  67. }
  68. /**
  69. * constructor
  70. */
  71. function wfSpecialWantedCategories() {
  72. list( $limit, $offset ) = wfCheckLimits();
  73. $wpp = new WantedCategoriesPage();
  74. $wpp->doQuery( $offset, $limit );
  75. }