r77310 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77309‎ | r77310 | r77311 >
Date:23:26, 25 November 2010
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Some documentation for r77302, more tomorrow. Functional change: make getTimestampStruck() return a sane value (false) when the sign-off is not struck.
Modified paths:
  • /trunk/extensions/CodeReview/backend/CodeRevision.php (modified) (history)
  • /trunk/extensions/CodeReview/backend/CodeSignoff.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/backend/CodeRevision.php
@@ -670,6 +670,13 @@
671671 $dbw->insert( 'code_signoffs', $rows, __METHOD__, array( 'IGNORE' ) );
672672 }
673673
 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+ */
674681 public function strikeSignoffs( $user, $ids ) {
675682 foreach ( $ids as $id ) {
676683 $signoff = CodeSignoff::newFromId( $this, $id );
Index: trunk/extensions/CodeReview/backend/CodeSignoff.php
@@ -1,8 +1,36 @@
22 <?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+ */
38 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+
520 private $timestampStruck;
621
 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+ */
735 public function __construct( $rev, $user, $userText, $flag, $timestamp, $timestampStruck ) {
836 $this->rev = $rev;
937 $this->user = $user;
@@ -12,14 +40,23 @@
1341 $this->timestampStruck = $timestampStruck;
1442 }
1543
 44+ /**
 45+ * @return bool Whether this sign-off has been struck
 46+ */
1647 public function isStruck() {
1748 return $this->timestampStruck !== Block::infinity();
1849 }
1950
 51+ /**
 52+ * @return mixed Timestamp (TS_MW format) the revision was struck at, or false if it hasn't been struck
 53+ */
2054 public function getTimestampStruck() {
21 - return wfTimestamp( TS_MW, $this->timestampStruck );
 55+ return $this->isStruck() ? wfTimestamp( TS_MW, $this->timestampStruck ) : false;
2256 }
2357
 58+ /**
 59+ * Strike this sign-off. Attempts to strike an already-struck signoff will be silently ignored.
 60+ */
2461 public function strike() {
2562 if ( $this->isStruck() ) {
2663 return;
@@ -36,20 +73,46 @@
3774 );
3875 }
3976
 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+ */
4085 public function getID() {
4186 return implode( '|', array( $this->flag, $this->timestampStruck, $this->userText ) );
4287 }
4388
 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+ */
4495 public static function newFromRow( $rev, $row ) {
4596 return self::newFromData( $rev, get_object_vars( $row ) );
4697 }
4798
 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+ */
48105 public static function newFromData( $rev, $data ) {
49106 return new self( $rev, $data['cs_user'], $data['cs_user_text'], $data['cs_flag'],
50107 wfTimestamp( TS_MW, $data['cs_timestamp'] ), $data['cs_timestamp_struck']
51108 );
52109 }
53110
 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+ */
54117 public static function newFromID( $rev, $id ) {
55118 $parts = explode( '|', $id, 3 );
56119 if ( count( $parts ) != 3 ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r77323Fix typo per r77310 CRcatrope10:22, 26 November 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r77302(bug 26014) Allow users to strike their own sign-offs. Implemented with a tim...catrope21:39, 25 November 2010

Comments

#Comment by Platonides (talk | contribs)   23:29, 25 November 2010

For piggybacking tomorrow: entires -> entries

Status & tagging log