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