2008-03-19 16:58:56 +00:00
|
|
|
<?php
|
2010-06-21 12:59:04 +00:00
|
|
|
/**
|
2010-08-14 19:19:41 +00:00
|
|
|
* Implements Special:FileDuplicateSearch
|
2010-06-21 12:59:04 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:16:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-06-21 12:59:04 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2008-03-19 16:58:56 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup SpecialPage
|
2008-03-19 16:58:56 +00:00
|
|
|
* @author Raimond Spekking, based on Special:MIMESearch by Ævar Arnfjörð Bjarmason
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Searches the database for files of the requested hash, comparing this with the
|
|
|
|
|
* 'img_sha1' field in the image table.
|
2010-08-14 19:19:41 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup SpecialPage
|
2008-03-19 16:58:56 +00:00
|
|
|
*/
|
|
|
|
|
class FileDuplicateSearchPage extends QueryPage {
|
2011-02-07 02:35:35 +00:00
|
|
|
protected $hash = '', $filename = '';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var File $file selected reference file, if present
|
|
|
|
|
*/
|
|
|
|
|
protected $file = null;
|
2008-03-19 16:58:56 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
function __construct( $name = 'FileDuplicateSearch' ) {
|
|
|
|
|
parent::__construct( $name );
|
2008-03-19 16:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-24 17:44:57 +00:00
|
|
|
function isSyndicated() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isCacheable() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isCached() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-03-19 16:58:56 +00:00
|
|
|
|
|
|
|
|
function linkParameters() {
|
|
|
|
|
return array( 'filename' => $this->filename );
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-07 02:35:35 +00:00
|
|
|
/**
|
|
|
|
|
* Fetch dupes from all connected file repositories.
|
|
|
|
|
*
|
2014-07-24 17:43:44 +00:00
|
|
|
* @return array Array of File objects
|
2011-02-07 02:35:35 +00:00
|
|
|
*/
|
|
|
|
|
function getDupes() {
|
|
|
|
|
return RepoGroup::singleton()->findBySha1( $this->hash );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2014-07-24 17:43:44 +00:00
|
|
|
* @param array $dupes Array of File objects
|
2011-02-07 02:35:35 +00:00
|
|
|
*/
|
|
|
|
|
function showList( $dupes ) {
|
|
|
|
|
$html = array();
|
|
|
|
|
$html[] = $this->openList( 0 );
|
|
|
|
|
|
2011-02-18 01:10:38 +00:00
|
|
|
foreach ( $dupes as $dupe ) {
|
2011-08-05 14:58:37 +00:00
|
|
|
$line = $this->formatResult( null, $dupe );
|
2011-02-07 02:35:35 +00:00
|
|
|
$html[] = "<li>" . $line . "</li>";
|
|
|
|
|
}
|
|
|
|
|
$html[] = $this->closeList();
|
|
|
|
|
|
2011-08-05 14:58:37 +00:00
|
|
|
$this->getOutput()->addHtml( implode( "\n", $html ) );
|
2011-02-07 02:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
function getQueryInfo() {
|
|
|
|
|
return array(
|
|
|
|
|
'tables' => array( 'image' ),
|
|
|
|
|
'fields' => array(
|
2012-08-15 13:16:09 +00:00
|
|
|
'title' => 'img_name',
|
|
|
|
|
'value' => 'img_sha1',
|
2010-12-22 14:16:25 +00:00
|
|
|
'img_user_text',
|
|
|
|
|
'img_timestamp'
|
|
|
|
|
),
|
|
|
|
|
'conds' => array( 'img_sha1' => $this->hash )
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
function execute( $par ) {
|
|
|
|
|
$this->setHeaders();
|
|
|
|
|
$this->outputHeader();
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2014-05-24 05:45:33 +00:00
|
|
|
$this->filename = $par !== null ? $par : $this->getRequest()->getText( 'filename' );
|
2011-02-07 02:35:35 +00:00
|
|
|
$this->file = null;
|
2010-12-22 14:16:25 +00:00
|
|
|
$this->hash = '';
|
2011-02-07 02:35:35 +00:00
|
|
|
$title = Title::newFromText( $this->filename, NS_FILE );
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $title && $title->getText() != '' ) {
|
2011-02-07 02:35:35 +00:00
|
|
|
$this->file = wfFindFile( $title );
|
2010-12-22 14:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-05 14:58:37 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
# Create the input form
|
2011-08-05 14:58:37 +00:00
|
|
|
$out->addHTML(
|
2013-04-14 17:27:14 +00:00
|
|
|
Html::openElement(
|
|
|
|
|
'form',
|
2014-08-03 21:25:52 +00:00
|
|
|
array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => wfScript() )
|
2013-04-14 17:27:14 +00:00
|
|
|
) . "\n" .
|
2013-12-24 08:07:04 +00:00
|
|
|
Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) . "\n" .
|
2013-04-14 17:27:14 +00:00
|
|
|
Html::openElement( 'fieldset' ) . "\n" .
|
|
|
|
|
Html::element( 'legend', null, $this->msg( 'fileduplicatesearch-legend' )->text() ) . "\n" .
|
|
|
|
|
Xml::inputLabel(
|
|
|
|
|
$this->msg( 'fileduplicatesearch-filename' )->text(),
|
|
|
|
|
'filename',
|
|
|
|
|
'filename',
|
|
|
|
|
50,
|
|
|
|
|
$this->filename
|
|
|
|
|
) . "\n" .
|
|
|
|
|
Xml::submitButton( $this->msg( 'fileduplicatesearch-submit' )->text() ) . "\n" .
|
|
|
|
|
Html::closeElement( 'fieldset' ) . "\n" .
|
|
|
|
|
Html::closeElement( 'form' )
|
2010-12-22 14:16:25 +00:00
|
|
|
);
|
|
|
|
|
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $this->file ) {
|
2011-02-07 02:35:35 +00:00
|
|
|
$this->hash = $this->file->getSha1();
|
2013-04-14 17:27:14 +00:00
|
|
|
} elseif ( $this->filename !== '' ) {
|
2011-08-05 14:58:37 +00:00
|
|
|
$out->wrapWikiMsg(
|
2011-02-07 02:35:35 +00:00
|
|
|
"<p class='mw-fileduplicatesearch-noresults'>\n$1\n</p>",
|
|
|
|
|
array( 'fileduplicatesearch-noresults', wfEscapeWikiText( $this->filename ) )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $this->hash != '' ) {
|
2010-12-22 14:16:25 +00:00
|
|
|
# Show a thumbnail of the file
|
2011-02-07 02:35:35 +00:00
|
|
|
$img = $this->file;
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $img ) {
|
|
|
|
|
$thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $thumb ) {
|
2011-09-07 05:23:16 +00:00
|
|
|
$out->addHTML( '<div id="mw-fileduplicatesearch-icon">' .
|
2010-12-22 14:16:25 +00:00
|
|
|
$thumb->toHtml( array( 'desc-link' => false ) ) . '<br />' .
|
2011-12-24 17:03:59 +00:00
|
|
|
$this->msg( 'fileduplicatesearch-info' )->numParams(
|
|
|
|
|
$img->getWidth(), $img->getHeight() )->params(
|
2013-04-14 17:27:14 +00:00
|
|
|
$this->getLanguage()->formatSize( $img->getSize() ),
|
|
|
|
|
$img->getMimeType() )->parseAsBlock() .
|
2010-12-22 14:16:25 +00:00
|
|
|
'</div>' );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-03-19 16:58:56 +00:00
|
|
|
|
2011-02-07 02:35:35 +00:00
|
|
|
$dupes = $this->getDupes();
|
|
|
|
|
$numRows = count( $dupes );
|
2010-12-22 14:16:25 +00:00
|
|
|
|
|
|
|
|
# Show a short summary
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $numRows == 1 ) {
|
2011-08-05 14:58:37 +00:00
|
|
|
$out->wrapWikiMsg(
|
2010-12-22 14:16:25 +00:00
|
|
|
"<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
|
2011-02-07 02:35:35 +00:00
|
|
|
array( 'fileduplicatesearch-result-1', wfEscapeWikiText( $this->filename ) )
|
2010-12-22 14:16:25 +00:00
|
|
|
);
|
2011-02-07 02:35:35 +00:00
|
|
|
} elseif ( $numRows ) {
|
2011-08-05 14:58:37 +00:00
|
|
|
$out->wrapWikiMsg(
|
2010-12-22 14:16:25 +00:00
|
|
|
"<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
|
2011-02-07 02:35:35 +00:00
|
|
|
array( 'fileduplicatesearch-result-n', wfEscapeWikiText( $this->filename ),
|
2011-11-21 16:13:21 +00:00
|
|
|
$this->getLanguage()->formatNum( $numRows - 1 ) )
|
2010-12-22 14:16:25 +00:00
|
|
|
);
|
|
|
|
|
}
|
2011-02-07 02:35:35 +00:00
|
|
|
|
2012-07-06 21:48:08 +00:00
|
|
|
$this->doBatchLookups( $dupes );
|
2011-02-07 02:35:35 +00:00
|
|
|
$this->showList( $dupes );
|
2010-12-22 14:16:25 +00:00
|
|
|
}
|
2008-03-19 16:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-06 21:48:08 +00:00
|
|
|
function doBatchLookups( $list ) {
|
|
|
|
|
$batch = new LinkBatch();
|
2013-04-14 17:27:14 +00:00
|
|
|
/** @var File $file */
|
|
|
|
|
foreach ( $list as $file ) {
|
2012-07-06 21:48:08 +00:00
|
|
|
$batch->addObj( $file->getTitle() );
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $file->isLocal() ) {
|
2012-07-06 21:48:08 +00:00
|
|
|
$userName = $file->getUser( 'text' );
|
|
|
|
|
$batch->add( NS_USER, $userName );
|
|
|
|
|
$batch->add( NS_USER_TALK, $userName );
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-14 17:27:14 +00:00
|
|
|
|
2012-07-06 21:48:08 +00:00
|
|
|
$batch->execute();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-07 02:35:35 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param Skin $skin
|
|
|
|
|
* @param File $result
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2008-03-19 16:58:56 +00:00
|
|
|
function formatResult( $skin, $result ) {
|
2011-08-05 14:58:37 +00:00
|
|
|
global $wgContLang;
|
2008-03-19 16:58:56 +00:00
|
|
|
|
2011-02-07 02:35:35 +00:00
|
|
|
$nt = $result->getTitle();
|
2008-03-19 16:58:56 +00:00
|
|
|
$text = $wgContLang->convert( $nt->getText() );
|
2011-08-05 14:58:37 +00:00
|
|
|
$plink = Linker::link(
|
2009-06-06 17:00:20 +00:00
|
|
|
Title::newFromText( $nt->getPrefixedText() ),
|
|
|
|
|
$text
|
|
|
|
|
);
|
2008-03-19 16:58:56 +00:00
|
|
|
|
2011-02-07 02:35:35 +00:00
|
|
|
$userText = $result->getUser( 'text' );
|
2012-07-06 21:48:08 +00:00
|
|
|
if ( $result->isLocal() ) {
|
|
|
|
|
$userId = $result->getUser( 'id' );
|
|
|
|
|
$user = Linker::userLink( $userId, $userText );
|
2014-12-20 21:36:43 +00:00
|
|
|
$user .= $this->getContext()->msg( 'word-separator' )->escaped();
|
2012-07-06 21:48:08 +00:00
|
|
|
$user .= '<span style="white-space: nowrap;">';
|
|
|
|
|
$user .= Linker::userToolLinks( $userId, $userText );
|
|
|
|
|
$user .= '</span>';
|
|
|
|
|
} else {
|
|
|
|
|
$user = htmlspecialchars( $userText );
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-24 17:03:59 +00:00
|
|
|
$time = $this->getLanguage()->userTimeAndDate( $result->getTimestamp(), $this->getUser() );
|
2008-03-19 16:58:56 +00:00
|
|
|
|
|
|
|
|
return "$plink . . $user . . $time";
|
|
|
|
|
}
|
2013-03-07 20:15:54 +00:00
|
|
|
|
|
|
|
|
protected function getGroupName() {
|
|
|
|
|
return 'media';
|
|
|
|
|
}
|
2008-03-19 16:58:56 +00:00
|
|
|
}
|