r68479 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68478‎ | r68479 | r68480 >
Date:19:08, 23 June 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Group for all Shapado messages + performance tweak
Modified paths:
  • /trunk/extensions/Translate/FFS.php (modified) (history)
  • /trunk/extensions/Translate/Groups.php (modified) (history)
  • /trunk/extensions/Translate/groups/Shapado/Shapado.yml (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/FFS.php
@@ -39,7 +39,7 @@
4040 public function setWritePath( $writePath ) { $this->writePath = $writePath; }
4141 public function getWritePath() { return $this->writePath; }
4242
43 - public function read( $code ) {
 43+ public function exists( $code = 'en' ) {
4444 $filename = $this->group->getSourceFilePath( $code );
4545 if ( $filename === null ) {
4646 return false;
@@ -49,6 +49,15 @@
5050 return false;
5151 }
5252
 53+ return true;
 54+ }
 55+
 56+ public function read( $code ) {
 57+ if ( !$this->exists( $code ) ) {
 58+ return false;
 59+ }
 60+
 61+ $filename = $this->group->getSourceFilePath( $code );
5362 $input = file_get_contents( $filename );
5463 if ( $input === false ) {
5564 throw new MWException( "Unable to read file $filename" );
Index: trunk/extensions/Translate/groups/Shapado/Shapado.yml
@@ -24,6 +24,45 @@
2525
2626 ---
2727 BASIC:
 28+ id: out-shapado-0-all
 29+ label: All Shapado messages
 30+ display: out/shapado
 31+ meta: yes
 32+ class: AggregateMessageGroup
 33+GROUPS:
 34+ - out-shapado-ads
 35+ - out-shapado-announcements
 36+ - out-shapado-answers
 37+ - out-shapado-badges
 38+ - out-shapado-closerequests
 39+ - out-shapado-comments
 40+ - out-shapado-doc
 41+ - out-shapado-errors
 42+ - out-shapado-favorites
 43+ - out-shapado-flags
 44+ - out-shapado-global
 45+ - out-shapado-groups
 46+ - out-shapado-imports
 47+ - out-shapado-layouts
 48+ - out-shapado-mailers
 49+ - out-shapado-manage
 50+ - out-shapado-members
 51+ - out-shapado-moderate
 52+ - out-shapado-notifier
 53+ - out-shapado-pages
 54+ - out-shapado-questions
 55+ - out-shapado-searches
 56+ - out-shapado-sessions
 57+ - out-shapado-shared
 58+ - out-shapado-unfavorites
 59+ - out-shapado-users
 60+ - out-shapado-votes
 61+ - out-shapado-welcome
 62+ - out-shapado-widgets
 63+ - out-shapado-wiki
 64+
 65+---
 66+BASIC:
2867 id: out-shapado-ads
2968 label: Shapado - Ads
3069 display: out/shapado/ads
Index: trunk/extensions/Translate/Groups.php
@@ -227,13 +227,12 @@
228228
229229 class FileBasedMessageGroup extends MessageGroupBase {
230230 public function exists() {
231 - return (bool) count( $this->load( 'en' ) );
 231+ return $this->getFFS()->exists();
232232 }
233233
234234 public function load( $code ) {
235235 $ffs = $this->getFFS();
236236 $data = $ffs->read( $code );
237 -
238237 return $data ? $data['MESSAGES'] : array();
239238 }
240239
@@ -316,3 +315,92 @@
317316 parent::setTags( $collection );
318317 }
319318 }
 319+
 320+
 321+/**
 322+ * Groups multiple message groups together as one big group.
 323+ * Limitations:
 324+ * - Only groups of same type and in the same namespace
 325+ */
 326+class AggregateMessageGroup extends MessageGroupBase {
 327+
 328+ public function exists() {
 329+ // Group exists if there is any subgroups
 330+ $exists = (bool) $this->conf['GROUPS'];
 331+
 332+ if ( !$exists ) {
 333+ trigger_error( __METHOD__ . "[{$this->getId()}]: Group is empty" );
 334+ }
 335+
 336+ return $exists;
 337+ }
 338+
 339+ public function load( $code ) {
 340+ $messages = array();
 341+ foreach( $this->getGroups() as $group ) {
 342+ $messages += $group->load( $code );
 343+ }
 344+ return $messages;
 345+ }
 346+
 347+ public function getMangler() {
 348+ if ( !isset( $this->mangler ) ) {
 349+ $this->mangler = StringMatcher::emptyMatcher();
 350+ }
 351+ return $this->mangler;
 352+ }
 353+
 354+ protected function getGroups() {
 355+ if ( !isset( $this->groups ) ) {
 356+ $groups = array();
 357+ $ids = (array) $this->conf['GROUPS'];
 358+ foreach( $ids as $id ) {
 359+ // Don't try to include self and go to infinite loop
 360+ if ( $id === $this->getId() ) continue;
 361+ $groups[$id] = MessageGroups::getGroup( $id );
 362+ }
 363+ $this->groups = $groups;
 364+ }
 365+ return $this->groups;
 366+ }
 367+
 368+ public function initCollection( $code ) {
 369+ $messages = array();
 370+ foreach( $this->getGroups() as $group ) {
 371+ $cache = new MessageGroupCache( $group );
 372+ foreach ( $cache->getKeys() as $key ) {
 373+ $messages[$key] = $cache->get( $key );
 374+ }
 375+ }
 376+
 377+ $namespace = $this->getNamespace();
 378+ $definitions = new MessageDefinitions( $namespace, $messages );
 379+ $collection = MessageCollection::newFromDefinitions( $definitions, $code );
 380+ $this->setTags( $collection );
 381+
 382+ return $collection;
 383+ }
 384+
 385+ public function getMessage( $key, $code ) {
 386+ foreach( $this->getGroups() as $group ) {
 387+ $message = $group->getMessage( $key, $code );
 388+ if ( $message !== null ) return $message;
 389+ }
 390+ }
 391+
 392+ public function getTags( $type = null ) {
 393+ $tags = array();
 394+ foreach( $this->getGroups() as $group ) {
 395+ //FIXME: is this correct?
 396+ $tags = array_merge_recursive( $tags, $group->getTags( $type ) );
 397+ }
 398+ return $tags;
 399+ }
 400+
 401+ protected function setTags( MessageCollection $collection ) {
 402+ foreach( $this->getGroups() as $group ) {
 403+ $group->setTags( $collection );
 404+ }
 405+ }
 406+
 407+}
\ No newline at end of file

Status & tagging log