r106514 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106513‎ | r106514 | r106515 >
Date:18:27, 17 December 2011
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
Expose rev_sha1/ar_sha1 to API (bug 21860)
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryDeletedrevs.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -53,6 +53,7 @@
5454 $fld_parsedcomment = isset ( $prop['parsedcomment'] );
5555 $fld_minor = isset( $prop['minor'] );
5656 $fld_len = isset( $prop['len'] );
 57+ $fld_sha1 = isset( $prop['sha1'] );
5758 $fld_content = isset( $prop['content'] );
5859 $fld_token = isset( $prop['token'] );
5960
@@ -101,6 +102,7 @@
102103 $this->addFieldsIf( 'ar_comment', $fld_comment || $fld_parsedcomment );
103104 $this->addFieldsIf( 'ar_minor_edit', $fld_minor );
104105 $this->addFieldsIf( 'ar_len', $fld_len );
 106+ $this->addFieldsIf( 'ar_sha1', $fld_sha1 );
105107
106108 if ( $fld_content ) {
107109 $this->addTables( 'text' );
@@ -233,6 +235,9 @@
234236 if ( $fld_len ) {
235237 $rev['len'] = $row->ar_len;
236238 }
 239+ if ( $fld_sha1 ) {
 240+ $rev['sha1'] = $row->ar_sha1;
 241+ }
237242 if ( $fld_content ) {
238243 ApiResult::setContent( $rev, Revision::getRevisionText( $row ) );
239244 }
@@ -314,6 +319,7 @@
315320 'parsedcomment',
316321 'minor',
317322 'len',
 323+ 'sha1',
318324 'content',
319325 'token'
320326 ),
@@ -340,7 +346,8 @@
341347 ' comment - Adds the comment of the revision',
342348 ' parsedcomment - Adds the parsed comment of the revision',
343349 ' minor - Tags if the revision is minor',
344 - ' len - Adds the length of the revision',
 350+ ' len - Adds the length (bytes) of the revision',
 351+ ' sha1 - Adds the SHA-1 (base 36) of the revision',
345352 ' content - Adds the content of the revision',
346353 ' token - Gives the edit token',
347354 ),
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -154,6 +154,7 @@
155155 $this->fld_comment = isset ( $prop['comment'] );
156156 $this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
157157 $this->fld_size = isset ( $prop['size'] );
 158+ $this->fld_sha1 = isset ( $prop['sha1'] );
158159 $this->fld_userid = isset( $prop['userid'] );
159160 $this->fld_user = isset ( $prop['user'] );
160161 $this->token = $params['token'];
@@ -412,6 +413,14 @@
413414 }
414415 }
415416
 417+ if ( $this->fld_sha1 ) {
 418+ if ( !is_null( $revision->getSha1() ) ) {
 419+ $vals['sha1'] = $revision->getSha1();
 420+ } else {
 421+ $vals['sha1'] = '';
 422+ }
 423+ }
 424+
416425 if ( $this->fld_comment || $this->fld_parsedcomment ) {
417426 if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) {
418427 $vals['commenthidden'] = '';
@@ -537,6 +546,7 @@
538547 'user',
539548 'userid',
540549 'size',
 550+ 'sha1',
541551 'comment',
542552 'parsedcomment',
543553 'content',
@@ -599,7 +609,8 @@
600610 ' timestamp - The timestamp of the revision',
601611 ' user - User that made the revision',
602612 ' userid - User id of revision creator',
603 - ' size - Length of the revision',
 613+ ' size - Length (bytes) of the revision',
 614+ ' sha1 - SHA-1 (base 36) the revision',
604615 ' comment - Comment by the user for revision',
605616 ' parsedcomment - Parsed comment by the user for the revision',
606617 ' content - Text of the revision',

Follow-up revisions

RevisionCommit summaryAuthorDate
r106533Kill some useless code in r106514aaron23:14, 17 December 2011
r106570FU r106514: use base 16 SHA-1 to be consistent with image infoaaron16:35, 18 December 2011
r106867grammar :) followup r106514brion21:29, 20 December 2011
r106876FU r106514: Sanity check for empty sha1 values in the DBaaron21:58, 20 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101021Reinstated r94289 et all - rev_sha1/ar_sha1 field for bug 21860aaron18:44, 27 October 2011

Comments

#Comment by Duplicatebug (talk | contribs)   18:36, 17 December 2011

revision.sha1 is NOT NULL

#Comment by Catrope (talk | contribs)   11:43, 18 December 2011
+				$rev['sha1'] = $row->ar_sha1;

This outputs the SHA1 hash in base 36, matching your parameter documentation. However, imageinfo outputs it in hex:

			$vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 );

For consistency, we should use hex everywhere.

#Comment by Aaron Schulz (talk | contribs)   16:36, 18 December 2011

Ahh, so this how things like "len" vs "size" happen :)

#Comment by Brion VIBBER (talk | contribs)   21:30, 20 December 2011

What happens if there is no recorded sha1 hash? The documentation string doesn't indicate that it's optional or may be missing, or give an expectation of what a missing value would look like.

Status & tagging log