26 namespace MediaWiki\Specials;
54 private $filename =
'';
78 parent::__construct(
'FileDuplicateSearch' );
79 $this->linkBatchFactory = $linkBatchFactory;
80 $this->repoGroup = $repoGroup;
81 $this->searchEngineFactory = $searchEngineFactory;
90 private function getDupes() {
91 return $this->repoGroup->findBySha1( $this->hash );
97 private function showList( $dupes ) {
99 $html[] =
"<ol class='special'>";
101 foreach ( $dupes as $dupe ) {
102 $line = $this->formatResult( $dupe );
103 $html[] =
"<li>" . $line .
"</li>";
107 $this->
getOutput()->addHTML( implode(
"\n", $html ) );
114 $this->filename = $par ?? $this->
getRequest()->getText(
'filename' );
118 if ( $title && $title->getText() !=
'' ) {
119 $this->file = $this->repoGroup->findFile( $title );
124 # Create the input form
128 'name' =>
'filename',
129 'label-message' =>
'fileduplicatesearch-filename',
132 'default' => $this->filename,
137 $htmlForm->setMethod(
'get' );
138 $htmlForm->setSubmitTextMsg( $this->
msg(
'fileduplicatesearch-submit' ) );
142 $htmlForm->prepareForm()->displayForm(
false );
145 $this->hash = $this->file->getSha1();
146 } elseif ( $this->filename !==
'' ) {
148 "<p class='mw-fileduplicatesearch-noresults'>\n$1\n</p>",
153 if ( $this->hash !=
'' ) {
154 # Show a thumbnail of the file
157 $thumb = $img->transform( [
'width' => 120,
'height' => 120 ] );
159 $out->addModuleStyles(
'mediawiki.special' );
160 $out->addHTML(
'<div id="mw-fileduplicatesearch-icon">' .
161 $thumb->toHtml( [
'desc-link' =>
false ] ) .
'<br />' .
162 $this->msg(
'fileduplicatesearch-info' )
163 ->numParams( $img->getWidth(), $img->getHeight() )
164 ->sizeParams( $img->getSize() )
165 ->params( $img->getMimeType() )->parseAsBlock() .
170 $dupes = $this->getDupes();
171 $numRows = count( $dupes );
173 # Show a short summary
174 if ( $numRows == 1 ) {
176 "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
179 } elseif ( $numRows ) {
181 "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
187 $this->doBatchLookups( $dupes );
188 $this->showList( $dupes );
195 private function doBatchLookups( $list ) {
196 $batch = $this->linkBatchFactory->newLinkBatch();
197 foreach ( $list as $file ) {
198 $batch->addObj(
$file->getTitle() );
199 if (
$file->isLocal() ) {
202 $batch->add(
NS_USER, $uploader->getName() );
215 private function formatResult( $result ) {
217 $nt = $result->getTitle();
218 $text = $this->languageConverter->convert( $nt->getText() );
219 $plink = $linkRenderer->makeLink(
225 if ( $result->isLocal() && $uploader ) {
227 $user .=
'<span style="white-space: nowrap;">';
230 } elseif ( $uploader ) {
231 $user = htmlspecialchars( $uploader->getName() );
233 $user =
'<span class="history-deleted">'
234 . $this->
msg(
'rev-deleted-user' )->escaped() .
'</span>';
237 $time = htmlspecialchars( $this->
getLanguage()->userTimeAndDate(
238 $result->getTimestamp(), $this->getUser() ) );
240 return "$plink . . $user . . $time";
253 if ( !$title || $title->getNamespace() !==
NS_FILE ) {
257 $searchEngine = $this->searchEngineFactory->create();
258 $searchEngine->setLimitOffset( $limit, $offset );
260 $searchEngine->setNamespaces( [
NS_FILE ] );
261 $result = $searchEngine->defaultPrefixSearch( $search );
263 return array_map(
static function (
Title $t ) {
265 return $t->getText();
277 class_alias( SpecialFileDuplicateSearch::class,
'SpecialFileDuplicateSearch' );
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...
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getPageTitle( $subpage=false)
Get a self-referential title object.
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.
getAuthority()
Shortcut to get the Authority executing this instance.
getContentLanguage()
Shortcut to get content language.
getLanguage()
Shortcut to get user's language.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Prioritized list of file repositories.
Factory class for SearchEngine.
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.