r83399 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83398‎ | r83399 | r83400 >
Date:20:05, 6 March 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
* (bug 27588) list=filearchive&faprop=sha1 returns empty attribute

Refactored code out, to be reused in ApiQueryFilearchive

Simplified too per Bryan on IRC
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryFilearchive.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalRepo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/LocalRepo.php
@@ -52,8 +52,8 @@
5353 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
5454 __METHOD__, array( 'FOR UPDATE' ) );
5555 if( !$inuse ) {
56 - $sha1 = substr( $key, 0, strcspn( $key, '.' ) );
57 - $ext = substr( $key, strcspn($key,'.') + 1 );
 56+ $sha1 = self::getHashFromKey( $key );
 57+ $ext = substr( $key, strcspn( $key, '.' ) + 1 );
5858 $ext = File::normalizeExtension($ext);
5959 $inuse = $dbw->selectField( 'oldimage', '1',
6060 array( 'oi_sha1' => $sha1,
@@ -75,6 +75,17 @@
7676 }
7777 return $status;
7878 }
 79+
 80+ /**
 81+ * Gets the SHA1 hash from a storage key
 82+ *
 83+ * @static
 84+ * @param string $key
 85+ * @return string
 86+ */
 87+ public static function getHashFromKey( $key ) {
 88+ return strtok( $key, '.' );
 89+ }
7990
8091 /**
8192 * Checks if there is a redirect named as $title
Index: trunk/phase3/includes/api/ApiQueryFilearchive.php
@@ -135,7 +135,7 @@
136136 self::addTitleInfo( $file, Title::makeTitle( NS_FILE, $row->fa_name ) );
137137
138138 if ( $fld_sha1 ) {
139 - $file['sha1'] = wfBaseConvert( $row->fa_storage_key, 36, 16, 40 );
 139+ $file['sha1'] = LocalRepo::getHashFromKey( $row->fa_storage_key );
140140 }
141141 if ( $fld_timestamp ) {
142142 $file['timestamp'] = wfTimestamp( TS_ISO_8601, $row->fa_timestamp );
Index: trunk/phase3/RELEASE-NOTES
@@ -217,6 +217,7 @@
218218 * (bug 27018) Added action=filerevert to revert files to an old version
219219 * (bug 27897) list=allusers and list=users list hidden users
220220 * (bug 27717) API's exturlusage module does not respect $wgMiserMode
 221+* (bug 27588) list=filearchive&faprop=sha1 returns empty attribute
221222
222223 === Languages updated in 1.18 ===
223224

Follow-up revisions

RevisionCommit summaryAuthorDate
r83401Followup r83399, add back base conversionreedy20:20, 6 March 2011

Comments

#Comment by Duplicatebug (talk | contribs)   20:18, 6 March 2011

In my opinion the wfBaseConvert is needed, because MediaWiki stored sha1base36, but you want output sha1.

#Comment by Bryan (talk | contribs)   20:25, 6 March 2011

I guess I missed on IRC that getHashFromKey() would be a method of LocalRepo. Perhaps it's to generic for that.

Note that to get the extension you can do strtok( ), but then you need to assume in the caller that you know that getHashFromKey() uses strtok... Hm...

-				$file['sha1'] = wfBaseConvert( $row->fa_storage_key, 36, 16, 40 );
+				$file['sha1'] = LocalRepo::getHashFromKey( $row->fa_storage_key );

The wfBaseConvert got lost here.

Status & tagging log