Index: trunk/extensions/CodeReview/backend/CodeRevision.php |
— | — | @@ -670,6 +670,13 @@ |
671 | 671 | $dbw->insert( 'code_signoffs', $rows, __METHOD__, array( 'IGNORE' ) ); |
672 | 672 | } |
673 | 673 | |
| 674 | + /** |
| 675 | + * Strike a set of sign-offs by a given user. Any sign-offs in $ids not |
| 676 | + * by $user are silently ignored, as well as nonexistent IDs and |
| 677 | + * already-struck sign-offs. |
| 678 | + * @param $user User object |
| 679 | + * @param $ids array of sign-off IDs to strike |
| 680 | + */ |
674 | 681 | public function strikeSignoffs( $user, $ids ) { |
675 | 682 | foreach ( $ids as $id ) { |
676 | 683 | $signoff = CodeSignoff::newFromId( $this, $id ); |
Index: trunk/extensions/CodeReview/backend/CodeSignoff.php |
— | — | @@ -1,8 +1,36 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * Class representing a sign-off. A sign-off in this context is the record of a |
| 5 | + * certain user having signed off on a certain revision with a certain flag. |
| 6 | + * Signing off with multiple flags at once creates multiple sign-offs. |
| 7 | + */ |
3 | 8 | class CodeSignoff { |
4 | | - public $rev, $user, $flag, $timestamp, $userText; |
| 9 | + /** CodeRevision object for the revision that was signed off on */ |
| 10 | + public $rev; |
| 11 | + /** User ID (on the wiki, not in SVN) of the user that signed off */ |
| 12 | + public $user; |
| 13 | + /** User name of the user that signed off */ |
| 14 | + public $userText; |
| 15 | + /** Sign-off flag. See CodeRevision::getPossibleFlags() for possible values */ |
| 16 | + public $flag; |
| 17 | + /** Timestamp of the sign-off, in TS_MW format */ |
| 18 | + public $timestamp; |
| 19 | + |
5 | 20 | private $timestampStruck; |
6 | 21 | |
| 22 | + /** |
| 23 | + * This constructor is only used by newFrom*(). You should not create your own |
| 24 | + * CodeSignoff objects, they'll be useless if they don't correspond to existing entires |
| 25 | + * in the database. |
| 26 | + * |
| 27 | + * For more detailed explanations of what each of the parameters mean, see public members. |
| 28 | + * @param $rev CodeRevision object |
| 29 | + * @param $user int User ID |
| 30 | + * @param $userText string User name |
| 31 | + * @param $flag string Flag |
| 32 | + * @param $timestamp string TS_MW timestamp |
| 33 | + * @param $timestampStruck string Raw (unformatted!) timestamp from the cs_timestamp_struck DB field |
| 34 | + */ |
7 | 35 | public function __construct( $rev, $user, $userText, $flag, $timestamp, $timestampStruck ) { |
8 | 36 | $this->rev = $rev; |
9 | 37 | $this->user = $user; |
— | — | @@ -12,14 +40,23 @@ |
13 | 41 | $this->timestampStruck = $timestampStruck; |
14 | 42 | } |
15 | 43 | |
| 44 | + /** |
| 45 | + * @return bool Whether this sign-off has been struck |
| 46 | + */ |
16 | 47 | public function isStruck() { |
17 | 48 | return $this->timestampStruck !== Block::infinity(); |
18 | 49 | } |
19 | 50 | |
| 51 | + /** |
| 52 | + * @return mixed Timestamp (TS_MW format) the revision was struck at, or false if it hasn't been struck |
| 53 | + */ |
20 | 54 | public function getTimestampStruck() { |
21 | | - return wfTimestamp( TS_MW, $this->timestampStruck ); |
| 55 | + return $this->isStruck() ? wfTimestamp( TS_MW, $this->timestampStruck ) : false; |
22 | 56 | } |
23 | 57 | |
| 58 | + /** |
| 59 | + * Strike this sign-off. Attempts to strike an already-struck signoff will be silently ignored. |
| 60 | + */ |
24 | 61 | public function strike() { |
25 | 62 | if ( $this->isStruck() ) { |
26 | 63 | return; |
— | — | @@ -36,20 +73,46 @@ |
37 | 74 | ); |
38 | 75 | } |
39 | 76 | |
| 77 | + /** |
| 78 | + * Get the ID of this signoff. This is not a numerical ID that exists in the database, |
| 79 | + * but a representation that you can use in URLs and the like. It's also not unique: |
| 80 | + * only the combination of a signoff ID and a revision is unique. You can obtain |
| 81 | + * a CodeSignoff object from its ID and its revision with newFromID(). |
| 82 | + * |
| 83 | + * @return string ID |
| 84 | + */ |
40 | 85 | public function getID() { |
41 | 86 | return implode( '|', array( $this->flag, $this->timestampStruck, $this->userText ) ); |
42 | 87 | } |
43 | 88 | |
| 89 | + /** |
| 90 | + * Create a CodeSignoff object from a revision and a database row object |
| 91 | + * @param $rev CodeRevision object the signoff belongs to |
| 92 | + * @param $row object Database row with cs_* fields from code_signoffs |
| 93 | + * @return CodeSignoff |
| 94 | + */ |
44 | 95 | public static function newFromRow( $rev, $row ) { |
45 | 96 | return self::newFromData( $rev, get_object_vars( $row ) ); |
46 | 97 | } |
47 | 98 | |
| 99 | + /** |
| 100 | + * Create a CodeSignoff object from a revision and a database row in array format |
| 101 | + * @param $rev CodeRevision object the signoff belongs to |
| 102 | + * @param $row array Database row with cs_* fields from code_signoffs |
| 103 | + * @return CodeSignoff |
| 104 | + */ |
48 | 105 | public static function newFromData( $rev, $data ) { |
49 | 106 | return new self( $rev, $data['cs_user'], $data['cs_user_text'], $data['cs_flag'], |
50 | 107 | wfTimestamp( TS_MW, $data['cs_timestamp'] ), $data['cs_timestamp_struck'] |
51 | 108 | ); |
52 | 109 | } |
53 | 110 | |
| 111 | + /** |
| 112 | + * Create a CodeSignoff object from a revision object and an ID previously obtained from getID() |
| 113 | + * @param $rev CodeRevision object |
| 114 | + * @param $id string ID generated by getID() |
| 115 | + * @return CodeSignoff |
| 116 | + */ |
54 | 117 | public static function newFromID( $rev, $id ) { |
55 | 118 | $parts = explode( '|', $id, 3 ); |
56 | 119 | if ( count( $parts ) != 3 ) { |