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