15use Wikimedia\Timestamp\TimestampFormat as TS;
31 parent::__construct( $query, $moduleName,
'df' );
32 $this->repoGroup = $repoGroup;
46 $this->run( $resultPageSet );
52 private function run( $resultPageSet =
null ) {
54 $namespaces = $this->
getPageSet()->getGoodAndMissingTitlesByNamespace();
55 if ( empty( $namespaces[
NS_FILE] ) ) {
60 if ( $params[
'dir'] ==
'descending' ) {
61 $images = array_reverse( $images );
64 $skipUntilThisDup =
false;
65 if ( isset( $params[
'continue'] ) ) {
67 $fromImage = $cont[0];
68 $skipUntilThisDup = $cont[1];
70 foreach ( $images as $image => $pageId ) {
71 if ( $image < $fromImage ) {
72 unset( $images[$image] );
79 $filesToFind = array_keys( $images );
80 if ( $params[
'localonly'] ) {
81 $files = $this->repoGroup->getLocalRepo()->findFiles( $filesToFind );
83 $files = $this->repoGroup->findFiles( $filesToFind );
91 foreach ( $files as $file ) {
93 $sha1s[$file->getName()] = $file->getSha1();
98 $filesToFindBySha1s = array_unique( array_values( $sha1s ) );
99 if ( $params[
'localonly'] ) {
100 $filesBySha1s = $this->repoGroup->getLocalRepo()->findBySha1s( $filesToFindBySha1s );
102 $filesBySha1s = $this->repoGroup->findBySha1s( $filesToFindBySha1s );
106 foreach ( $images as $image => $pageId ) {
107 if ( !isset( $sha1s[$image] ) ) {
110 $sha1 = $sha1s[$image];
111 $dupFiles = $filesBySha1s[$sha1];
112 if ( $params[
'dir'] ==
'descending' ) {
113 $dupFiles = array_reverse( $dupFiles );
116 foreach ( $dupFiles as $dupFile ) {
117 $dupName = $dupFile->getName();
118 if ( $image == $dupName && $dupFile->isLocal() ) {
121 if ( $skipUntilThisDup !==
false && $dupName < $skipUntilThisDup ) {
124 $skipUntilThisDup =
false;
125 if ( ++$count > $params[
'limit'] ) {
132 if ( $resultPageSet !==
null ) {
133 $titles[] = $dupFile->getTitle();
137 'timestamp' =>
wfTimestamp( TS::ISO_8601, $dupFile->getTimestamp() ),
138 'shared' => !$dupFile->isLocal(),
140 $uploader = $dupFile->getUploader( File::FOR_PUBLIC );
142 $r[
'user'] = $uploader->getName();
155 if ( $resultPageSet !==
null ) {
156 $resultPageSet->populateFromTitles( $titles );
164 ParamValidator::PARAM_DEFAULT => 10,
165 ParamValidator::PARAM_TYPE =>
'limit',
166 IntegerDef::PARAM_MIN => 1,
174 ParamValidator::PARAM_DEFAULT =>
'ascending',
175 ParamValidator::PARAM_TYPE => [
180 'localonly' =>
false,
187 'action=query&titles=File:Albert_Einstein_Head.jpg&prop=duplicatefiles'
188 =>
'apihelp-query+duplicatefiles-example-simple',
189 'action=query&generator=allimages&prop=duplicatefiles'
190 =>
'apihelp-query+duplicatefiles-example-generated',
196 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Duplicatefiles';
201class_alias( ApiQueryDuplicateFiles::class,
'ApiQueryDuplicateFiles' );
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.