50 private $filename =
'';
68 parent::__construct(
'FileDuplicateSearch' );
69 $this->linkBatchFactory = $linkBatchFactory;
70 $this->repoGroup = $repoGroup;
71 $this->searchEngineFactory = $searchEngineFactory;
80 private function getDupes() {
81 return $this->repoGroup->findBySha1( $this->hash );
87 private function showList( $dupes ) {
89 $html[] =
"<ol class='special'>";
91 foreach ( $dupes as $dupe ) {
92 $line = $this->formatResult( $dupe );
93 $html[] =
"<li>" . $line .
"</li>";
97 $this->
getOutput()->addHTML( implode(
"\n", $html ) );
104 $this->filename = $par ?? $this->
getRequest()->getText(
'filename' );
107 $title = Title::newFromText( $this->filename,
NS_FILE );
108 if ( $title && $title->getText() !=
'' ) {
109 $this->file = $this->repoGroup->findFile( $title );
114 # Create the input form
118 'name' =>
'filename',
119 'label-message' =>
'fileduplicatesearch-filename',
122 'default' => $this->filename,
125 $htmlForm = HTMLForm::factory(
'ooui', $formFields, $this->
getContext() );
127 $htmlForm->setMethod(
'get' );
128 $htmlForm->setSubmitTextMsg( $this->
msg(
'fileduplicatesearch-submit' ) );
132 $htmlForm->prepareForm()->displayForm(
false );
135 $this->hash = $this->file->getSha1();
136 } elseif ( $this->filename !==
'' ) {
138 "<p class='mw-fileduplicatesearch-noresults'>\n$1\n</p>",
143 if ( $this->hash !=
'' ) {
144 # Show a thumbnail of the file
147 $thumb = $img->transform( [
'width' => 120,
'height' => 120 ] );
149 $out->addModuleStyles(
'mediawiki.special' );
150 $out->addHTML(
'<div id="mw-fileduplicatesearch-icon">' .
151 $thumb->toHtml( [
'desc-link' =>
false ] ) .
'<br />' .
152 $this->msg(
'fileduplicatesearch-info' )
153 ->numParams( $img->getWidth(), $img->getHeight() )
154 ->sizeParams( $img->getSize() )
155 ->params( $img->getMimeType() )->parseAsBlock() .
160 $dupes = $this->getDupes();
161 $numRows = count( $dupes );
163 # Show a short summary
164 if ( $numRows == 1 ) {
166 "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
169 } elseif ( $numRows ) {
171 "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
177 $this->doBatchLookups( $dupes );
178 $this->showList( $dupes );
185 private function doBatchLookups( $list ) {
186 $batch = $this->linkBatchFactory->newLinkBatch();
187 foreach ( $list as $file ) {
188 $batch->addObj( $file->getTitle() );
189 if ( $file->isLocal() ) {
190 $uploader = $file->getUploader( File::FOR_THIS_USER, $this->
getAuthority() );
192 $batch->addUser( $uploader );
204 private function formatResult( $result ) {
206 $nt = $result->getTitle();
207 $text = $this->languageConverter->convert( $nt->getText() );
208 $plink = $linkRenderer->makeLink(
213 $uploader = $result->getUploader( File::FOR_THIS_USER, $this->
getAuthority() );
214 if ( $result->isLocal() && $uploader ) {
215 $user = Linker::userLink( $uploader->getId(), $uploader->getName() );
216 $user .=
'<span style="white-space: nowrap;">';
217 $user .= Linker::userToolLinks( $uploader->getId(), $uploader->getName() );
219 } elseif ( $uploader ) {
220 $user = htmlspecialchars( $uploader->getName() );
222 $user =
'<span class="history-deleted">'
223 . $this->
msg(
'rev-deleted-user' )->escaped() .
'</span>';
226 $time = htmlspecialchars( $this->
getLanguage()->userTimeAndDate(
227 $result->getTimestamp(), $this->getUser() ) );
229 return "$plink . . $user . . $time";
241 $title = Title::newFromText( $search,
NS_FILE );
242 if ( !$title || $title->getNamespace() !==
NS_FILE ) {
246 $searchEngine = $this->searchEngineFactory->create();
247 $searchEngine->setLimitOffset( $limit, $offset );
249 $searchEngine->setNamespaces( [
NS_FILE ] );
250 $result = $searchEngine->defaultPrefixSearch( $search );
252 return array_map(
static function (
Title $t ) {
254 return $t->getText();
264class_alias( SpecialFileDuplicateSearch::class,
'SpecialFileDuplicateSearch' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
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 By default the message key is the canonical name of...
Factory class for SearchEngine.