SpecialWantedfiles.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * Implements Special:Wantedfiles
  4. *
  5. * Copyright © 2008 Soxred93
  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 Soxred93 <soxred93@gmail.com>
  25. */
  26. use MediaWiki\MediaWikiServices;
  27. /**
  28. * Querypage that lists the most wanted files
  29. *
  30. * @ingroup SpecialPage
  31. */
  32. class WantedFilesPage extends WantedQueryPage {
  33. function __construct( $name = 'Wantedfiles' ) {
  34. parent::__construct( $name );
  35. }
  36. function getPageHeader() {
  37. # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
  38. # category would be used on main namespace pages, for those tricky wikipedia
  39. # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
  40. $catMessage = $this->msg( 'broken-file-category' )
  41. ->title( Title::newFromText( "Wanted Files", NS_MAIN ) )
  42. ->inContentLanguage();
  43. if ( !$catMessage->isDisabled() ) {
  44. $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
  45. } else {
  46. $category = false;
  47. }
  48. $noForeign = '';
  49. if ( !$this->likelyToHaveFalsePositives() ) {
  50. // Additional messages for grep:
  51. // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
  52. $noForeign = '-noforeign';
  53. }
  54. if ( $category ) {
  55. return $this
  56. ->msg( 'wantedfiletext-cat' . $noForeign )
  57. ->params( $category->getFullText() )
  58. ->parseAsBlock();
  59. } else {
  60. return $this
  61. ->msg( 'wantedfiletext-nocat' . $noForeign )
  62. ->parseAsBlock();
  63. }
  64. }
  65. /**
  66. * Whether foreign repos are likely to cause false positives
  67. *
  68. * In its own function to allow subclasses to override.
  69. * @see SpecialWantedFilesGUOverride in GlobalUsage extension.
  70. * @since 1.24
  71. * @return bool
  72. */
  73. protected function likelyToHaveFalsePositives() {
  74. return RepoGroup::singleton()->hasForeignRepos();
  75. }
  76. /**
  77. * KLUGE: The results may contain false positives for files
  78. * that exist e.g. in a shared repo. Setting this at least
  79. * keeps them from showing up as redlinks in the output, even
  80. * if it doesn't fix the real problem (T8220).
  81. *
  82. * @note could also have existing links here from broken file
  83. * redirects.
  84. * @return bool
  85. */
  86. function forceExistenceCheck() {
  87. return true;
  88. }
  89. /**
  90. * Does the file exist?
  91. *
  92. * Use findFile() so we still think file namespace pages without files
  93. * are missing, but valid file redirects and foreign files are ok.
  94. *
  95. * @param Title $title
  96. * @return bool
  97. */
  98. protected function existenceCheck( Title $title ) {
  99. return (bool)MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title );
  100. }
  101. function getQueryInfo() {
  102. return [
  103. 'tables' => [
  104. 'imagelinks',
  105. 'page',
  106. 'redirect',
  107. 'img1' => 'image',
  108. 'img2' => 'image',
  109. ],
  110. 'fields' => [
  111. 'namespace' => NS_FILE,
  112. 'title' => 'il_to',
  113. 'value' => 'COUNT(*)'
  114. ],
  115. 'conds' => [
  116. 'img1.img_name' => null,
  117. // We also need to exclude file redirects
  118. 'img2.img_name' => null,
  119. ],
  120. 'options' => [ 'GROUP BY' => 'il_to' ],
  121. 'join_conds' => [
  122. 'img1' => [ 'LEFT JOIN',
  123. 'il_to = img1.img_name'
  124. ],
  125. 'page' => [ 'LEFT JOIN', [
  126. 'il_to = page_title',
  127. 'page_namespace' => NS_FILE,
  128. ] ],
  129. 'redirect' => [ 'LEFT JOIN', [
  130. 'page_id = rd_from',
  131. 'rd_namespace' => NS_FILE,
  132. 'rd_interwiki' => ''
  133. ] ],
  134. 'img2' => [ 'LEFT JOIN',
  135. 'rd_title = img2.img_name'
  136. ]
  137. ]
  138. ];
  139. }
  140. protected function getGroupName() {
  141. return 'maintenance';
  142. }
  143. }