SpecialShortpages.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. /**
  7. * SpecialShortpages extends QueryPage. It is used to return the shortest
  8. * pages in the database.
  9. * @ingroup SpecialPage
  10. */
  11. class ShortPagesPage extends QueryPage {
  12. function getName() {
  13. return 'Shortpages';
  14. }
  15. /**
  16. * This query is indexed as of 1.5
  17. */
  18. function isExpensive() {
  19. return true;
  20. }
  21. function isSyndicated() {
  22. return false;
  23. }
  24. function getSQL() {
  25. global $wgContentNamespaces;
  26. $dbr = wfGetDB( DB_SLAVE );
  27. $page = $dbr->tableName( 'page' );
  28. $name = $dbr->addQuotes( $this->getName() );
  29. $forceindex = $dbr->useIndexClause("page_len");
  30. if ($wgContentNamespaces)
  31. $nsclause = "page_namespace IN (" . $dbr->makeList($wgContentNamespaces) . ")";
  32. else
  33. $nsclause = "page_namespace = " . NS_MAIN;
  34. return
  35. "SELECT $name as type,
  36. page_namespace as namespace,
  37. page_title as title,
  38. page_len AS value
  39. FROM $page $forceindex
  40. WHERE $nsclause AND page_is_redirect=0";
  41. }
  42. function preprocessResults( $db, $res ) {
  43. # There's no point doing a batch check if we aren't caching results;
  44. # the page must exist for it to have been pulled out of the table
  45. if( $this->isCached() ) {
  46. $batch = new LinkBatch();
  47. while( $row = $db->fetchObject( $res ) )
  48. $batch->add( $row->namespace, $row->title );
  49. $batch->execute();
  50. if( $db->numRows( $res ) > 0 )
  51. $db->dataSeek( $res, 0 );
  52. }
  53. }
  54. function sortDescending() {
  55. return false;
  56. }
  57. function formatResult( $skin, $result ) {
  58. global $wgLang, $wgContLang;
  59. $dm = $wgContLang->getDirMark();
  60. $title = Title::makeTitleSafe( $result->namespace, $result->title );
  61. if ( !$title ) {
  62. return '<!-- Invalid title ' . htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
  63. }
  64. $hlink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
  65. $plink = $this->isCached()
  66. ? $skin->makeLinkObj( $title )
  67. : $skin->makeKnownLinkObj( $title );
  68. $size = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->value ) ) );
  69. return $title->exists()
  70. ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
  71. : "<s>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</s>";
  72. }
  73. }
  74. /**
  75. * constructor
  76. */
  77. function wfSpecialShortpages() {
  78. list( $limit, $offset ) = wfCheckLimits();
  79. $spp = new ShortPagesPage();
  80. return $spp->doQuery( $offset, $limit );
  81. }