Message.php

Go to the documentation of this file.
00001 <?php
00014 abstract class TMessage {
00016     protected $key;
00018     protected $definition;
00020     protected $infile;
00022     protected $tags = array();
00024     protected $props = array();
00026     protected $reviewers = array();
00027 
00034     public function __construct( $key, $definition ) {
00035         $this->key = $key;
00036         $this->definition = $definition;
00037     }
00038 
00043     public function key() {
00044         return $this->key;
00045     }
00046 
00051     public function definition() {
00052         return $this->definition;
00053     }
00054 
00059     abstract public function translation();
00060 
00065     public function setInfile( $text ) {
00066         $this->infile = $text;
00067     }
00068 
00073     public function infile() {
00074         return $this->infile;
00075     }
00076 
00081     public function addTag( $tag ) {
00082         $this->tags[] = $tag;
00083     }
00084 
00090     public function hasTag( $tag ) {
00091         return in_array( $tag, $this->tags, true );
00092     }
00093 
00098     public function getTags() {
00099         return $this->tags;
00100     }
00101 
00102     public function setProperty( $key, $value ) {
00103         $this->props[$key] = $value;
00104     }
00105 
00106     public function appendProperty( $key, $value ) {
00107         if ( !isset( $this->props[$key] ) ) {
00108             $this->props[$key] = array();
00109         }
00110         $this->props[$key][] = $value;
00111     }
00112 
00113     public function getProperty( $key ) {
00114         return isset( $this->props[$key] ) ? $this->props[$key] : null;
00115     }
00116 
00122     public function getPropertyNames() {
00123         return array_keys( $this->props );
00124     }
00125 }
00126 
00132 class ThinMessage extends TMessage {
00133     // This maps properties to fields in the database result row
00134     protected static $propertyMap = array(
00135         'last-translator-text' => 'rev_user_text',
00136         'last-translator-id' => 'rev_user',
00137     );
00138 
00142     protected $row;
00143 
00148     public function setRow( $row ) {
00149         $this->row = $row;
00150     }
00151 
00152     public function translation() {
00153         if ( !isset( $this->row ) ) {
00154             return $this->infile();
00155         }
00156 
00157         return Revision::getRevisionText( $this->row );
00158     }
00159 
00160     // Re-implemented
00161     public function getProperty( $key ) {
00162         if ( !isset( self::$propertyMap[$key] ) ) {
00163             return parent::getProperty( $key );
00164         }
00165 
00166         $field = self::$propertyMap[$key];
00167         if ( !isset( $this->row->$field ) ) {
00168             return null;
00169         }
00170 
00171         return $this->row->$field;
00172     }
00173 
00174     // Re-implemented
00175     public function getPropertyNames() {
00176         return array_merge( parent::getPropertyNames(), array_keys( self::$propertyMap ) );
00177     }
00178 }
00179 
00184 class FatMessage extends TMessage {
00186     protected $translation;
00187 
00192     public function setTranslation( $text ) {
00193         $this->translation = $text;
00194     }
00195 
00196     public function translation() {
00197         if ( $this->translation === null ) {
00198             return $this->infile;
00199         }
00200 
00201         return $this->translation;
00202     }
00203 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3