SpecialUnusedTemplates.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Implements Special:Unusedtemplates
  4. *
  5. * Copyright © 2006 Rob Church
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. * http://www.gnu.org/copyleft/gpl.html
  21. *
  22. * @file
  23. * @ingroup SpecialPage
  24. * @author Rob Church <robchur@gmail.com>
  25. */
  26. /**
  27. * A special page that lists unused templates
  28. *
  29. * @ingroup SpecialPage
  30. */
  31. class SpecialUnusedTemplates extends QueryPage {
  32. function __construct( $name = 'Unusedtemplates' ) {
  33. parent::__construct( $name );
  34. }
  35. public function isExpensive() {
  36. return true;
  37. }
  38. function isSyndicated() {
  39. return false;
  40. }
  41. function sortDescending() {
  42. return false;
  43. }
  44. function getOrderFields() {
  45. return [ 'title' ];
  46. }
  47. public function getQueryInfo() {
  48. return [
  49. 'tables' => [ 'page', 'templatelinks' ],
  50. 'fields' => [
  51. 'namespace' => 'page_namespace',
  52. 'title' => 'page_title',
  53. ],
  54. 'conds' => [
  55. 'page_namespace' => NS_TEMPLATE,
  56. 'tl_from IS NULL',
  57. 'page_is_redirect' => 0
  58. ],
  59. 'join_conds' => [ 'templatelinks' => [
  60. 'LEFT JOIN', [ 'tl_title = page_title',
  61. 'tl_namespace = page_namespace' ] ] ]
  62. ];
  63. }
  64. /**
  65. * @param Skin $skin
  66. * @param object $result Result row
  67. * @return string
  68. */
  69. function formatResult( $skin, $result ) {
  70. $linkRenderer = $this->getLinkRenderer();
  71. $title = Title::makeTitle( NS_TEMPLATE, $result->title );
  72. $pageLink = $linkRenderer->makeKnownLink(
  73. $title,
  74. null,
  75. [],
  76. [ 'redirect' => 'no' ]
  77. );
  78. $wlhLink = $linkRenderer->makeKnownLink(
  79. SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ),
  80. $this->msg( 'unusedtemplateswlh' )->text()
  81. );
  82. return $this->getLanguage()->specialList( $pageLink, $wlhLink );
  83. }
  84. function getPageHeader() {
  85. return $this->msg( 'unusedtemplatestext' )->parseAsBlock();
  86. }
  87. protected function getGroupName() {
  88. return 'maintenance';
  89. }
  90. }