AggregateMessageGroup.php
Go to the documentation of this file.00001 <?php
00018 class AggregateMessageGroup extends MessageGroupBase {
00019 public function exists() {
00020
00021 $exists = (bool)$this->conf['GROUPS'];
00022
00023 return $exists;
00024 }
00025
00026 public function load( $code ) {
00027 $messages = array();
00028
00032 foreach ( $this->getGroups() as $group ) {
00033 $messages += $group->load( $code );
00034 }
00035
00036 return $messages;
00037 }
00038
00039 public function getMangler() {
00040 if ( !isset( $this->mangler ) ) {
00041 $this->mangler = StringMatcher::emptyMatcher();
00042 }
00043
00044 return $this->mangler;
00045 }
00046
00047 public function getGroups() {
00048 if ( !isset( $this->groups ) ) {
00049 $groups = array();
00050 $ids = (array)$this->conf['GROUPS'];
00051 $ids = MessageGroups::expandWildcards( $ids );
00052
00053 foreach ( $ids as $id ) {
00054
00055 if ( $id === $this->getId() ) {
00056 continue;
00057 }
00058
00059 $group = MessageGroups::getGroup( $id );
00060 if ( $group === null ) {
00061 error_log( "Invalid group id in {$this->getId()}: $id" );
00062 continue;
00063 }
00064
00065 if ( MessageGroups::getPriority( $group ) === 'discouraged' ) {
00066 continue;
00067 }
00068
00069 $groups[$id] = $group;
00070 }
00071
00072 $this->groups = $groups;
00073 }
00074
00075 return $this->groups;
00076 }
00077
00078 protected function loadMessagesFromCache( $groups ) {
00079 $messages = array();
00080 foreach ( $groups as $group ) {
00081 if ( $group instanceof MessageGroupOld ) {
00082 $messages += $group->getDefinitions();
00083 continue;
00084 }
00085
00086 if ( $group instanceof AggregateMessageGroup ) {
00087 $messages += $this->loadMessagesFromCache( $group->getGroups() );
00088 continue;
00089 }
00090
00091 $cache = new MessageGroupCache( $group );
00092 if ( $cache->exists() ) {
00093 foreach ( $cache->getKeys() as $key ) {
00094 $messages[$key] = $cache->get( $key );
00095 }
00096 }
00097 }
00098
00099 return $messages;
00100 }
00101
00102 public function initCollection( $code ) {
00103 $messages = $this->loadMessagesFromCache( $this->getGroups() );
00104 $namespace = $this->getNamespace();
00105 $definitions = new MessageDefinitions( $messages, $namespace );
00106 $collection = MessageCollection::newFromDefinitions( $definitions, $code );
00107
00108 $this->setTags( $collection );
00109
00110 return $collection;
00111 }
00112
00113 public function getMessage( $key, $code ) {
00114
00115
00116
00117
00118
00119
00120
00121 $title = Title::makeTitle( $this->getNamespace(), $key );
00122 $handle = new MessageHandle( $title );
00123 $groupId = MessageIndex::getPrimaryGroupId( $handle );
00124 if ( $groupId === $this->getId() ) {
00125
00126
00127 error_log( "AggregateMessageGroup $groupId cannot be primary owner of key $key" );
00128
00129 return null;
00130 }
00131
00132 $group = MessageGroups::getGroup( $groupId );
00133 if ( $group ) {
00134 return $group->getMessage( $key, $code );
00135 } else {
00136 return null;
00137 }
00138 }
00139
00140 public function getTags( $type = null ) {
00141 $tags = array();
00142
00146 foreach ( $this->getGroups() as $group ) {
00147 $tags = array_merge_recursive( $tags, $group->getTags( $type ) );
00148 }
00149
00150 return $tags;
00151 }
00152
00153 public function getKeys() {
00154 $keys = array();
00158 foreach ( $this->getGroups() as $group ) {
00159
00160 if ( method_exists( $group, 'getKeys' ) ) {
00161 $keys = array_merge( $keys, $group->getKeys() );
00162 } else {
00163 $keys = array_keys( $group->getDefinitions() );
00164 }
00165 }
00166
00167
00168
00169
00170
00171 return array_unique( $keys );
00172 }
00173 }