SpecialPopularpages.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. /**
  7. * implements Special:Popularpages
  8. * @ingroup SpecialPage
  9. */
  10. class PopularPagesPage extends QueryPage {
  11. function getName() {
  12. return "Popularpages";
  13. }
  14. function isExpensive() {
  15. # page_counter is not indexed
  16. return true;
  17. }
  18. function isSyndicated() { return false; }
  19. function getSQL() {
  20. $dbr = wfGetDB( DB_SLAVE );
  21. $page = $dbr->tableName( 'page' );
  22. $query =
  23. "SELECT 'Popularpages' as type,
  24. page_namespace as namespace,
  25. page_title as title,
  26. page_counter as value
  27. FROM $page ";
  28. $where =
  29. "WHERE page_is_redirect=0 AND page_namespace";
  30. global $wgContentNamespaces;
  31. if( empty( $wgContentNamespaces ) ) {
  32. $where .= '='.NS_MAIN;
  33. } else if( count( $wgContentNamespaces ) > 1 ) {
  34. $where .= ' in (' . implode( ', ', $wgContentNamespaces ) . ')';
  35. } else {
  36. $where .= '='.$wgContentNamespaces[0];
  37. }
  38. return $query . $where;
  39. }
  40. function formatResult( $skin, $result ) {
  41. global $wgLang, $wgContLang;
  42. $title = Title::makeTitle( $result->namespace, $result->title );
  43. $link = $skin->makeKnownLinkObj( $title, htmlspecialchars( $wgContLang->convert( $title->getPrefixedText() ) ) );
  44. $nv = wfMsgExt( 'nviews', array( 'parsemag', 'escape'),
  45. $wgLang->formatNum( $result->value ) );
  46. return wfSpecialList($link, $nv);
  47. }
  48. }
  49. /**
  50. * Constructor
  51. */
  52. function wfSpecialPopularpages() {
  53. list( $limit, $offset ) = wfCheckLimits();
  54. $ppp = new PopularPagesPage();
  55. return $ppp->doQuery( $offset, $limit );
  56. }