44 private $filename =
'';
52 private $linkBatchFactory;
58 private $searchEngineFactory;
61 private $languageConverter;
75 parent::__construct(
'FileDuplicateSearch' );
76 $this->linkBatchFactory = $linkBatchFactory;
77 $this->repoGroup = $repoGroup;
78 $this->searchEngineFactory = $searchEngineFactory;
87 private function getDupes() {
88 return $this->repoGroup->findBySha1( $this->hash );
94 private function showList( $dupes ) {
96 $html[] =
"<ol class='special'>";
98 foreach ( $dupes as $dupe ) {
99 $line = $this->formatResult( $dupe );
100 $html[] =
"<li>" .
$line .
"</li>";
104 $this->
getOutput()->addHTML( implode(
"\n", $html ) );
111 $this->filename = $par ?? $this->
getRequest()->getText(
'filename' );
116 $this->file = $this->repoGroup->findFile(
$title );
121 # Create the input form
125 'name' =>
'filename',
126 'label-message' =>
'fileduplicatesearch-filename',
129 'default' => $this->filename,
132 $htmlForm = HTMLForm::factory(
'ooui', $formFields, $this->
getContext() );
134 $htmlForm->setMethod(
'get' );
135 $htmlForm->setSubmitTextMsg( $this->
msg(
'fileduplicatesearch-submit' ) );
139 $htmlForm->prepareForm()->displayForm(
false );
142 $this->hash = $this->file->getSha1();
143 } elseif ( $this->filename !==
'' ) {
145 "<p class='mw-fileduplicatesearch-noresults'>\n$1\n</p>",
150 if ( $this->hash !=
'' ) {
151 # Show a thumbnail of the file
154 $thumb = $img->transform( [
'width' => 120,
'height' => 120 ] );
156 $out->addModuleStyles(
'mediawiki.special' );
157 $out->addHTML(
'<div id="mw-fileduplicatesearch-icon">' .
158 $thumb->toHtml( [
'desc-link' =>
false ] ) .
'<br />' .
159 $this->msg(
'fileduplicatesearch-info' )
160 ->numParams( $img->getWidth(), $img->getHeight() )
161 ->sizeParams( $img->getSize() )
162 ->params( $img->getMimeType() )->parseAsBlock() .
167 $dupes = $this->getDupes();
168 $numRows = count( $dupes );
170 # Show a short summary
171 if ( $numRows == 1 ) {
173 "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
176 } elseif ( $numRows ) {
178 "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
184 $this->doBatchLookups( $dupes );
185 $this->showList( $dupes );
192 private function doBatchLookups( $list ) {
193 $batch = $this->linkBatchFactory->newLinkBatch();
194 foreach ( $list as $file ) {
195 $batch->addObj(
$file->getTitle() );
196 if (
$file->isLocal() ) {
199 $batch->add(
NS_USER, $uploader->getName() );
212 private function formatResult( $result ) {
214 $nt = $result->getTitle();
215 $text = $this->languageConverter->convert( $nt->getText() );
216 $plink = $linkRenderer->makeLink(
221 $uploader = $result->getUploader( File::FOR_THIS_USER, $this->
getAuthority() );
222 if ( $result->isLocal() && $uploader ) {
224 $user .=
'<span style="white-space: nowrap;">';
227 } elseif ( $uploader ) {
228 $user = htmlspecialchars( $uploader->getName() );
230 $user =
'<span class="history-deleted">'
231 . $this->
msg(
'rev-deleted-user' )->escaped() .
'</span>';
234 $time = htmlspecialchars( $this->
getLanguage()->userTimeAndDate(
235 $result->getTimestamp(), $this->getUser() ) );
237 return "$plink . . $user . . $time";
254 $searchEngine = $this->searchEngineFactory->create();
255 $searchEngine->setLimitOffset( $limit, $offset );
257 $searchEngine->setNamespaces( [
NS_FILE ] );
258 $result = $searchEngine->defaultPrefixSearch( $search );
260 return array_map(
static function (
Title $t ) {
262 return $t->getText();
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Implements some public methods and some protected utility functions which are required by multiple ch...
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null, $useParentheses=true)
Generate standard user tool links (talk, contributions, block link, etc.)
Prioritized list of file repositories.
Factory class for SearchEngine.
Searches the database for files of the requested hash, comparing this with the 'img_sha1' field in th...
execute( $par)
Default execute method Checks user permissions.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(LinkBatchFactory $linkBatchFactory, RepoGroup $repoGroup, SearchEngineFactory $searchEngineFactory, LanguageConverterFactory $languageConverterFactory)
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getAuthority()
Shortcut to get the Authority executing this instance.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
getLanguage()
Shortcut to get user's language.
getContentLanguage()
Shortcut to get content language.
Represents a title within MediaWiki.
The shared interface for all language converters.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.