* @ingroup SpecialPage
*/
class FileDuplicateSearchPage extends QueryPage {
- protected $hash, $filename;
+ protected $hash = '', $filename = '';
+
+ /**
+ * @var File $file selected reference file, if present
+ */
+ protected $file = null;
function __construct( $name = 'FileDuplicateSearch' ) {
parent::__construct( $name );
return array( 'filename' => $this->filename );
}
+ /**
+ * Fetch dupes from all connected file repositories.
+ *
+ * @return Array of File objects
+ */
+ function getDupes() {
+ return RepoGroup::singleton()->findBySha1( $this->hash );
+ }
+
+ /**
+ *
+ * @param $dupes Array of File objects
+ */
+ function showList( $dupes ) {
+ $html = array();
+ $html[] = $this->openList( 0 );
+
+ foreach ( $dupes as $dupe ) {
+ $line = $this->formatResult( null, $dupe );
+ $html[] = "<li>" . $line . "</li>";
+ }
+ $html[] = $this->closeList();
+
+ $this->getOutput()->addHtml( implode( "\n", $html ) );
+ }
+
function getQueryInfo() {
return array(
'tables' => array( 'image' ),
'conds' => array( 'img_sha1' => $this->hash )
);
}
-
+
function execute( $par ) {
- global $wgRequest, $wgOut, $wgLang, $wgContLang, $wgScript;
-
+ global $wgScript;
+
$this->setHeaders();
$this->outputHeader();
-
- $this->filename = isset( $par ) ? $par : $wgRequest->getText( 'filename' );
+
+ $this->filename = isset( $par ) ? $par : $this->getRequest()->getText( 'filename' );
+ $this->file = null;
$this->hash = '';
- $title = Title::makeTitleSafe( NS_FILE, $this->filename );
+ $title = Title::newFromText( $this->filename, NS_FILE );
if( $title && $title->getText() != '' ) {
- $dbr = wfGetDB( DB_SLAVE );
- $this->hash = $dbr->selectField( 'image', 'img_sha1', array( 'img_name' => $title->getDBkey() ), __METHOD__ );
+ $this->file = wfFindFile( $title );
}
+ $out = $this->getOutput();
+
# Create the input form
- $wgOut->addHTML(
+ $out->addHTML(
Xml::openElement( 'form', array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => $wgScript ) ) .
Html::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
Xml::openElement( 'fieldset' ) .
Xml::closeElement( 'form' )
);
- if( $this->hash != '' ) {
- $align = $wgContLang->alignEnd();
+ if( $this->file ) {
+ $this->hash = $this->file->getSha1();
+ } elseif( $this->filename !== '' ) {
+ $out->wrapWikiMsg(
+ "<p class='mw-fileduplicatesearch-noresults'>\n$1\n</p>",
+ array( 'fileduplicatesearch-noresults', wfEscapeWikiText( $this->filename ) )
+ );
+ }
+ if( $this->hash != '' ) {
# Show a thumbnail of the file
- $img = wfFindFile( $title );
+ $img = $this->file;
if ( $img ) {
$thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
if( $thumb ) {
- $wgOut->addHTML( '<div style="float:' . $align . '" id="mw-fileduplicatesearch-icon">' .
+ $out->addHTML( '<div id="mw-fileduplicatesearch-icon">' .
$thumb->toHtml( array( 'desc-link' => false ) ) . '<br />' .
wfMsgExt( 'fileduplicatesearch-info', array( 'parse' ),
- $wgLang->formatNum( $img->getWidth() ),
- $wgLang->formatNum( $img->getHeight() ),
- $wgLang->formatSize( $img->getSize() ),
+ $this->getLanguage()->formatNum( $img->getWidth() ),
+ $this->getLanguage()->formatNum( $img->getHeight() ),
+ $this->getLanguage()->formatSize( $img->getSize() ),
$img->getMimeType()
) .
'</div>' );
}
}
- parent::execute( $par );
+ $dupes = $this->getDupes();
+ $numRows = count( $dupes );
# Show a short summary
- if( $this->numRows == 1 ) {
- $wgOut->wrapWikiMsg(
+ if( $numRows == 1 ) {
+ $out->wrapWikiMsg(
"<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
- array( 'fileduplicatesearch-result-1', $this->filename )
+ array( 'fileduplicatesearch-result-1', wfEscapeWikiText( $this->filename ) )
);
- } elseif ( $this->numRows > 1 ) {
- $wgOut->wrapWikiMsg(
+ } elseif ( $numRows ) {
+ $out->wrapWikiMsg(
"<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
- array( 'fileduplicatesearch-result-n', $this->filename,
- $wgLang->formatNum( $this->numRows - 1 ) )
+ array( 'fileduplicatesearch-result-n', wfEscapeWikiText( $this->filename ),
+ $this->getLanguage()->formatNum( $numRows - 1 ) )
);
}
+
+ $this->showList( $dupes );
}
}
+ /**
+ *
+ * @param Skin $skin
+ * @param File $result
+ * @return string
+ */
function formatResult( $skin, $result ) {
- global $wgContLang, $wgLang;
+ global $wgContLang;
- $nt = Title::makeTitle( NS_FILE, $result->title );
+ $nt = $result->getTitle();
$text = $wgContLang->convert( $nt->getText() );
- $plink = $skin->link(
+ $plink = Linker::link(
Title::newFromText( $nt->getPrefixedText() ),
$text
);
- $user = $skin->link( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text );
- $time = $wgLang->timeanddate( $result->img_timestamp );
+ $userText = $result->getUser( 'text' );
+ $user = Linker::link( Title::makeTitle( NS_USER, $userText ), $userText );
+ $time = $this->getLanguage()->timeanddate( $result->getTimestamp() );
return "$plink . . $user . . $time";
}