Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 55 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
SpecialListFiles | |
0.00% |
0 / 54 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 40 |
|
0.00% |
0 / 1 |
42 | |||
prefixSearchSubpages | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Implements Special:Listfiles |
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 | |
24 | namespace MediaWiki\Specials; |
25 | |
26 | use MediaWiki\Cache\UserCache; |
27 | use MediaWiki\CommentFormatter\CommentFormatter; |
28 | use MediaWiki\CommentStore\CommentStore; |
29 | use MediaWiki\Pager\ImageListPager; |
30 | use MediaWiki\SpecialPage\IncludableSpecialPage; |
31 | use MediaWiki\User\UserNamePrefixSearch; |
32 | use MediaWiki\User\UserNameUtils; |
33 | use MediaWiki\User\UserRigorOptions; |
34 | use RepoGroup; |
35 | use Wikimedia\Rdbms\IConnectionProvider; |
36 | |
37 | class SpecialListFiles extends IncludableSpecialPage { |
38 | |
39 | private RepoGroup $repoGroup; |
40 | private IConnectionProvider $dbProvider; |
41 | private CommentStore $commentStore; |
42 | private UserNameUtils $userNameUtils; |
43 | private UserNamePrefixSearch $userNamePrefixSearch; |
44 | private UserCache $userCache; |
45 | private CommentFormatter $commentFormatter; |
46 | |
47 | /** |
48 | * @param RepoGroup $repoGroup |
49 | * @param IConnectionProvider $dbProvider |
50 | * @param CommentStore $commentStore |
51 | * @param UserNameUtils $userNameUtils |
52 | * @param UserNamePrefixSearch $userNamePrefixSearch |
53 | * @param UserCache $userCache |
54 | * @param CommentFormatter $commentFormatter |
55 | */ |
56 | public function __construct( |
57 | RepoGroup $repoGroup, |
58 | IConnectionProvider $dbProvider, |
59 | CommentStore $commentStore, |
60 | UserNameUtils $userNameUtils, |
61 | UserNamePrefixSearch $userNamePrefixSearch, |
62 | UserCache $userCache, |
63 | CommentFormatter $commentFormatter |
64 | ) { |
65 | parent::__construct( 'Listfiles' ); |
66 | $this->repoGroup = $repoGroup; |
67 | $this->dbProvider = $dbProvider; |
68 | $this->commentStore = $commentStore; |
69 | $this->userNameUtils = $userNameUtils; |
70 | $this->userNamePrefixSearch = $userNamePrefixSearch; |
71 | $this->userCache = $userCache; |
72 | $this->commentFormatter = $commentFormatter; |
73 | } |
74 | |
75 | public function execute( $par ) { |
76 | $this->setHeaders(); |
77 | $this->outputHeader(); |
78 | $this->addHelpLink( 'Help:Managing_files' ); |
79 | |
80 | if ( $this->including() ) { |
81 | $userName = (string)$par; |
82 | $search = ''; |
83 | $showAll = false; |
84 | } else { |
85 | $userName = $this->getRequest()->getText( 'user', $par ?? '' ); |
86 | $search = $this->getRequest()->getText( 'ilsearch', '' ); |
87 | $showAll = $this->getRequest()->getBool( 'ilshowall', false ); |
88 | } |
89 | // Sanitize usernames to avoid symbols in the title of page. |
90 | $sanitizedUserName = $this->userNameUtils->getCanonical( $userName, UserRigorOptions::RIGOR_NONE ); |
91 | if ( $sanitizedUserName ) { |
92 | $userName = $sanitizedUserName; |
93 | } |
94 | |
95 | if ( $userName ) { |
96 | $pageTitle = $this->msg( 'listfiles_subpage' )->plaintextParams( $userName ); |
97 | } else { |
98 | $pageTitle = $this->msg( 'listfiles' ); |
99 | } |
100 | |
101 | $pager = new ImageListPager( |
102 | $this->getContext(), |
103 | $this->commentStore, |
104 | $this->getLinkRenderer(), |
105 | $this->dbProvider, |
106 | $this->repoGroup, |
107 | $this->userCache, |
108 | $this->userNameUtils, |
109 | $this->commentFormatter, |
110 | $userName, |
111 | $search, |
112 | $this->including(), |
113 | $showAll |
114 | ); |
115 | |
116 | $out = $this->getOutput(); |
117 | $out->setPageTitleMsg( $pageTitle ); |
118 | $out->addModuleStyles( 'mediawiki.special' ); |
119 | if ( $this->including() ) { |
120 | $out->addParserOutputContent( $pager->getBodyOutput() ); |
121 | } else { |
122 | $user = $pager->getRelevantUser(); |
123 | if ( $user ) { |
124 | $this->getSkin()->setRelevantUser( $user ); |
125 | } |
126 | $pager->getForm(); |
127 | $out->addParserOutputContent( $pager->getFullOutput() ); |
128 | } |
129 | } |
130 | |
131 | /** |
132 | * Return an array of subpages beginning with $search that this special page will accept. |
133 | * |
134 | * @param string $search Prefix to search for |
135 | * @param int $limit Maximum number of results to return (usually 10) |
136 | * @param int $offset Number of results to skip (usually 0) |
137 | * @return string[] Matching subpages |
138 | */ |
139 | public function prefixSearchSubpages( $search, $limit, $offset ) { |
140 | $search = $this->userNameUtils->getCanonical( $search ); |
141 | if ( !$search ) { |
142 | // No prefix suggestion for invalid user |
143 | return []; |
144 | } |
145 | // Autocomplete subpage as user list - public to allow caching |
146 | return $this->userNamePrefixSearch |
147 | ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset ); |
148 | } |
149 | |
150 | protected function getGroupName() { |
151 | return 'media'; |
152 | } |
153 | } |
154 | |
155 | /** @deprecated class alias since 1.41 */ |
156 | class_alias( SpecialListFiles::class, 'SpecialListFiles' ); |