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