r98314 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98313‎ | r98314 | r98315 >
Date:14:54, 28 September 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
added ContestComment class
Modified paths:
  • /trunk/extensions/Contest/includes/ContestComment.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/includes/ContestComment.php
@@ -0,0 +1,103 @@
 2+<?php
 3+
 4+/**
 5+ * Class representing a single contest comment.
 6+ * Comments can be made by judges on submissions of contestants.
 7+ *
 8+ * @since 0.1
 9+ *
 10+ * @file ContestComment.php
 11+ * @ingroup Contest
 12+ *
 13+ * @licence GNU GPL v3 or later
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+class ContestComment extends ContestDBObject {
 17+
 18+ /**
 19+ * Method to get an instance so methods that ought to be static,
 20+ * but can't be due to PHP 5.2 not having LSB, can be called on
 21+ * it. This also allows easy identifying of code that needs to
 22+ * be changed once PHP 5.3 becomes an acceptable requirement.
 23+ *
 24+ * @since 0.1
 25+ *
 26+ * @return ContestDBObject
 27+ */
 28+ public static function s() {
 29+ static $instance = false;
 30+
 31+ if ( $instance === false ) {
 32+ $instance = new self( array() );
 33+ }
 34+
 35+ return $instance;
 36+ }
 37+
 38+ /**
 39+ * Get a new instance of the class from an array.
 40+ * This method ought to be in the basic class and
 41+ * return a new static(), but this requires LSB/PHP>=5.3.
 42+ *
 43+ * @since 0.1
 44+ *
 45+ * @param array $data
 46+ * @param boolean $loadDefaults
 47+ *
 48+ * @return ContestDBObject
 49+ */
 50+ public function newFromArray( array $data, $loadDefaults = false ) {
 51+ return new self( $data, $loadDefaults );
 52+ }
 53+
 54+ /**
 55+ * @see parent::getFieldTypes
 56+ *
 57+ * @since 0.1
 58+ *
 59+ * @return string
 60+ */
 61+ public function getDBTable() {
 62+ return 'contest_comments';
 63+ }
 64+
 65+ /**
 66+ * @see parent::getFieldTypes
 67+ *
 68+ * @since 0.1
 69+ *
 70+ * @return string
 71+ */
 72+ protected function getFieldPrefix() {
 73+ return 'comment_';
 74+ }
 75+
 76+ /**
 77+ * @see parent::getFieldTypes
 78+ *
 79+ * @since 0.1
 80+ *
 81+ * @return array
 82+ */
 83+ protected function getFieldTypes() {
 84+ return array(
 85+ 'id' => 'id',
 86+ 'contestant_id' => 'id',
 87+ 'text' => 'str',
 88+ );
 89+ }
 90+
 91+ /**
 92+ * @see parent::getDefaults
 93+ *
 94+ * @since 0.1
 95+ *
 96+ * @return array
 97+ */
 98+ public function getDefaults() {
 99+ return array(
 100+ 'text' => '',
 101+ );
 102+ }
 103+
 104+}

Comments

#Comment by Nikerabbit (talk | contribs)   16:50, 28 September 2011

Isn't s() a bit short function name?

#Comment by Jeroen De Dauw (talk | contribs)   16:53, 28 September 2011

It's not a "real" function, but a hack to emulate PHP 5.3 functionality. Once this can use PHP 5.3, every "::s()->" should be replaced by "::".

Status & tagging log