| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use MediaWiki\Cache\LinkBatchFactory; |
| 24 |
use MediaWiki\CommentFormatter\CommentFormatter; |
| 25 |
use MediaWiki\CommentStore\CommentStore; |
| 26 |
use MediaWiki\Pager\ImageListPager; |
| 27 |
use MediaWiki\SpecialPage\IncludableSpecialPage; |
| 28 |
use MediaWiki\User\UserNamePrefixSearch; |
| 29 |
use MediaWiki\User\UserNameUtils; |
| 30 |
use MediaWiki\User\UserRigorOptions; |
| 31 |
use RepoGroup; |
| 32 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
class SpecialListFiles extends IncludableSpecialPage { |
| 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 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 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 |
|
| 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 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public function prefixSearchSubpages( $search, $limit, $offset ) { |
| 142 |
$search = $this->userNameUtils->getCanonical( $search ); |
| 143 |
if ( !$search ) { |
| 144 |
|
| 145 |
return []; |
| 146 |
} |
| 147 |
|
| 148 |
return $this->userNamePrefixSearch |
| 149 |
->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset ); |
| 150 |
} |
| 151 |
|
| 152 |
protected function getGroupName() { |
| 153 |
return 'media'; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
class_alias( SpecialListFiles::class, 'SpecialListFiles' ); |