Index: trunk/phase3/includes/specials/SpecialFileDuplicateSearch.php |
— | — | @@ -29,8 +29,13 @@ |
30 | 30 | * @ingroup SpecialPage |
31 | 31 | */ |
32 | 32 | class FileDuplicateSearchPage extends QueryPage { |
33 | | - protected $hash, $filename; |
| 33 | + protected $hash = '', $filename = ''; |
34 | 34 | |
| 35 | + /** |
| 36 | + * @var File $file selected reference file, if present |
| 37 | + */ |
| 38 | + protected $file = null; |
| 39 | + |
35 | 40 | function __construct( $name = 'FileDuplicateSearch' ) { |
36 | 41 | parent::__construct( $name ); |
37 | 42 | } |
— | — | @@ -43,6 +48,35 @@ |
44 | 49 | return array( 'filename' => $this->filename ); |
45 | 50 | } |
46 | 51 | |
| 52 | + /** |
| 53 | + * Fetch dupes from all connected file repositories. |
| 54 | + * |
| 55 | + * @return Array of File objects |
| 56 | + */ |
| 57 | + function getDupes() { |
| 58 | + return RepoGroup::singleton()->findBySha1( $this->hash ); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * |
| 63 | + * @param Array of File objects $dupes |
| 64 | + */ |
| 65 | + function showList( $dupes ) { |
| 66 | + global $wgUser, $wgOut; |
| 67 | + $skin = $wgUser->getSkin(); |
| 68 | + |
| 69 | + $html = array(); |
| 70 | + $html[] = $this->openList( 0 ); |
| 71 | + |
| 72 | + foreach ( $dupes as $key => $dupe ) { |
| 73 | + $line = $this->formatResult( $skin, $dupe ); |
| 74 | + $html[] = "<li>" . $line . "</li>"; |
| 75 | + } |
| 76 | + $html[] = $this->closeList(); |
| 77 | + |
| 78 | + $wgOut->addHtml( implode( "\n", $html ) ); |
| 79 | + } |
| 80 | + |
47 | 81 | function getQueryInfo() { |
48 | 82 | return array( |
49 | 83 | 'tables' => array( 'image' ), |
— | — | @@ -63,11 +97,11 @@ |
64 | 98 | $this->outputHeader(); |
65 | 99 | |
66 | 100 | $this->filename = isset( $par ) ? $par : $wgRequest->getText( 'filename' ); |
| 101 | + $this->file = null; |
67 | 102 | $this->hash = ''; |
68 | | - $title = Title::makeTitleSafe( NS_FILE, $this->filename ); |
| 103 | + $title = Title::newFromText( $this->filename, NS_FILE ); |
69 | 104 | if( $title && $title->getText() != '' ) { |
70 | | - $dbr = wfGetDB( DB_SLAVE ); |
71 | | - $this->hash = $dbr->selectField( 'image', 'img_sha1', array( 'img_name' => $title->getDBkey() ), __METHOD__ ); |
| 105 | + $this->file = wfFindFile( $title ); |
72 | 106 | } |
73 | 107 | |
74 | 108 | # Create the input form |
— | — | @@ -82,11 +116,20 @@ |
83 | 117 | Xml::closeElement( 'form' ) |
84 | 118 | ); |
85 | 119 | |
| 120 | + if( $this->file ) { |
| 121 | + $this->hash = $this->file->getSha1(); |
| 122 | + } else { |
| 123 | + $wgOut->wrapWikiMsg( |
| 124 | + "<p class='mw-fileduplicatesearch-noresults'>\n$1\n</p>", |
| 125 | + array( 'fileduplicatesearch-noresults', wfEscapeWikiText( $this->filename ) ) |
| 126 | + ); |
| 127 | + } |
| 128 | + |
86 | 129 | if( $this->hash != '' ) { |
87 | 130 | $align = $wgContLang->alignEnd(); |
88 | 131 | |
89 | 132 | # Show a thumbnail of the file |
90 | | - $img = wfFindFile( $title ); |
| 133 | + $img = $this->file; |
91 | 134 | if ( $img ) { |
92 | 135 | $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) ); |
93 | 136 | if( $thumb ) { |
— | — | @@ -102,36 +145,46 @@ |
103 | 146 | } |
104 | 147 | } |
105 | 148 | |
106 | | - parent::execute( $par ); |
| 149 | + $dupes = $this->getDupes(); |
| 150 | + $numRows = count( $dupes ); |
107 | 151 | |
108 | 152 | # Show a short summary |
109 | | - if( $this->numRows == 1 ) { |
| 153 | + if( $numRows == 1 ) { |
110 | 154 | $wgOut->wrapWikiMsg( |
111 | 155 | "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>", |
112 | | - array( 'fileduplicatesearch-result-1', $this->filename ) |
| 156 | + array( 'fileduplicatesearch-result-1', wfEscapeWikiText( $this->filename ) ) |
113 | 157 | ); |
114 | | - } elseif ( $this->numRows > 1 ) { |
| 158 | + } elseif ( $numRows ) { |
115 | 159 | $wgOut->wrapWikiMsg( |
116 | 160 | "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>", |
117 | | - array( 'fileduplicatesearch-result-n', $this->filename, |
118 | | - $wgLang->formatNum( $this->numRows - 1 ) ) |
| 161 | + array( 'fileduplicatesearch-result-n', wfEscapeWikiText( $this->filename ), |
| 162 | + $wgLang->formatNum( $numRows - 1 ) ) |
119 | 163 | ); |
120 | 164 | } |
| 165 | + |
| 166 | + $this->showList( $dupes ); |
121 | 167 | } |
122 | 168 | } |
123 | 169 | |
| 170 | + /** |
| 171 | + * |
| 172 | + * @param Skin $skin |
| 173 | + * @param File $result |
| 174 | + * @return string |
| 175 | + */ |
124 | 176 | function formatResult( $skin, $result ) { |
125 | 177 | global $wgContLang, $wgLang; |
126 | 178 | |
127 | | - $nt = Title::makeTitle( NS_FILE, $result->title ); |
| 179 | + $nt = $result->getTitle(); |
128 | 180 | $text = $wgContLang->convert( $nt->getText() ); |
129 | 181 | $plink = $skin->link( |
130 | 182 | Title::newFromText( $nt->getPrefixedText() ), |
131 | 183 | $text |
132 | 184 | ); |
133 | 185 | |
134 | | - $user = $skin->link( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text ); |
135 | | - $time = $wgLang->timeanddate( $result->img_timestamp ); |
| 186 | + $userText = $result->getUser( 'text' ); |
| 187 | + $user = $skin->link( Title::makeTitle( NS_USER, $userText ), $userText ); |
| 188 | + $time = $wgLang->timeanddate( $result->getTimestamp() ); |
136 | 189 | |
137 | 190 | return "$plink . . $user . . $time"; |
138 | 191 | } |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -4318,15 +4318,14 @@ |
4319 | 4319 | |
4320 | 4320 | # Special:FileDuplicateSearch |
4321 | 4321 | 'fileduplicatesearch' => 'Search for duplicate files', |
4322 | | -'fileduplicatesearch-summary' => 'Search for duplicate files based on hash values. |
4323 | | - |
4324 | | -Enter the filename without the "{{ns:file}}:" prefix.', |
| 4322 | +'fileduplicatesearch-summary' => 'Search for duplicate files based on hash values.', |
4325 | 4323 | 'fileduplicatesearch-legend' => 'Search for a duplicate', |
4326 | 4324 | 'fileduplicatesearch-filename' => 'Filename:', |
4327 | 4325 | 'fileduplicatesearch-submit' => 'Search', |
4328 | 4326 | 'fileduplicatesearch-info' => '$1 × $2 pixel<br />File size: $3<br />MIME type: $4', |
4329 | 4327 | 'fileduplicatesearch-result-1' => 'The file "$1" has no identical duplication.', |
4330 | 4328 | 'fileduplicatesearch-result-n' => 'The file "$1" has {{PLURAL:$2|1 identical duplication|$2 identical duplications}}.', |
| 4329 | +'fileduplicatesearch-noresults' => 'No file named "$1" found.', |
4331 | 4330 | |
4332 | 4331 | # Special:SpecialPages |
4333 | 4332 | 'specialpages' => 'Special pages', |