raise timeout for CdbTest::testCdb()
[lhc/web/wiklou.git] / includes / api / ApiQueryDuplicateFiles.php
index 719c84a..3b04426 100644 (file)
@@ -66,10 +66,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
                $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
@@ -82,7 +79,12 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
                        }
                }
 
-               $files = RepoGroup::singleton()->findFiles( array_keys( $images ) );
+               $filesToFind = array_keys( $images );
+               if( $params['localonly'] ) {
+                       $files = RepoGroup::singleton()->getLocalRepo()->findFiles( $filesToFind );
+               } else {
+                       $files = RepoGroup::singleton()->findFiles( $filesToFind );
+               }
 
                $fit = true;
                $count = 0;
@@ -94,7 +96,12 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
                }
 
                // find all files with the hashes, result format is: array( hash => array( dup1, dup2 ), hash1 => ... )
-               $filesBySha1s = RepoGroup::singleton()->findBySha1s( array_unique( array_values( $sha1s ) ) );
+               $filesToFindBySha1s = array_unique( array_values( $sha1s ) );
+               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 ) {
@@ -108,8 +115,8 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
                        }
                        foreach ( $dupFiles as $dupFile ) {
                                $dupName = $dupFile->getName();
-                               if( $image == $dupName ) {
-                                       continue; //ignore the file itself
+                               if( $image == $dupName && $dupFile->isLocal() ) {
+                                       continue; //ignore the local file itself
                                }
                                if( $skipUntilThisDup !== false && $dupName < $skipUntilThisDup ) {
                                        continue; //skip to pos after the image from continue param
@@ -123,13 +130,16 @@ 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() ) {
+                                               $r['shared'] = '';
+                                       }
                                        $fit = $this->addPageSubItem( $pageId, $r );
                                        if ( !$fit ) {
                                                $this->setContinueEnumParameter( 'continue', $image . '|' . $dupName );
@@ -163,6 +173,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
                                        'descending'
                                )
                        ),
+                       'localonly' => false,
                );
        }
 
@@ -171,6 +182,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
                        'limit' => 'How many duplicate files to return',
                        'continue' => 'When more results are available, use this to continue',
                        'dir' => 'The direction in which to list',
+                       'localonly' => 'Look only for files in the local repository',
                );
        }
 
@@ -179,7 +191,8 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
                        '' => array(
                                'name' => 'string',
                                'user' => 'string',
-                               'timestamp' => 'timestamp'
+                               'timestamp' => 'timestamp',
+                               'shared' => 'boolean',
                        )
                );
        }
@@ -188,12 +201,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',
@@ -204,8 +211,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$';
-       }
 }