* (bug 27588) list=filearchive&faprop=sha1 returns empty attribute
authorSam Reed <reedy@users.mediawiki.org>
Sun, 6 Mar 2011 20:05:41 +0000 (20:05 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 6 Mar 2011 20:05:41 +0000 (20:05 +0000)
Refactored code out, to be reused in ApiQueryFilearchive

Simplified too per Bryan on IRC

RELEASE-NOTES
includes/api/ApiQueryFilearchive.php
includes/filerepo/LocalRepo.php

index a90d041..5bc50e1 100644 (file)
@@ -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 ===
 
index 914caed..cef35c5 100644 (file)
@@ -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 );
index ab728ba..bbd99aa 100644 (file)
@@ -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