Expose rev_sha1/ar_sha1 to API (bug 21860)
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 17 Dec 2011 18:27:38 +0000 (18:27 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 17 Dec 2011 18:27:38 +0000 (18:27 +0000)
includes/api/ApiQueryDeletedrevs.php
includes/api/ApiQueryRevisions.php

index 43e871f..8f286ce 100644 (file)
@@ -53,6 +53,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                $fld_parsedcomment = isset ( $prop['parsedcomment'] );
                $fld_minor = isset( $prop['minor'] );
                $fld_len = isset( $prop['len'] );
+               $fld_sha1 = isset( $prop['sha1'] );
                $fld_content = isset( $prop['content'] );
                $fld_token = isset( $prop['token'] );
 
@@ -101,6 +102,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                $this->addFieldsIf( 'ar_comment', $fld_comment || $fld_parsedcomment );
                $this->addFieldsIf( 'ar_minor_edit', $fld_minor );
                $this->addFieldsIf( 'ar_len', $fld_len );
+               $this->addFieldsIf( 'ar_sha1', $fld_sha1 );
 
                if ( $fld_content ) {
                        $this->addTables( 'text' );
@@ -233,6 +235,9 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                        if ( $fld_len ) {
                                $rev['len'] = $row->ar_len;
                        }
+                       if ( $fld_sha1 ) {
+                               $rev['sha1'] = $row->ar_sha1;
+                       }
                        if ( $fld_content ) {
                                ApiResult::setContent( $rev, Revision::getRevisionText( $row ) );
                        }
@@ -314,6 +319,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                                        'parsedcomment',
                                        'minor',
                                        'len',
+                                       'sha1',
                                        'content',
                                        'token'
                                ),
@@ -340,7 +346,8 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                                ' comment        - Adds the comment of the revision',
                                ' parsedcomment  - Adds the parsed comment of the revision',
                                ' minor          - Tags if the revision is minor',
-                               ' len            - Adds the length of the revision',
+                               ' len            - Adds the length (bytes) of the revision',
+                               ' sha1           - Adds the SHA-1 (base 36) of the revision',
                                ' content        - Adds the content of the revision',
                                ' token          - Gives the edit token',
                        ),
index 7323d29..33ffaa1 100644 (file)
@@ -154,6 +154,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                $this->fld_comment = isset ( $prop['comment'] );
                $this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
                $this->fld_size = isset ( $prop['size'] );
+               $this->fld_sha1 = isset ( $prop['sha1'] );
                $this->fld_userid = isset( $prop['userid'] );
                $this->fld_user = isset ( $prop['user'] );
                $this->token = $params['token'];
@@ -412,6 +413,14 @@ class ApiQueryRevisions extends ApiQueryBase {
                        }
                }
 
+               if ( $this->fld_sha1 ) {
+                       if ( !is_null( $revision->getSha1() ) ) {
+                               $vals['sha1'] = $revision->getSha1();
+                       } else {
+                               $vals['sha1'] = '';
+                       }
+               }
+
                if ( $this->fld_comment || $this->fld_parsedcomment ) {
                        if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) {
                                $vals['commenthidden'] = '';
@@ -537,6 +546,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                                        'user',
                                        'userid',
                                        'size',
+                                       'sha1',
                                        'comment',
                                        'parsedcomment',
                                        'content',
@@ -599,7 +609,8 @@ class ApiQueryRevisions extends ApiQueryBase {
                                ' timestamp      - The timestamp of the revision',
                                ' user           - User that made the revision',
                                ' userid         - User id of revision creator',
-                               ' size           - Length of the revision',
+                               ' size           - Length (bytes) of the revision',
+                               ' sha1           - SHA-1 (base 36) the revision',
                                ' comment        - Comment by the user for revision',
                                ' parsedcomment  - Parsed comment by the user for the revision',
                                ' content        - Text of the revision',