Debian Codegraph @

includes/specials/SpecialWantedFiles.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright © 2008 Soxred93
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 */
22
23 namespace MediaWiki\Specials;
24
25 use MediaWiki\Cache\LinkBatchFactory;
26 use MediaWiki\Page\PageReferenceValue;
27 use MediaWiki\SpecialPage\WantedQueryPage;
28 use MediaWiki\Title\Title;
29 use RepoGroup;
30 use Wikimedia\Rdbms\IConnectionProvider;
31
32 /**
33 * List of the most linked non-existent files.
34 *
35 * @ingroup SpecialPage
36 * @author Soxred93 <[email protected]>
37 */
38 class SpecialWantedFiles extends WantedQueryPage {
39
40 private RepoGroup $repoGroup;
41
42 /**
43 * @param RepoGroup $repoGroup
44 * @param IConnectionProvider $dbProvider
45 * @param LinkBatchFactory $linkBatchFactory
46 */
47 public function __construct(
48 RepoGroup $repoGroup,
49 IConnectionProvider $dbProvider,
50 LinkBatchFactory $linkBatchFactory
51 ) {
52 parent::__construct( 'Wantedfiles' );
53 $this->repoGroup = $repoGroup;
54 $this->setDatabaseProvider( $dbProvider );
55 $this->setLinkBatchFactory( $linkBatchFactory );
56 }
57
58 protected function getPageHeader() {
59 # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
60 # category would be used on main namespace pages, for those tricky wikipedia
61 # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
62 $catMessage = $this->msg( 'broken-file-category' )
63 ->page( PageReferenceValue::localReference( NS_MAIN, "Wanted Files" ) )
64 ->inContentLanguage();
65
66 if ( !$catMessage->isDisabled() ) {
67 $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
68 } else {
69 $category = false;
70 }
71
72 $noForeign = '';
73 if ( !$this->likelyToHaveFalsePositives() ) {
74 // Additional messages for grep:
75 // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
76 $noForeign = '-noforeign';
77 }
78
79 if ( $category ) {
80 return $this
81 ->msg( 'wantedfiletext-cat' . $noForeign )
82 ->params( $category->getFullText() )
83 ->parseAsBlock();
84 } else {
85 return $this
86 ->msg( 'wantedfiletext-nocat' . $noForeign )
87 ->parseAsBlock();
88 }
89 }
90
91 /**
92 * Whether foreign repos are likely to cause false positives
93 *
94 * In its own function to allow subclasses to override.
95 * @see SpecialWantedFilesGUOverride in GlobalUsage extension.
96 * @since 1.24
97 * @return bool
98 */
99 protected function likelyToHaveFalsePositives() {
100 return $this->repoGroup->hasForeignRepos();
101 }
102
103 /**
104 * KLUGE: The results may contain false positives for files
105 * that exist e.g. in a shared repo. Setting this at least
106 * keeps them from showing up as redlinks in the output, even
107 * if it doesn't fix the real problem (T8220).
108 *
109 * @note could also have existing links here from broken file
110 * redirects.
111 * @return bool
112 */
113 protected function forceExistenceCheck() {
114 return true;
115 }
116
117 /**
118 * Does the file exist?
119 *
120 * Use findFile() so we still think file namespace pages without files
121 * are missing, but valid file redirects and foreign files are ok.
122 *
123 * @param Title $title
124 * @return bool
125 */
126 protected function existenceCheck( Title $title ) {
127 return (bool)$this->repoGroup->findFile( $title );
128 }
129
130 public function getQueryInfo() {
131 return [
132 'tables' => [
133 'imagelinks',
134 'page',
135 'redirect',
136 'img1' => 'image',
137 'img2' => 'image',
138 ],
139 'fields' => [
140 'namespace' => NS_FILE,
141 'title' => 'il_to',
142 'value' => 'COUNT(*)'
143 ],
144 'conds' => [
145 'img1.img_name' => null,
146 // We also need to exclude file redirects
147 'img2.img_name' => null,
148 ],
149 'options' => [ 'GROUP BY' => 'il_to' ],
150 'join_conds' => [
151 'img1' => [ 'LEFT JOIN',
152 'il_to = img1.img_name'
153 ],
154 'page' => [ 'LEFT JOIN', [
155 'il_to = page_title',
156 'page_namespace' => NS_FILE,
157 ] ],
158 'redirect' => [ 'LEFT JOIN', [
159 'page_id = rd_from',
160 'rd_namespace' => NS_FILE,
161 'rd_interwiki' => ''
162 ] ],
163 'img2' => [ 'LEFT JOIN',
164 'rd_title = img2.img_name'
165 ]
166 ]
167 ];
168 }
169
170 protected function getGroupName() {
171 return 'maintenance';
172 }
173 }
174
175 /**
176 * Retain the old class name for backwards compatibility.
177 * @deprecated since 1.40
178 */
179 class_alias( SpecialWantedFiles::class, 'WantedFilesPage' );