MediaWiki master
SpecialListFiles.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
31use RepoGroup;
33
40
41 private RepoGroup $repoGroup;
42 private IConnectionProvider $dbProvider;
43 private CommentStore $commentStore;
44 private UserNameUtils $userNameUtils;
45 private UserNamePrefixSearch $userNamePrefixSearch;
46 private CommentFormatter $commentFormatter;
47 private LinkBatchFactory $linkBatchFactory;
48
58 public function __construct(
59 RepoGroup $repoGroup,
60 IConnectionProvider $dbProvider,
61 CommentStore $commentStore,
62 UserNameUtils $userNameUtils,
63 UserNamePrefixSearch $userNamePrefixSearch,
64 CommentFormatter $commentFormatter,
65 LinkBatchFactory $linkBatchFactory
66 ) {
67 parent::__construct( 'Listfiles' );
68 $this->repoGroup = $repoGroup;
69 $this->dbProvider = $dbProvider;
70 $this->commentStore = $commentStore;
71 $this->userNameUtils = $userNameUtils;
72 $this->userNamePrefixSearch = $userNamePrefixSearch;
73 $this->commentFormatter = $commentFormatter;
74 $this->linkBatchFactory = $linkBatchFactory;
75 }
76
77 public function execute( $par ) {
78 $this->setHeaders();
79 $this->outputHeader();
80 $this->addHelpLink( 'Help:Managing_files' );
81
82 if ( $this->including() ) {
83 $userName = (string)$par;
84 $search = '';
85 $showAll = false;
86 } else {
87 $userName = $this->getRequest()->getText( 'user', $par ?? '' );
88 $search = $this->getRequest()->getText( 'ilsearch', '' );
89 $showAll = $this->getRequest()->getBool( 'ilshowall', false );
90 }
91 // Sanitize usernames to avoid symbols in the title of page.
92 $sanitizedUserName = $this->userNameUtils->getCanonical( $userName, UserRigorOptions::RIGOR_NONE );
93 if ( $sanitizedUserName !== false ) {
94 $userName = $sanitizedUserName;
95 }
96
97 if ( $userName !== '' ) {
98 $pageTitle = $this->msg( 'listfiles_subpage' )->plaintextParams( $userName );
99 } else {
100 $pageTitle = $this->msg( 'listfiles' );
101 }
102
103 $pager = new ImageListPager(
104 $this->getContext(),
105 $this->commentStore,
106 $this->getLinkRenderer(),
107 $this->dbProvider,
108 $this->repoGroup,
109 $this->userNameUtils,
110 $this->commentFormatter,
111 $this->linkBatchFactory,
112 $userName,
113 $search,
114 $this->including(),
115 $showAll
116 );
117
118 $out = $this->getOutput();
119 $out->setPageTitleMsg( $pageTitle );
120 $out->addModuleStyles( 'mediawiki.special' );
121 if ( $this->including() ) {
122 $out->addParserOutputContent( $pager->getBodyOutput() );
123 } else {
124 $user = $pager->getRelevantUser();
125 if ( $user ) {
126 $this->getSkin()->setRelevantUser( $user );
127 }
128 $pager->getForm();
129 $out->addParserOutputContent( $pager->getFullOutput() );
130 }
131 }
132
141 public function prefixSearchSubpages( $search, $limit, $offset ) {
142 $search = $this->userNameUtils->getCanonical( $search );
143 if ( !$search ) {
144 // No prefix suggestion for invalid user
145 return [];
146 }
147 // Autocomplete subpage as user list - public to allow caching
148 return $this->userNamePrefixSearch
149 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
150 }
151
152 protected function getGroupName() {
153 return 'media';
154 }
155}
156
158class_alias( SpecialListFiles::class, 'SpecialListFiles' );
This is the main service interface for converting single-line comments from various DB comment fields...
Handle database storage of comments such as edit summaries and log reasons.
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, CommentFormatter $commentFormatter, 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.
Prioritized list of file repositories.
Definition RepoGroup.php:30
Shared interface for rigor levels when dealing with User methods.
Provide primary and replica IDatabase connections.