Merge "(bug 43207) Fix regression in API generator=duplicatefiles"
[lhc/web/wiklou.git] / includes / api / ApiQueryFilearchive.php
index eed9d7c..7ec47fa 100644 (file)
@@ -59,11 +59,12 @@ class ApiQueryFilearchive extends ApiQueryBase {
                $fld_mediatype = isset( $prop['mediatype'] );
                $fld_metadata = isset( $prop['metadata'] );
                $fld_bitdepth = isset( $prop['bitdepth'] );
+               $fld_archivename = isset( $prop['archivename'] );
 
                $this->addTables( 'filearchive' );
 
                $this->addFields( array( 'fa_name', 'fa_deleted' ) );
-               $this->addFieldsIf( 'fa_storage_key', $fld_sha1 );
+               $this->addFieldsIf( 'fa_sha1', $fld_sha1 );
                $this->addFieldsIf( 'fa_timestamp', $fld_timestamp );
                $this->addFieldsIf( array( 'fa_user', 'fa_user_text' ), $fld_user );
                $this->addFieldsIf( array( 'fa_height', 'fa_width', 'fa_size' ), $fld_dimensions || $fld_size );
@@ -72,6 +73,7 @@ class ApiQueryFilearchive extends ApiQueryBase {
                $this->addFieldsIf( 'fa_media_type', $fld_mediatype );
                $this->addFieldsIf( 'fa_metadata', $fld_metadata );
                $this->addFieldsIf( 'fa_bits', $fld_bitdepth );
+               $this->addFieldsIf( 'fa_archive_name', $fld_archivename );
 
                if ( !is_null( $params['continue'] ) ) {
                        $cont = explode( '|', $params['continue'] );
@@ -99,25 +101,21 @@ class ApiQueryFilearchive extends ApiQueryBase {
                $sha1Set = isset( $params['sha1'] );
                $sha1base36Set = isset( $params['sha1base36'] );
                if ( $sha1Set || $sha1base36Set ) {
-                       global $wgMiserMode;
-                       if ( $wgMiserMode  ) {
-                               $this->dieUsage( 'Search by hash disabled in Miser Mode', 'hashsearchdisabled' );
-                       }
-
                        $sha1 = false;
                        if ( $sha1Set ) {
-                               if ( !$this->validateSha1Hash( $params['sha1'] ) ) {
+                               $sha1 = strtolower( $params['sha1'] );
+                               if ( !$this->validateSha1Hash( $sha1 ) ) {
                                        $this->dieUsage( 'The SHA1 hash provided is not valid', 'invalidsha1hash' );
                                }
-                               $sha1 = wfBaseConvert( $params['sha1'], 16, 36, 31 );
+                               $sha1 = wfBaseConvert( $sha1, 16, 36, 31 );
                        } elseif ( $sha1base36Set ) {
-                               if ( !$this->validateSha1Base36Hash( $params['sha1base36'] ) ) {
+                               $sha1 = strtolower( $params['sha1base36'] );
+                               if ( !$this->validateSha1Base36Hash( $sha1 ) ) {
                                        $this->dieUsage( 'The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash' );
                                }
-                               $sha1 = $params['sha1base36'];
                        }
                        if ( $sha1 ) {
-                               $this->addWhere( 'fa_storage_key ' . $db->buildLike( "{$sha1}.", $db->anyString() ) );
+                               $this->addWhereFld( 'fa_sha1', $sha1 );
                        }
                }
 
@@ -153,7 +151,7 @@ class ApiQueryFilearchive extends ApiQueryBase {
                        self::addTitleInfo( $file, $title );
 
                        if ( $fld_sha1 ) {
-                               $file['sha1'] = wfBaseConvert( LocalRepo::getHashFromKey( $row->fa_storage_key ), 36, 16, 40 );
+                               $file['sha1'] = wfBaseConvert( $row->fa_sha1, 36, 16, 40 );
                        }
                        if ( $fld_timestamp ) {
                                $file['timestamp'] = wfTimestamp( TS_ISO_8601, $row->fa_timestamp );
@@ -194,6 +192,9 @@ class ApiQueryFilearchive extends ApiQueryBase {
                        if ( $fld_mime ) {
                                $file['mime'] = "$row->fa_major_mime/$row->fa_minor_mime";
                        }
+                       if ( $fld_archivename && !is_null( $row->fa_archive_name ) ) {
+                               $file['archivename'] = $row->fa_archive_name;
+                       }
 
                        if ( $row->fa_deleted & File::DELETED_FILE ) {
                                $file['filehidden'] = '';
@@ -256,7 +257,8 @@ class ApiQueryFilearchive extends ApiQueryBase {
                                        'mime',
                                        'mediatype',
                                        'metadata',
-                                       'bitdepth'
+                                       'bitdepth',
+                                       'archivename',
                                ),
                        ),
                );
@@ -270,8 +272,8 @@ class ApiQueryFilearchive extends ApiQueryBase {
                        'prefix' => 'Search for all image titles that begin with this value',
                        'dir' => 'The direction in which to list',
                        'limit' => 'How many images to return in total',
-                       'sha1' => "SHA1 hash of image. Overrides {$this->getModulePrefix()}sha1base36. Disabled in Miser Mode",
-                       'sha1base36' => 'SHA1 hash of image in base 36 (used in MediaWiki). Disabled in Miser Mode',
+                       'sha1' => "SHA1 hash of image. Overrides {$this->getModulePrefix()}sha1base36",
+                       'sha1base36' => 'SHA1 hash of image in base 36 (used in MediaWiki)',
                        'prop' => array(
                                'What image information to get:',
                                ' sha1              - Adds SHA-1 hash for the image',
@@ -285,6 +287,7 @@ class ApiQueryFilearchive extends ApiQueryBase {
                                ' mediatype         - Adds the media type of the image',
                                ' metadata          - Lists EXIF metadata for the version of the image',
                                ' bitdepth          - Adds the bit depth of the version',
+                               ' archivename       - Adds the file name of the archive version for non-latest versions'
                        ),
                );
        }
@@ -346,7 +349,10 @@ class ApiQueryFilearchive extends ApiQueryBase {
                        ),
                        'mediatype' => array(
                                'mediatype' => 'string'
-                       )
+                       ),
+                       'archivename' => array(
+                               'archivename' => 'string'
+                       ),
                );
        }