Index: trunk/extensions/Translate/Message.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Classes for message objects. |
| 4 | + * Classes for message objects TMessage and ThinMessage. |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @author Niklas Laxström |
— | — | @@ -9,11 +9,17 @@ |
10 | 10 | */ |
11 | 11 | |
12 | 12 | /** |
13 | | - * @todo Needs documentation. |
| 13 | + * Interface for message objects used by MessageCollection. |
14 | 14 | */ |
15 | 15 | abstract class TMessage { |
| 16 | + /// \string Message display key. |
16 | 17 | protected $key; |
| 18 | + /// \string Message definition. |
17 | 19 | protected $definition; |
| 20 | + /// \string Committed in-file translation. |
| 21 | + protected $infile; |
| 22 | + /// \list{String} Message tags. |
| 23 | + protected $tags = array(); |
18 | 24 | |
19 | 25 | /** |
20 | 26 | * Creates new message object. |
— | — | @@ -26,75 +32,110 @@ |
27 | 33 | $this->definition = $definition; |
28 | 34 | } |
29 | 35 | |
| 36 | + /** |
| 37 | + * Get the message key. |
| 38 | + * @return \string |
| 39 | + */ |
30 | 40 | public function key() { return $this->key; } |
| 41 | + |
| 42 | + /** |
| 43 | + * Get the message definition. |
| 44 | + * @return \string |
| 45 | + */ |
31 | 46 | public function definition() { return $this->definition; } |
| 47 | + |
| 48 | + /** |
| 49 | + * Get the message translation. |
| 50 | + * @return \types{\string,\null} |
| 51 | + */ |
32 | 52 | abstract public function translation(); |
| 53 | + |
| 54 | + /** |
| 55 | + * Get the last translator of the message. |
| 56 | + * @return \types{\string,\null} |
| 57 | + */ |
33 | 58 | abstract public function author(); |
34 | | -} |
35 | 59 | |
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 | + */ |
44 | 64 | public function setInfile( $text ) { |
45 | 65 | $this->infile = $text; |
46 | 66 | } |
47 | 67 | |
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; |
50 | 74 | } |
51 | 75 | |
| 76 | + /** |
| 77 | + * Add a tag for this message. |
| 78 | + * @param $tag \string |
| 79 | + * @todo Rename to addTag. |
| 80 | + */ |
52 | 81 | public function setTag( $tag ) { |
53 | 82 | $this->tags[] = $tag; |
54 | 83 | } |
55 | 84 | |
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 ); |
58 | 92 | } |
| 93 | +} |
59 | 94 | |
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; |
62 | 110 | } |
63 | 111 | |
64 | 112 | public function translation() { |
65 | 113 | if ( !isset( $this->row ) ) { |
66 | 114 | return $this->infile(); |
67 | 115 | } |
68 | | - |
69 | 116 | return Revision::getRevisionText( $this->row ); |
70 | 117 | } |
| 118 | + |
71 | 119 | public function author() { |
72 | 120 | if ( !isset( $this->row ) ) { |
73 | 121 | return null; |
74 | 122 | } |
75 | | - |
76 | 123 | return $this->row->rev_user_text; |
77 | 124 | } |
78 | 125 | |
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 | | - } |
90 | 126 | } |
91 | 127 | |
92 | 128 | /** |
93 | | - * @todo Needs documentation. |
| 129 | + * %Message object where you can directly set the translation. |
| 130 | + * Hence the name fat. Authors are not supported. |
94 | 131 | */ |
95 | 132 | class FatMessage extends TMessage { |
96 | | - protected $translation = null; |
97 | | - protected $infile = null; |
| 133 | + /// \string Stored translation. |
| 134 | + protected $translation; |
98 | 135 | |
| 136 | + /** |
| 137 | + * Set the current translation of this message. |
| 138 | + * @param $text \string |
| 139 | + */ |
99 | 140 | public function setTranslation( $text ) { |
100 | 141 | $this->translation = $text; |
101 | 142 | } |
— | — | @@ -103,17 +144,9 @@ |
104 | 145 | if ( $this->translation === null ) { |
105 | 146 | return $this->infile; |
106 | 147 | } |
107 | | - |
108 | 148 | return $this->translation; |
109 | 149 | } |
110 | 150 | |
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() {} |
120 | 153 | } |