MediaWiki master
SpecialListFiles.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
34
41
42 private RepoGroup $repoGroup;
43 private IConnectionProvider $dbProvider;
44 private CommentStore $commentStore;
45 private UserNameUtils $userNameUtils;
46 private UserNamePrefixSearch $userNamePrefixSearch;
47 private RowCommentFormatter $rowCommentFormatter;
48 private LinkBatchFactory $linkBatchFactory;
49
50 public function __construct(
51 RepoGroup $repoGroup,
52 IConnectionProvider $dbProvider,
53 CommentStore $commentStore,
54 UserNameUtils $userNameUtils,
55 UserNamePrefixSearch $userNamePrefixSearch,
56 RowCommentFormatter $rowCommentFormatter,
57 LinkBatchFactory $linkBatchFactory
58 ) {
59 parent::__construct( 'Listfiles' );
60 $this->repoGroup = $repoGroup;
61 $this->dbProvider = $dbProvider;
62 $this->commentStore = $commentStore;
63 $this->userNameUtils = $userNameUtils;
64 $this->userNamePrefixSearch = $userNamePrefixSearch;
65 $this->rowCommentFormatter = $rowCommentFormatter;
66 $this->linkBatchFactory = $linkBatchFactory;
67 }
68
69 public function execute( $par ) {
70 $this->setHeaders();
71 $this->outputHeader();
72 $this->addHelpLink( 'Help:Managing_files' );
73
74 if ( $this->including() ) {
75 $userName = (string)$par;
76 $search = '';
77 $showAll = false;
78 } else {
79 $userName = $this->getRequest()->getText( 'user', $par ?? '' );
80 $search = $this->getRequest()->getText( 'ilsearch', '' );
81 $showAll = $this->getRequest()->getBool( 'ilshowall', false );
82 }
83 // Sanitize usernames to avoid symbols in the title of page.
84 $sanitizedUserName = $this->userNameUtils->getCanonical( $userName, UserRigorOptions::RIGOR_NONE );
85 if ( $sanitizedUserName !== false ) {
86 $userName = $sanitizedUserName;
87 }
88
89 if ( $userName !== '' ) {
90 $pageTitle = $this->msg( 'listfiles_subpage' )->plaintextParams( $userName );
91 } else {
92 $pageTitle = $this->msg( 'listfiles' );
93 }
94
95 $pager = new ImageListPager(
96 $this->getContext(),
97 $this->commentStore,
98 $this->getLinkRenderer(),
99 $this->dbProvider,
100 $this->repoGroup,
101 $this->userNameUtils,
102 $this->rowCommentFormatter,
103 $this->linkBatchFactory,
104 $userName,
105 $search,
106 $this->including(),
107 $showAll
108 );
109
110 $out = $this->getOutput();
111 $out->setPageTitleMsg( $pageTitle );
112 $out->addModuleStyles( 'mediawiki.special' );
113 $parserOptions = ParserOptions::newFromContext( $this->getContext() );
114 if ( $this->including() ) {
115 $out->addParserOutputContent( $pager->getBodyOutput(), $parserOptions );
116 } else {
117 $user = $pager->getRelevantUser();
118 if ( $user ) {
119 $this->getSkin()->setRelevantUser( $user );
120 }
121 $pager->getForm();
122 $out->addParserOutputContent( $pager->getFullOutput(), $parserOptions );
123 }
124 }
125
134 public function prefixSearchSubpages( $search, $limit, $offset ) {
135 $search = $this->userNameUtils->getCanonical( $search );
136 if ( !$search ) {
137 // No prefix suggestion for invalid user
138 return [];
139 }
140 // Autocomplete subpage as user list - public to allow caching
141 return $this->userNamePrefixSearch
142 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
143 }
144
145 protected function getGroupName() {
146 return 'media';
147 }
148}
149
151class_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:38
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.
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.