diff options
Diffstat (limited to 'includes/api/ApiQueryDuplicateFiles.php')
-rw-r--r-- | includes/api/ApiQueryDuplicateFiles.php | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/includes/api/ApiQueryDuplicateFiles.php b/includes/api/ApiQueryDuplicateFiles.php index 8f0fd3be..0311fa7f 100644 --- a/includes/api/ApiQueryDuplicateFiles.php +++ b/includes/api/ApiQueryDuplicateFiles.php @@ -48,8 +48,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { } /** - * @param $resultPageSet ApiPageSet - * @return + * @param ApiPageSet $resultPageSet */ private function run( $resultPageSet = null ) { $params = $this->extractRequestParams(); @@ -59,17 +58,14 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { } $images = $namespaces[NS_FILE]; - if( $params['dir'] == 'descending' ) { + if ( $params['dir'] == 'descending' ) { $images = array_reverse( $images ); } $skipUntilThisDup = false; if ( isset( $params['continue'] ) ) { $cont = explode( '|', $params['continue'] ); - if ( count( $cont ) != 2 ) { - $this->dieUsage( 'Invalid continue param. You should pass the ' . - 'original value returned by the previous query', '_badcontinue' ); - } + $this->dieContinueUsageIf( count( $cont ) != 2 ); $fromImage = $cont[0]; $skipUntilThisDup = $cont[1]; // Filter out any images before $fromImage @@ -83,7 +79,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { } $filesToFind = array_keys( $images ); - if( $params['localonly'] ) { + if ( $params['localonly'] ) { $files = RepoGroup::singleton()->getLocalRepo()->findFiles( $filesToFind ); } else { $files = RepoGroup::singleton()->findFiles( $filesToFind ); @@ -95,33 +91,35 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { $sha1s = array(); foreach ( $files as $file ) { + /** @var $file File */ $sha1s[$file->getName()] = $file->getSha1(); } // find all files with the hashes, result format is: array( hash => array( dup1, dup2 ), hash1 => ... ) $filesToFindBySha1s = array_unique( array_values( $sha1s ) ); - if( $params['localonly'] ) { + if ( $params['localonly'] ) { $filesBySha1s = RepoGroup::singleton()->getLocalRepo()->findBySha1s( $filesToFindBySha1s ); } else { $filesBySha1s = RepoGroup::singleton()->findBySha1s( $filesToFindBySha1s ); } // iterate over $images to handle continue param correct - foreach( $images as $image => $pageId ) { - if( !isset( $sha1s[$image] ) ) { + foreach ( $images as $image => $pageId ) { + if ( !isset( $sha1s[$image] ) ) { continue; //file does not exist } $sha1 = $sha1s[$image]; $dupFiles = $filesBySha1s[$sha1]; - if( $params['dir'] == 'descending' ) { + if ( $params['dir'] == 'descending' ) { $dupFiles = array_reverse( $dupFiles ); } + /** @var $dupFile File */ foreach ( $dupFiles as $dupFile ) { $dupName = $dupFile->getName(); - if( $image == $dupName && $dupFile->isLocal() ) { + if ( $image == $dupName && $dupFile->isLocal() ) { continue; //ignore the local file itself } - if( $skipUntilThisDup !== false && $dupName < $skipUntilThisDup ) { + if ( $skipUntilThisDup !== false && $dupName < $skipUntilThisDup ) { continue; //skip to pos after the image from continue param } $skipUntilThisDup = false; @@ -133,14 +131,14 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { break; } if ( !is_null( $resultPageSet ) ) { - $titles[] = $file->getTitle(); + $titles[] = $dupFile->getTitle(); } else { $r = array( 'name' => $dupName, 'user' => $dupFile->getUser( 'text' ), 'timestamp' => wfTimestamp( TS_ISO_8601, $dupFile->getTimestamp() ) ); - if( !$dupFile->isLocal() ) { + if ( !$dupFile->isLocal() ) { $r['shared'] = ''; } $fit = $this->addPageSubItem( $pageId, $r ); @@ -150,7 +148,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { } } } - if( !$fit ) { + if ( !$fit ) { break; } } @@ -204,12 +202,6 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { return 'List all files that are duplicates of the given file(s) based on hash values'; } - public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ), - ) ); - } - public function getExamples() { return array( 'api.php?action=query&titles=File:Albert_Einstein_Head.jpg&prop=duplicatefiles', @@ -220,8 +212,4 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { public function getHelpUrls() { return 'https://www.mediawiki.org/wiki/API:Properties#duplicatefiles_.2F_df'; } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } } |