Index: trunk/extensions/CodeReview/backend/CodeSignoff.php |
— | — | @@ -15,9 +15,9 @@ |
16 | 16 | public $flag; |
17 | 17 | /** Timestamp of the sign-off, in TS_MW format */ |
18 | 18 | public $timestamp; |
19 | | - |
| 19 | + |
20 | 20 | private $timestampStruck; |
21 | | - |
| 21 | + |
22 | 22 | /** |
23 | 23 | * This constructor is only used by newFrom*(). You should not create your own |
24 | 24 | * CodeSignoff objects, they'll be useless if they don't correspond to existing entries |
— | — | @@ -39,21 +39,21 @@ |
40 | 40 | $this->timestamp = $timestamp; |
41 | 41 | $this->timestampStruck = $timestampStruck; |
42 | 42 | } |
43 | | - |
| 43 | + |
44 | 44 | /** |
45 | 45 | * @return bool Whether this sign-off has been struck |
46 | 46 | */ |
47 | 47 | public function isStruck() { |
48 | 48 | return $this->timestampStruck !== Block::infinity(); |
49 | 49 | } |
50 | | - |
| 50 | + |
51 | 51 | /** |
52 | 52 | * @return mixed Timestamp (TS_MW format) the revision was struck at, or false if it hasn't been struck |
53 | 53 | */ |
54 | 54 | public function getTimestampStruck() { |
55 | 55 | return $this->isStruck() ? wfTimestamp( TS_MW, $this->timestampStruck ) : false; |
56 | 56 | } |
57 | | - |
| 57 | + |
58 | 58 | /** |
59 | 59 | * Strike this sign-off. Attempts to strike an already-struck signoff will be silently ignored. |
60 | 60 | */ |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | ), __METHOD__ |
74 | 74 | ); |
75 | 75 | } |
76 | | - |
| 76 | + |
77 | 77 | /** |
78 | 78 | * Get the ID of this signoff. This is not a numerical ID that exists in the database, |
79 | 79 | * but a representation that you can use in URLs and the like. It's also not unique: |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | public function getID() { |
86 | 86 | return implode( '|', array( $this->flag, $this->timestampStruck, $this->userText ) ); |
87 | 87 | } |
88 | | - |
| 88 | + |
89 | 89 | /** |
90 | 90 | * Create a CodeSignoff object from a revision and a database row object |
91 | 91 | * @param $rev CodeRevision object the signoff belongs to |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | public static function newFromRow( $rev, $row ) { |
96 | 96 | return self::newFromData( $rev, get_object_vars( $row ) ); |
97 | 97 | } |
98 | | - |
| 98 | + |
99 | 99 | /** |
100 | 100 | * Create a CodeSignoff object from a revision and a database row in array format |
101 | 101 | * @param $rev CodeRevision object the signoff belongs to |
— | — | @@ -106,7 +106,7 @@ |
107 | 107 | wfTimestamp( TS_MW, $data['cs_timestamp'] ), $data['cs_timestamp_struck'] |
108 | 108 | ); |
109 | 109 | } |
110 | | - |
| 110 | + |
111 | 111 | /** |
112 | 112 | * Create a CodeSignoff object from a revision object and an ID previously obtained from getID() |
113 | 113 | * @param $rev CodeRevision object |
Index: trunk/extensions/CodeReview/ui/CodeRevisionView.php |
— | — | @@ -480,7 +480,7 @@ |
481 | 481 | $header .= '<th>' . wfMsgHtml( 'code-signoff-field-user' ) . '</th>'; |
482 | 482 | $header .= '<th>' . wfMsgHtml( 'code-signoff-field-flag' ). '</th>'; |
483 | 483 | $header .= '<th>' . wfMsgHtml( 'code-signoff-field-date' ). '</th>'; |
484 | | - $buttonrow = $showButtons ? $this->signoffButtons() : ''; |
| 484 | + $buttonrow = $showButtons ? $this->signoffButtons( $signOffs ) : ''; |
485 | 485 | return "<table border='1' class='TablePager'><tr>$header</tr>$signoffs$buttonrow</table>"; |
486 | 486 | } |
487 | 487 | |
— | — | @@ -732,26 +732,48 @@ |
733 | 733 | '</div>'; |
734 | 734 | } |
735 | 735 | |
736 | | - // TODO : checkboxes should be disabled if user already has set the flag |
737 | 736 | /** |
738 | 737 | * Render the bottom row of the sign-offs table containing the buttons to |
739 | 738 | * strike and submit sign-offs |
740 | 739 | * @return string HTML |
741 | 740 | */ |
742 | | - protected function signoffButtons() { |
| 741 | + protected function signoffButtons( $signOffs ) { |
| 742 | + $userSignOffs = $this->getUserSignoffs( $signOffs ); |
743 | 743 | $strikeButton = Xml::submitButton( wfMsg( 'code-signoff-strike' ), array( 'name' => 'wpStrikeSignoffs' ) ); |
744 | 744 | $signoffText = wfMsgHtml( 'code-signoff-signoff' ); |
745 | 745 | $signoffButton = Xml::submitButton( wfMsg( 'code-signoff-submit' ), array( 'name' => 'wpSignoff' ) ); |
746 | 746 | $checks = ''; |
| 747 | + |
747 | 748 | foreach ( CodeRevision::getPossibleFlags() as $flag ) { |
748 | | - $checks .= Html::input( 'wpSignoffFlags[]', $flag, 'checkbox', array( 'id' => "wpSignoffFlags-$flag" ) ) . |
| 749 | + $checks .= Html::input( 'wpSignoffFlags[]', $flag, 'checkbox', |
| 750 | + array( |
| 751 | + 'id' => "wpSignoffFlags-$flag", |
| 752 | + isset( $userSignOffs[$flag] ) ? 'disabled' : '' => '', |
| 753 | + ) ) . |
749 | 754 | ' ' . Xml::label( wfMsg( "code-signoff-flag-$flag" ), "wpSignoffFlags-$flag" ) . ' '; |
750 | 755 | } |
751 | 756 | return "<tr class='mw-codereview-signoffbuttons'><td colspan='4'>$strikeButton " . |
752 | 757 | "<div class='mw-codereview-signoffchecks'>$signoffText $checks $signoffButton</div></td></tr>"; |
753 | 758 | } |
754 | | - |
| 759 | + |
755 | 760 | /** |
| 761 | + * Gets all the current signoffs the user has against this revision |
| 762 | + * |
| 763 | + * @param Array $signOffs |
| 764 | + * @return Array |
| 765 | + */ |
| 766 | + protected function getUserSignoffs( $signOffs ) { |
| 767 | + $ret = array(); |
| 768 | + global $wgUser; |
| 769 | + foreach( $signOffs as $s ) { |
| 770 | + if ( $s->userText == $wgUser->getName() && !$s->isStruck() ) { |
| 771 | + $ret[$s->flag] = true; |
| 772 | + } |
| 773 | + } |
| 774 | + return $ret; |
| 775 | + } |
| 776 | + |
| 777 | + /** |
756 | 778 | * Render the bottom row of the follow-up revisions table containing the buttons and |
757 | 779 | * textbox to add and remove follow-up associations |
758 | 780 | * @return string HTML |