SpecialLonelyPages.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Implements Special:Lonelypaages
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup SpecialPage
  22. */
  23. use MediaWiki\MediaWikiServices;
  24. /**
  25. * A special page looking for articles with no article linking to them,
  26. * thus being lonely.
  27. *
  28. * @ingroup SpecialPage
  29. */
  30. class SpecialLonelyPages extends PageQueryPage {
  31. function __construct( $name = 'Lonelypages' ) {
  32. parent::__construct( $name );
  33. }
  34. function getPageHeader() {
  35. return $this->msg( 'lonelypagestext' )->parseAsBlock();
  36. }
  37. function sortDescending() {
  38. return false;
  39. }
  40. function isExpensive() {
  41. return true;
  42. }
  43. function isSyndicated() {
  44. return false;
  45. }
  46. function getQueryInfo() {
  47. $tables = [ 'page', 'pagelinks', 'templatelinks' ];
  48. $conds = [
  49. 'pl_namespace IS NULL',
  50. 'page_namespace' => MediaWikiServices::getInstance()->getNamespaceInfo()->
  51. getContentNamespaces(),
  52. 'page_is_redirect' => 0,
  53. 'tl_namespace IS NULL'
  54. ];
  55. $joinConds = [
  56. 'pagelinks' => [
  57. 'LEFT JOIN', [
  58. 'pl_namespace = page_namespace',
  59. 'pl_title = page_title'
  60. ]
  61. ],
  62. 'templatelinks' => [
  63. 'LEFT JOIN', [
  64. 'tl_namespace = page_namespace',
  65. 'tl_title = page_title'
  66. ]
  67. ]
  68. ];
  69. // Allow extensions to modify the query
  70. Hooks::run( 'LonelyPagesQuery', [ &$tables, &$conds, &$joinConds ] );
  71. return [
  72. 'tables' => $tables,
  73. 'fields' => [
  74. 'namespace' => 'page_namespace',
  75. 'title' => 'page_title',
  76. ],
  77. 'conds' => $conds,
  78. 'join_conds' => $joinConds
  79. ];
  80. }
  81. function getOrderFields() {
  82. // For some crazy reason ordering by a constant
  83. // causes a filesort in MySQL 5
  84. if ( count( MediaWikiServices::getInstance()->getNamespaceInfo()->
  85. getContentNamespaces() ) > 1
  86. ) {
  87. return [ 'page_namespace', 'page_title' ];
  88. } else {
  89. return [ 'page_title' ];
  90. }
  91. }
  92. protected function getGroupName() {
  93. return 'maintenance';
  94. }
  95. }