From: Sam Reed Date: Sun, 6 Mar 2011 20:05:41 +0000 (+0000) Subject: * (bug 27588) list=filearchive&faprop=sha1 returns empty attribute X-Git-Tag: 1.31.0-rc.0~31597 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=56aefb445ffbbeccb2bd5c4074f17c7c26b10ec7;p=lhc%2Fweb%2Fwiklou.git * (bug 27588) list=filearchive&faprop=sha1 returns empty attribute Refactored code out, to be reused in ApiQueryFilearchive Simplified too per Bryan on IRC --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a90d0414ef..5bc50e1629 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -217,6 +217,7 @@ PHP if you have not done so prior to upgrading MediaWiki. * (bug 27018) Added action=filerevert to revert files to an old version * (bug 27897) list=allusers and list=users list hidden users * (bug 27717) API's exturlusage module does not respect $wgMiserMode +* (bug 27588) list=filearchive&faprop=sha1 returns empty attribute === Languages updated in 1.18 === diff --git a/includes/api/ApiQueryFilearchive.php b/includes/api/ApiQueryFilearchive.php index 914caed249..cef35c5d3f 100644 --- a/includes/api/ApiQueryFilearchive.php +++ b/includes/api/ApiQueryFilearchive.php @@ -135,7 +135,7 @@ class ApiQueryFilearchive extends ApiQueryBase { self::addTitleInfo( $file, Title::makeTitle( NS_FILE, $row->fa_name ) ); if ( $fld_sha1 ) { - $file['sha1'] = wfBaseConvert( $row->fa_storage_key, 36, 16, 40 ); + $file['sha1'] = LocalRepo::getHashFromKey( $row->fa_storage_key ); } if ( $fld_timestamp ) { $file['timestamp'] = wfTimestamp( TS_ISO_8601, $row->fa_timestamp ); diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index ab728ba78e..bbd99aaba2 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -52,8 +52,8 @@ class LocalRepo extends FSRepo { array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ), __METHOD__, array( 'FOR UPDATE' ) ); if( !$inuse ) { - $sha1 = substr( $key, 0, strcspn( $key, '.' ) ); - $ext = substr( $key, strcspn($key,'.') + 1 ); + $sha1 = self::getHashFromKey( $key ); + $ext = substr( $key, strcspn( $key, '.' ) + 1 ); $ext = File::normalizeExtension($ext); $inuse = $dbw->selectField( 'oldimage', '1', array( 'oi_sha1' => $sha1, @@ -75,6 +75,17 @@ class LocalRepo extends FSRepo { } return $status; } + + /** + * Gets the SHA1 hash from a storage key + * + * @static + * @param string $key + * @return string + */ + public static function getHashFromKey( $key ) { + return strtok( $key, '.' ); + } /** * Checks if there is a redirect named as $title