diff options
Diffstat (limited to 'MLEB/Translate/ffs/SimpleFFS.php')
-rw-r--r-- | MLEB/Translate/ffs/SimpleFFS.php | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/MLEB/Translate/ffs/SimpleFFS.php b/MLEB/Translate/ffs/SimpleFFS.php index ddc2e476..44cd456e 100644 --- a/MLEB/Translate/ffs/SimpleFFS.php +++ b/MLEB/Translate/ffs/SimpleFFS.php @@ -13,6 +13,7 @@ * @ingroup FFS */ +use MediaWiki\Extension\Translate\Services; use UtfNormal\Validator; class SimpleFFS implements FFS { @@ -94,6 +95,10 @@ class SimpleFFS implements FFS { * @throws MWException if the file is not readable or has bad encoding */ public function read( $code ) { + if ( !$this->isGroupFfsReadable() ) { + return []; + } + if ( !$this->exists( $code ) ) { return false; } @@ -262,13 +267,7 @@ class SimpleFFS implements FFS { * @param MessageCollection $collection */ protected function tryReadSource( $filename, MessageCollection $collection ) { - $ffs = $this->group->getFFS(); - - if ( $ffs === null ) { - return; - } - - if ( get_class( $ffs ) !== get_class( $this ) ) { + if ( !$this->isGroupFfsReadable() ) { return; } @@ -323,33 +322,17 @@ class SimpleFFS implements FFS { * @param string $code * @return array */ - protected function filterAuthors( array $authors, $code ) { - global $wgTranslateAuthorBlacklist; + public function filterAuthors( array $authors, $code ) { $groupId = $this->group->getId(); + $configHelper = Services::getInstance()->getConfigHelper(); foreach ( $authors as $i => $v ) { - $hash = "$groupId;$code;$v"; - - $excluded = false; - foreach ( $wgTranslateAuthorBlacklist as $rule ) { - list( $type, $regex ) = $rule; - - if ( preg_match( $regex, $hash ) ) { - if ( $type === 'white' ) { - $excluded = false; - break; - } else { - $excluded = true; - } - } - } - - if ( $excluded ) { + if ( $configHelper->isAuthorExcluded( $groupId, $code, $v ) ) { unset( $authors[$i] ); } } - return $authors; + return array_values( $authors ); } /** @@ -373,4 +356,24 @@ class SimpleFFS implements FFS { public function shouldOverwrite( $a, $b ) { return true; } + + /** + * Check if the file format of the current group is readable by the file + * format system. This might happen if we are trying to export a JsonFFS + * or WikiPageMessage group to a GettextFFS + * @return bool + */ + public function isGroupFfsReadable(): bool { + try { + $ffs = $this->group->getFFS(); + } catch ( RunTimeException $e ) { + if ( $e->getCode() === FileBasedMessageGroup::NO_FFS_CLASS ) { + return false; + } + + throw $e; + } + + return get_class( $ffs ) === get_class( $this ); + } } |