Debian Codegraph @

includes/specials/SpecialListFiles.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Specials;
22
23 use MediaWiki\Cache\LinkBatchFactory;
24 use MediaWiki\CommentFormatter\CommentFormatter;
25 use MediaWiki\CommentStore\CommentStore;
26 use MediaWiki\Pager\ImageListPager;
27 use MediaWiki\SpecialPage\IncludableSpecialPage;
28 use MediaWiki\User\UserNamePrefixSearch;
29 use MediaWiki\User\UserNameUtils;
30 use MediaWiki\User\UserRigorOptions;
31 use RepoGroup;
32 use Wikimedia\Rdbms\IConnectionProvider;
33
34 /**
35 * Implements Special:Listfiles
36 *
37 * @ingroup SpecialPage
38 */
39 class SpecialListFiles extends IncludableSpecialPage {
40
41 private RepoGroup $repoGroup;
42 private IConnectionProvider $dbProvider;
43 private CommentStore $commentStore;
44 private UserNameUtils $userNameUtils;
45 private UserNamePrefixSearch $userNamePrefixSearch;
46 private CommentFormatter $commentFormatter;
47 private LinkBatchFactory $linkBatchFactory;
48
49 /**
50 * @param RepoGroup $repoGroup
51 * @param IConnectionProvider $dbProvider
52 * @param CommentStore $commentStore
53 * @param UserNameUtils $userNameUtils
54 * @param UserNamePrefixSearch $userNamePrefixSearch
55 * @param CommentFormatter $commentFormatter
56 * @param LinkBatchFactory $linkBatchFactory
57 */
58 public function __construct(
59 RepoGroup $repoGroup,
60 IConnectionProvider $dbProvider,
61 CommentStore $commentStore,
62 UserNameUtils $userNameUtils,
63 UserNamePrefixSearch $userNamePrefixSearch,
64 CommentFormatter $commentFormatter,
65 LinkBatchFactory $linkBatchFactory
66 ) {
67 parent::__construct( 'Listfiles' );
68 $this->repoGroup = $repoGroup;
69 $this->dbProvider = $dbProvider;
70 $this->commentStore = $commentStore;
71 $this->userNameUtils = $userNameUtils;
72 $this->userNamePrefixSearch = $userNamePrefixSearch;
73 $this->commentFormatter = $commentFormatter;
74 $this->linkBatchFactory = $linkBatchFactory;
75 }
76
77 public function execute( $par ) {
78 $this->setHeaders();
79 $this->outputHeader();
80 $this->addHelpLink( 'Help:Managing_files' );
81
82 if ( $this->including() ) {
83 $userName = (string)$par;
84 $search = '';
85 $showAll = false;
86 } else {
87 $userName = $this->getRequest()->getText( 'user', $par ?? '' );
88 $search = $this->getRequest()->getText( 'ilsearch', '' );
89 $showAll = $this->getRequest()->getBool( 'ilshowall', false );
90 }
91 // Sanitize usernames to avoid symbols in the title of page.
92 $sanitizedUserName = $this->userNameUtils->getCanonical( $userName, UserRigorOptions::RIGOR_NONE );
93 if ( $sanitizedUserName !== false ) {
94 $userName = $sanitizedUserName;
95 }
96
97 if ( $userName !== '' ) {
98 $pageTitle = $this->msg( 'listfiles_subpage' )->plaintextParams( $userName );
99 } else {
100 $pageTitle = $this->msg( 'listfiles' );
101 }
102
103 $pager = new ImageListPager(
104 $this->getContext(),
105 $this->commentStore,
106 $this->getLinkRenderer(),
107 $this->dbProvider,
108 $this->repoGroup,
109 $this->userNameUtils,
110 $this->commentFormatter,
111 $this->linkBatchFactory,
112 $userName,
113 $search,
114 $this->including(),
115 $showAll
116 );
117
118 $out = $this->getOutput();
119 $out->setPageTitleMsg( $pageTitle );
120 $out->addModuleStyles( 'mediawiki.special' );
121 if ( $this->including() ) {
122 $out->addParserOutputContent( $pager->getBodyOutput() );
123 } else {
124 $user = $pager->getRelevantUser();
125 if ( $user ) {
126 $this->getSkin()->setRelevantUser( $user );
127 }
128 $pager->getForm();
129 $out->addParserOutputContent( $pager->getFullOutput() );
130 }
131 }
132
133 /**
134 * Return an array of subpages beginning with $search that this special page will accept.
135 *
136 * @param string $search Prefix to search for
137 * @param int $limit Maximum number of results to return (usually 10)
138 * @param int $offset Number of results to skip (usually 0)
139 * @return string[] Matching subpages
140 */
141 public function prefixSearchSubpages( $search, $limit, $offset ) {
142 $search = $this->userNameUtils->getCanonical( $search );
143 if ( !$search ) {
144 // No prefix suggestion for invalid user
145 return [];
146 }
147 // Autocomplete subpage as user list - public to allow caching
148 return $this->userNamePrefixSearch
149 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
150 }
151
152 protected function getGroupName() {
153 return 'media';
154 }
155 }
156
157 /** @deprecated class alias since 1.41 */
158 class_alias( SpecialListFiles::class, 'SpecialListFiles' );