15use Wikimedia\Timestamp\TimestampFormat as TS;
29 parent::__construct( $query, $moduleName,
'df' );
43 $this->run( $resultPageSet );
49 private function run( $resultPageSet =
null ) {
51 $namespaces = $this->
getPageSet()->getGoodAndMissingTitlesByNamespace();
52 if ( empty( $namespaces[
NS_FILE] ) ) {
57 if ( $params[
'dir'] ==
'descending' ) {
58 $images = array_reverse( $images );
61 $skipUntilThisDup =
false;
62 if ( isset( $params[
'continue'] ) ) {
64 $fromImage = $cont[0];
65 $skipUntilThisDup = $cont[1];
67 foreach ( $images as $image => $pageId ) {
68 if ( $image < $fromImage ) {
69 unset( $images[$image] );
76 $filesToFind = array_keys( $images );
77 if ( $params[
'localonly'] ) {
78 $files = $this->repoGroup->getLocalRepo()->findFiles( $filesToFind );
80 $files = $this->repoGroup->findFiles( $filesToFind );
88 foreach ( $files as $file ) {
90 $sha1s[$file->getName()] = $file->getSha1();
95 $filesToFindBySha1s = array_unique( array_values( $sha1s ) );
96 if ( $params[
'localonly'] ) {
97 $filesBySha1s = $this->repoGroup->getLocalRepo()->findBySha1s( $filesToFindBySha1s );
99 $filesBySha1s = $this->repoGroup->findBySha1s( $filesToFindBySha1s );
103 foreach ( $images as $image => $pageId ) {
104 if ( !isset( $sha1s[$image] ) ) {
107 $sha1 = $sha1s[$image];
108 $dupFiles = $filesBySha1s[$sha1];
109 if ( $params[
'dir'] ==
'descending' ) {
110 $dupFiles = array_reverse( $dupFiles );
113 foreach ( $dupFiles as $dupFile ) {
114 $dupName = $dupFile->getName();
115 if ( $image == $dupName && $dupFile->isLocal() ) {
118 if ( $skipUntilThisDup !==
false && $dupName < $skipUntilThisDup ) {
121 $skipUntilThisDup =
false;
122 if ( ++$count > $params[
'limit'] ) {
129 if ( $resultPageSet !==
null ) {
130 $titles[] = $dupFile->getTitle();
134 'timestamp' =>
wfTimestamp( TS::ISO_8601, $dupFile->getTimestamp() ),
135 'shared' => !$dupFile->isLocal(),
137 $uploader = $dupFile->getUploader( File::FOR_PUBLIC );
139 $r[
'user'] = $uploader->getName();
152 if ( $resultPageSet !==
null ) {
153 $resultPageSet->populateFromTitles( $titles );
161 ParamValidator::PARAM_DEFAULT => 10,
162 ParamValidator::PARAM_TYPE =>
'limit',
163 IntegerDef::PARAM_MIN => 1,
171 ParamValidator::PARAM_DEFAULT =>
'ascending',
172 ParamValidator::PARAM_TYPE => [
177 'localonly' =>
false,
184 'action=query&titles=File:Albert_Einstein_Head.jpg&prop=duplicatefiles'
185 =>
'apihelp-query+duplicatefiles-example-simple',
186 'action=query&generator=allimages&prop=duplicatefiles'
187 =>
'apihelp-query+duplicatefiles-example-generated',
193 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Duplicatefiles';
198class_alias( ApiQueryDuplicateFiles::class,
'ApiQueryDuplicateFiles' );
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.