SpecialMostlinkedcategories.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. /**
  7. * A querypage to show categories ordered in descending order by the pages in them
  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 MostlinkedCategoriesPage extends QueryPage {
  16. function getName() { return 'Mostlinkedcategories'; }
  17. function isExpensive() { return true; }
  18. function isSyndicated() { return false; }
  19. function getSQL() {
  20. $dbr = wfGetDB( DB_SLAVE );
  21. $categorylinks = $dbr->tableName( 'categorylinks' );
  22. $name = $dbr->addQuotes( $this->getName() );
  23. return
  24. "
  25. SELECT
  26. $name as type,
  27. " . NS_CATEGORY . " as namespace,
  28. cl_to as title,
  29. COUNT(*) as value
  30. FROM $categorylinks
  31. GROUP BY cl_to
  32. ";
  33. }
  34. function sortDescending() { return true; }
  35. /**
  36. * Fetch user page links and cache their existence
  37. */
  38. function preprocessResults( $db, $res ) {
  39. $batch = new LinkBatch;
  40. while ( $row = $db->fetchObject( $res ) )
  41. $batch->add( $row->namespace, $row->title );
  42. $batch->execute();
  43. // Back to start for display
  44. if ( $db->numRows( $res ) > 0 )
  45. // If there are no rows we get an error seeking.
  46. $db->dataSeek( $res, 0 );
  47. }
  48. function formatResult( $skin, $result ) {
  49. global $wgLang, $wgContLang;
  50. $nt = Title::makeTitle( $result->namespace, $result->title );
  51. $text = $wgContLang->convert( $nt->getText() );
  52. $plink = $skin->makeLinkObj( $nt, htmlspecialchars( $text ) );
  53. $nlinks = wfMsgExt( 'nmembers', array( 'parsemag', 'escape'),
  54. $wgLang->formatNum( $result->value ) );
  55. return wfSpecialList($plink, $nlinks);
  56. }
  57. }
  58. /**
  59. * constructor
  60. */
  61. function wfSpecialMostlinkedCategories() {
  62. list( $limit, $offset ) = wfCheckLimits();
  63. $wpp = new MostlinkedCategoriesPage();
  64. $wpp->doQuery( $offset, $limit );
  65. }