MediaWiki master
SpecialListFiles.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
9use MediaWiki\Cache\LinkBatchFactory;
13use MediaWiki\Pager\ImageListPager;
20
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
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
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
133 protected function getGroupName() {
134 return 'media';
135 }
136}
137
139class_alias( SpecialListFiles::class, 'SpecialListFiles' );
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
Handle database storage of comments such as edit summaries and log reasons.
Prioritized list of file repositories.
Definition RepoGroup.php:30
Set options of the Parser.
Shortcut to construct an includable special page.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getSkin()
Shortcut to get the skin being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
including( $x=null)
Whether the special page is being evaluated via transclusion.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Implements Special:Listfiles.
__construct(RepoGroup $repoGroup, IConnectionProvider $dbProvider, CommentStore $commentStore, UserNameUtils $userNameUtils, UserNamePrefixSearch $userNamePrefixSearch, RowCommentFormatter $rowCommentFormatter, LinkBatchFactory $linkBatchFactory)
execute( $par)
Default execute method Checks user permissions.This must be overridden by subclasses; it will be made...
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Handles searching prefixes of user names.
UserNameUtils service.
Shared interface for rigor levels when dealing with User methods.
Provide primary and replica IDatabase connections.