r83354 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83353‎ | r83354 | r83355 >
Date:01:54, 6 March 2011
Author:reedy
Status:ok
Tags:
Comment:
Fix a Roan left TODO

If user has a current valid (ie non struck) signoffs, disable the relevant checkbox
Modified paths:
  • /trunk/extensions/CodeReview/backend/CodeSignoff.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/backend/CodeSignoff.php
@@ -15,9 +15,9 @@
1616 public $flag;
1717 /** Timestamp of the sign-off, in TS_MW format */
1818 public $timestamp;
19 -
 19+
2020 private $timestampStruck;
21 -
 21+
2222 /**
2323 * This constructor is only used by newFrom*(). You should not create your own
2424 * CodeSignoff objects, they'll be useless if they don't correspond to existing entries
@@ -39,21 +39,21 @@
4040 $this->timestamp = $timestamp;
4141 $this->timestampStruck = $timestampStruck;
4242 }
43 -
 43+
4444 /**
4545 * @return bool Whether this sign-off has been struck
4646 */
4747 public function isStruck() {
4848 return $this->timestampStruck !== Block::infinity();
4949 }
50 -
 50+
5151 /**
5252 * @return mixed Timestamp (TS_MW format) the revision was struck at, or false if it hasn't been struck
5353 */
5454 public function getTimestampStruck() {
5555 return $this->isStruck() ? wfTimestamp( TS_MW, $this->timestampStruck ) : false;
5656 }
57 -
 57+
5858 /**
5959 * Strike this sign-off. Attempts to strike an already-struck signoff will be silently ignored.
6060 */
@@ -72,7 +72,7 @@
7373 ), __METHOD__
7474 );
7575 }
76 -
 76+
7777 /**
7878 * Get the ID of this signoff. This is not a numerical ID that exists in the database,
7979 * but a representation that you can use in URLs and the like. It's also not unique:
@@ -84,7 +84,7 @@
8585 public function getID() {
8686 return implode( '|', array( $this->flag, $this->timestampStruck, $this->userText ) );
8787 }
88 -
 88+
8989 /**
9090 * Create a CodeSignoff object from a revision and a database row object
9191 * @param $rev CodeRevision object the signoff belongs to
@@ -94,7 +94,7 @@
9595 public static function newFromRow( $rev, $row ) {
9696 return self::newFromData( $rev, get_object_vars( $row ) );
9797 }
98 -
 98+
9999 /**
100100 * Create a CodeSignoff object from a revision and a database row in array format
101101 * @param $rev CodeRevision object the signoff belongs to
@@ -106,7 +106,7 @@
107107 wfTimestamp( TS_MW, $data['cs_timestamp'] ), $data['cs_timestamp_struck']
108108 );
109109 }
110 -
 110+
111111 /**
112112 * Create a CodeSignoff object from a revision object and an ID previously obtained from getID()
113113 * @param $rev CodeRevision object
Index: trunk/extensions/CodeReview/ui/CodeRevisionView.php
@@ -480,7 +480,7 @@
481481 $header .= '<th>' . wfMsgHtml( 'code-signoff-field-user' ) . '</th>';
482482 $header .= '<th>' . wfMsgHtml( 'code-signoff-field-flag' ). '</th>';
483483 $header .= '<th>' . wfMsgHtml( 'code-signoff-field-date' ). '</th>';
484 - $buttonrow = $showButtons ? $this->signoffButtons() : '';
 484+ $buttonrow = $showButtons ? $this->signoffButtons( $signOffs ) : '';
485485 return "<table border='1' class='TablePager'><tr>$header</tr>$signoffs$buttonrow</table>";
486486 }
487487
@@ -732,26 +732,48 @@
733733 '</div>';
734734 }
735735
736 - // TODO : checkboxes should be disabled if user already has set the flag
737736 /**
738737 * Render the bottom row of the sign-offs table containing the buttons to
739738 * strike and submit sign-offs
740739 * @return string HTML
741740 */
742 - protected function signoffButtons() {
 741+ protected function signoffButtons( $signOffs ) {
 742+ $userSignOffs = $this->getUserSignoffs( $signOffs );
743743 $strikeButton = Xml::submitButton( wfMsg( 'code-signoff-strike' ), array( 'name' => 'wpStrikeSignoffs' ) );
744744 $signoffText = wfMsgHtml( 'code-signoff-signoff' );
745745 $signoffButton = Xml::submitButton( wfMsg( 'code-signoff-submit' ), array( 'name' => 'wpSignoff' ) );
746746 $checks = '';
 747+
747748 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+ ) ) .
749754 ' ' . Xml::label( wfMsg( "code-signoff-flag-$flag" ), "wpSignoffFlags-$flag" ) . ' ';
750755 }
751756 return "<tr class='mw-codereview-signoffbuttons'><td colspan='4'>$strikeButton " .
752757 "<div class='mw-codereview-signoffchecks'>$signoffText $checks $signoffButton</div></td></tr>";
753758 }
754 -
 759+
755760 /**
 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+ /**
756778 * Render the bottom row of the follow-up revisions table containing the buttons and
757779 * textbox to add and remove follow-up associations
758780 * @return string HTML

Status & tagging log