CoreMessageGroup.php

Go to the documentation of this file.
00001 <?php
00017 class CoreMessageGroup extends MessageGroupOld {
00018     protected $label = 'MediaWiki';
00019     protected $id = 'core';
00020     protected $type = 'mediawiki';
00021     protected $description = '{{int:translate-group-desc-mediawikicore}}';
00022     protected $icon;
00023 
00024     public function __construct() {
00025         parent::__construct();
00026 
00027         global $IP;
00028 
00029         $this->prefix = $IP . '/languages/messages';
00030         $this->metaDataPrefix = $IP . '/maintenance/language';
00031     }
00032 
00033     protected $prefix = '';
00034 
00035     public function getPrefix() {
00036         return $this->prefix;
00037     }
00038 
00039     public function setPrefix( $value ) {
00040         $this->prefix = $value;
00041     }
00042 
00043     protected $metaDataPrefix = '';
00044 
00045     public function getMetaDataPrefix() {
00046         return $this->metaDataPrefix;
00047     }
00048 
00049     public function setMetaDataPrefix( $value ) {
00050         $this->metaDataPrefix = $value;
00051     }
00052 
00053     public $parentId = null;
00054 
00055     public static function factory( $label, $id ) {
00056         $group = new CoreMessageGroup;
00057         $group->setLabel( $label );
00058         $group->setId( $id );
00059 
00060         return $group;
00061     }
00062 
00064     public function setIcon( $icon ) {
00065         $this->icon = $icon;
00066     }
00067 
00068     public function getIcon() {
00069         return $this->icon;
00070     }
00071 
00072     public function getUniqueDefinitions() {
00073         if ( $this->parentId ) {
00074             $parent = MessageGroups::getGroup( $this->parentId );
00075             $parentDefs = $parent->getDefinitions();
00076             $ourDefs = $this->getDefinitions();
00077 
00078             // Filter out shared messages.
00079             foreach ( array_keys( $parentDefs ) as $key ) {
00080                 unset( $ourDefs[$key] );
00081             }
00082 
00083             return $ourDefs;
00084         }
00085 
00086         return $this->getDefinitions();
00087     }
00088 
00089     public function getMessageFile( $code ) {
00090         $code = ucfirst( str_replace( '-', '_', $code ) );
00091 
00092         return "Messages$code.php";
00093     }
00094 
00095     public function getPath() {
00096         return $this->prefix;
00097     }
00098 
00099     public function getReader( $code ) {
00100         return new WikiFormatReader( $this->getMessageFileWithPath( $code ) );
00101     }
00102 
00103     public function getWriter() {
00104         return new WikiFormatWriter( $this );
00105     }
00106 
00107     public function getTags( $type = null ) {
00108         require $this->getMetaDataPrefix() . '/messageTypes.inc';
00109         $mangler = $this->getMangler();
00110         $this->optional = $mangler->mangle( $wgOptionalMessages );
00111         $this->ignored = $mangler->mangle( $wgIgnoredMessages );
00112 
00113         return parent::getTags( $type );
00114     }
00115 
00116     public function load( $code ) {
00117         $file = $this->getMessageFileWithPath( $code );
00118         // Can return null, convert to array.
00119         $mangler = $this->getMangler();
00120         $messages = (array)$mangler->mangle(
00121             PHPVariableLoader::loadVariableFromPHPFile( $file, 'messages' )
00122         );
00123 
00124         if ( $this->parentId ) {
00125             if ( !$this->isSourceLanguage( $code ) ) {
00126                 // For branches, load newer compatible messages for missing entries, if any.
00127                 $trunk = MessageGroups::getGroup( $this->parentId );
00128                 $messages += $trunk->getMangler()->mangle( $trunk->load( $code ) );
00129             }
00130         }
00131 
00132         return $messages;
00133     }
00134 
00135     public function getChecker() {
00136         $checker = new MediaWikiMessageChecker( $this );
00137         $checker->setChecks( array(
00138             array( $checker, 'pluralCheck' ),
00139             array( $checker, 'pluralFormsCheck' ),
00140             array( $checker, 'wikiParameterCheck' ),
00141             array( $checker, 'wikiLinksCheck' ),
00142             array( $checker, 'XhtmlCheck' ),
00143             array( $checker, 'braceBalanceCheck' ),
00144             array( $checker, 'pagenameMessagesCheck' ),
00145             array( $checker, 'miscMWChecks' )
00146         ) );
00147 
00148         return $checker;
00149     }
00150 
00151     public function getInsertablesSuggester() {
00152         return new MediaWikiInsertablesSuggester();
00153     }
00154 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3