r72419 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72418‎ | r72419 | r72420 >
Date:13:07, 5 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Documentation updates. Moved some methods to the interface that were common or required by MessageCollection.
Modified paths:
  • /trunk/extensions/Translate/Message.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Message.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * Classes for message objects.
 4+ * Classes for message objects TMessage and ThinMessage.
55 *
66 * @file
77 * @author Niklas Laxström
@@ -9,11 +9,17 @@
1010 */
1111
1212 /**
13 - * @todo Needs documentation.
 13+ * Interface for message objects used by MessageCollection.
1414 */
1515 abstract class TMessage {
 16+ /// \string Message display key.
1617 protected $key;
 18+ /// \string Message definition.
1719 protected $definition;
 20+ /// \string Committed in-file translation.
 21+ protected $infile;
 22+ /// \list{String} Message tags.
 23+ protected $tags = array();
1824
1925 /**
2026 * Creates new message object.
@@ -26,75 +32,110 @@
2733 $this->definition = $definition;
2834 }
2935
 36+ /**
 37+ * Get the message key.
 38+ * @return \string
 39+ */
3040 public function key() { return $this->key; }
 41+
 42+ /**
 43+ * Get the message definition.
 44+ * @return \string
 45+ */
3146 public function definition() { return $this->definition; }
 47+
 48+ /**
 49+ * Get the message translation.
 50+ * @return \types{\string,\null}
 51+ */
3252 abstract public function translation();
 53+
 54+ /**
 55+ * Get the last translator of the message.
 56+ * @return \types{\string,\null}
 57+ */
3358 abstract public function author();
34 -}
3559
36 -/**
37 - * @todo Needs documentation.
38 - */
39 -class ThinMessage extends TMessage {
40 - private $infile;
41 - private $row;
42 - private $tags = array();
43 -
 60+ /**
 61+ * Set the committed translation.
 62+ * @param $text \string
 63+ */
4464 public function setInfile( $text ) {
4565 $this->infile = $text;
4666 }
4767
48 - public function setRow( $row ) {
49 - $this->row = $row;
 68+ /**
 69+ * Returns the committed translation.
 70+ * @return \types{\string,\null}
 71+ */
 72+ public function infile() {
 73+ return $this->infile;
5074 }
5175
 76+ /**
 77+ * Add a tag for this message.
 78+ * @param $tag \string
 79+ * @todo Rename to addTag.
 80+ */
5281 public function setTag( $tag ) {
5382 $this->tags[] = $tag;
5483 }
5584
56 - public function key() {
57 - return $this->key;
 85+ /**
 86+ * Check if this message has a given tag.
 87+ * @param $tag \string
 88+ * @return \bool
 89+ */
 90+ public function hasTag( $tag ) {
 91+ return in_array( $tag, $this->tags, true );
5892 }
 93+}
5994
60 - public function definition() {
61 - return $this->definition;
 95+/**
 96+ * %Message object which is based on database result row. Hence the name thin.
 97+ * Needs fields rev_user_text and those that are needed for loading revision
 98+ * text.
 99+ */
 100+class ThinMessage extends TMessage {
 101+ /// \type{Database Result Row}
 102+ protected $row;
 103+
 104+ /**
 105+ * Set the database row this message is based on.
 106+ * @param $row \type{Database Result Row}
 107+ */
 108+ public function setRow( $row ) {
 109+ $this->row = $row;
62110 }
63111
64112 public function translation() {
65113 if ( !isset( $this->row ) ) {
66114 return $this->infile();
67115 }
68 -
69116 return Revision::getRevisionText( $this->row );
70117 }
 118+
71119 public function author() {
72120 if ( !isset( $this->row ) ) {
73121 return null;
74122 }
75 -
76123 return $this->row->rev_user_text;
77124 }
78125
79 - public function infile() {
80 - if ( !isset( $this->infile ) ) {
81 - return null;
82 - }
83 -
84 - return $this->infile;
85 - }
86 -
87 - public function hasTag( $tag ) {
88 - return in_array( $tag, $this->tags, true );
89 - }
90126 }
91127
92128 /**
93 - * @todo Needs documentation.
 129+ * %Message object where you can directly set the translation.
 130+ * Hence the name fat. Authors are not supported.
94131 */
95132 class FatMessage extends TMessage {
96 - protected $translation = null;
97 - protected $infile = null;
 133+ /// \string Stored translation.
 134+ protected $translation;
98135
 136+ /**
 137+ * Set the current translation of this message.
 138+ * @param $text \string
 139+ */
99140 public function setTranslation( $text ) {
100141 $this->translation = $text;
101142 }
@@ -103,17 +144,9 @@
104145 if ( $this->translation === null ) {
105146 return $this->infile;
106147 }
107 -
108148 return $this->translation;
109149 }
110150
111 - public function author() { }
112 -
113 - public function setInfile( $text ) {
114 - $this->infile = $text;
115 - }
116 -
117 - public function infile() {
118 - return $this->infile;
119 - }
 151+ // Not implemented
 152+ public function author() {}
120153 }

Status & tagging log