SpecialWantedtemplates.php 2.8 KB

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