MediaWiki master
SpecialListFiles.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
13use MediaWiki\Pager\ImageListPager;
20
27
28 public function __construct(
29 private readonly RepoGroup $repoGroup,
30 private readonly IConnectionProvider $dbProvider,
31 private readonly CommentStore $commentStore,
32 private readonly UserNameUtils $userNameUtils,
33 private readonly UserNamePrefixSearch $userNamePrefixSearch,
34 private readonly RowCommentFormatter $rowCommentFormatter,
35 private readonly LinkBatchFactory $linkBatchFactory,
36 ) {
37 parent::__construct( 'Listfiles' );
38 }
39
41 public function execute( $par ) {
42 $this->setHeaders();
43 $this->outputHeader();
44 $this->addHelpLink( 'Help:Managing_files' );
45
46 if ( $this->including() ) {
47 $userName = (string)$par;
48 $search = '';
49 $showAll = false;
50 } else {
51 $userName = $this->getRequest()->getText( 'user', $par ?? '' );
52 $search = $this->getRequest()->getText( 'ilsearch', '' );
53 $showAll = $this->getRequest()->getBool( 'ilshowall', false );
54 }
55 // Sanitize usernames to avoid symbols in the title of page.
56 $sanitizedUserName = $this->userNameUtils->getCanonical( $userName, UserRigorOptions::RIGOR_NONE );
57 if ( $sanitizedUserName !== false ) {
58 $userName = $sanitizedUserName;
59 }
60
61 if ( $userName !== '' ) {
62 $pageTitle = $this->msg( 'listfiles_subpage' )->plaintextParams( $userName );
63 } else {
64 $pageTitle = $this->msg( 'listfiles' );
65 }
66
67 $pager = new ImageListPager(
68 $this->getContext(),
69 $this->commentStore,
70 $this->getLinkRenderer(),
71 $this->dbProvider,
72 $this->repoGroup,
73 $this->userNameUtils,
74 $this->rowCommentFormatter,
75 $this->linkBatchFactory,
76 $userName,
77 $search,
78 $this->including(),
79 $showAll
80 );
81
82 $out = $this->getOutput();
83 $out->setPageTitleMsg( $pageTitle );
84 $out->addModuleStyles( 'mediawiki.special' );
85 $parserOptions = ParserOptions::newFromContext( $this->getContext() );
86 if ( $this->including() ) {
87 $out->addParserOutputContent( $pager->getBodyOutput(), $parserOptions );
88 } else {
89 $user = $pager->getRelevantUser();
90 if ( $user ) {
91 $this->getSkin()->setRelevantUser( $user );
92 }
93 $pager->getForm();
94 $out->addParserOutputContent( $pager->getFullOutput(), $parserOptions );
95 }
96 }
97
106 public function prefixSearchSubpages( $search, $limit, $offset ) {
107 $search = $this->userNameUtils->getCanonical( $search );
108 if ( !$search ) {
109 // No prefix suggestion for invalid user
110 return [];
111 }
112 // Autocomplete subpage as user list - public to allow caching
113 return $this->userNamePrefixSearch
114 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
115 }
116
118 protected function getGroupName() {
119 return 'media';
120 }
121}
122
124class_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
Factory for LinkBatch objects to batch query page metadata.
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.
execute( $par)
Default execute method Checks user permissions.This must be overridden by subclasses; it will be made...
__construct(private readonly RepoGroup $repoGroup, private readonly IConnectionProvider $dbProvider, private readonly CommentStore $commentStore, private readonly UserNameUtils $userNameUtils, private readonly UserNamePrefixSearch $userNamePrefixSearch, private readonly RowCommentFormatter $rowCommentFormatter, private readonly LinkBatchFactory $linkBatchFactory,)
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.