diff options
Diffstat (limited to 'MLEB/Translate/ffs/MediaWikiExtensions.php')
-rw-r--r-- | MLEB/Translate/ffs/MediaWikiExtensions.php | 122 |
1 files changed, 78 insertions, 44 deletions
diff --git a/MLEB/Translate/ffs/MediaWikiExtensions.php b/MLEB/Translate/ffs/MediaWikiExtensions.php index 231a730f..123c5012 100644 --- a/MLEB/Translate/ffs/MediaWikiExtensions.php +++ b/MLEB/Translate/ffs/MediaWikiExtensions.php @@ -4,16 +4,20 @@ * * @file * @author Niklas Laxström - * @copyright Copyright © 2008-2013, Niklas Laxström - * @license GPL-2.0+ + * @license GPL-2.0-or-later */ /** - * Class which handles special definition format for %MediaWiki extensions. + * Class which handles special definition format for %MediaWiki extensions and skins. */ class PremadeMediawikiExtensionGroups { + /** @var bool */ protected $useConfigure = true; + + /** @var string */ protected $idPrefix = 'ext-'; + + /** @var int */ protected $namespace = NS_MEDIAWIKI; /** @@ -43,7 +47,9 @@ class PremadeMediawikiExtensionGroups { /** * Whether to use the Configure extension to load extension home pages. + * * @since 2012-03-22 + * @param bool $value Whether Configure should be used. */ public function setUseConfigure( $value ) { $this->useConfigure = $value; @@ -51,26 +57,39 @@ class PremadeMediawikiExtensionGroups { /** * How to prefix message group ids. + * * @since 2012-03-22 + * @param string $value */ public function setGroupPrefix( $value ) { $this->idPrefix = $value; } /** - * What namespace holds the messages. + * Which namespace holds the messages. + * * @since 2012-03-22 + * @param int $value */ public function setNamespace( $value ) { $this->namespace = $value; } - /// Makes an group id from extension name - static function foldId( $name ) { + /** + * Makes an group id from extension name + * @param string $name + * @return string + */ + public static function foldId( $name ) { return preg_replace( '/\s+/', '', strtolower( $name ) ); } - /// Hook: TranslatePostInitGroups + /** + * Hook: TranslatePostInitGroups + * @param array &$list + * @param array &$deps + * @return true + */ public function register( array &$list, array &$deps ) { $groups = $this->parseFile(); $groups = $this->processGroups( $groups ); @@ -90,7 +109,7 @@ class PremadeMediawikiExtensionGroups { * @return MediaWikiExtensionMessageGroup */ protected function createMessageGroup( $id, $info ) { - $conf = array(); + $conf = []; $conf['BASIC']['class'] = 'MediaWikiExtensionMessageGroup'; $conf['BASIC']['id'] = $id; $conf['BASIC']['namespace'] = $this->namespace; @@ -103,12 +122,7 @@ class PremadeMediawikiExtensionGroups { $conf['BASIC']['extensionurl'] = $info['url']; } - if ( $info['format'] === 'json' ) { - $conf['FILES']['class'] = 'JsonFFS'; - } else { - $conf['FILES']['class'] = 'MediaWikiExtensionFFS'; - } - + $conf['FILES']['class'] = 'JsonFFS'; $conf['FILES']['sourcePattern'] = $this->path . '/' . $info['file']; // @todo Find a better way @@ -136,16 +150,15 @@ class PremadeMediawikiExtensionGroups { } $conf['CHECKER']['class'] = 'MediaWikiMessageChecker'; - $conf['CHECKER']['checks'] = array( + $conf['CHECKER']['checks'] = [ 'pluralCheck', 'pluralFormsCheck', 'wikiParameterCheck', 'wikiLinksCheck', - 'XhtmlCheck', 'braceBalanceCheck', 'pagenameMessagesCheck', 'miscMWChecks', - ); + ]; $conf['INSERTABLES']['class'] = 'MediaWikiInsertablesSuggester'; @@ -156,6 +169,27 @@ class PremadeMediawikiExtensionGroups { $conf['TAGS']['ignored'] = $info['ignored']; } + if ( isset( $info['languages'] ) ) { + $conf['LANGUAGES'] = [ + 'whitelist' => [], + 'blacklist' => [], + ]; + + foreach ( $info['languages'] as $tagSpec ) { + if ( preg_match( '/^([+-])?(.+)$/', $tagSpec, $m ) ) { + list( , $sign, $tag ) = $m; + if ( $sign === '+' ) { + $conf['LANGUAGES']['whitelist'][] = $tag; + } elseif ( $sign === '-' ) { + $conf['LANGUAGES']['blacklist'][] = $tag; + } else { + $conf['LANGUAGES']['blacklist'] = '*'; + $conf['LANGUAGES']['whitelist'][] = $tag; + } + } + } + } + return MessageGroupBase::factory( $conf ); } @@ -166,11 +200,11 @@ class PremadeMediawikiExtensionGroups { 'trim', preg_split( "/$linefeed{2,}/", $defines, -1, PREG_SPLIT_NO_EMPTY ) ); - $groups = array(); + $groups = []; foreach ( $sections as $section ) { $lines = array_map( 'trim', preg_split( "/$linefeed/", $section ) ); - $newgroup = array(); + $newgroup = []; foreach ( $lines as $line ) { if ( $line === '' || $line[0] === '#' ) { @@ -181,7 +215,7 @@ class PremadeMediawikiExtensionGroups { if ( empty( $newgroup['name'] ) ) { $newgroup['name'] = $line; } else { - throw new MWException( "Trying to define name twice: " . $line ); + throw new MWException( 'Trying to define name twice: ' . $line ); } } else { list( $key, $value ) = array_map( 'trim', explode( '=', $line, 2 ) ); @@ -190,7 +224,6 @@ class PremadeMediawikiExtensionGroups { case 'desc': case 'descmsg': case 'file': - case 'format': case 'id': case 'magicfile': case 'var': @@ -198,9 +231,10 @@ class PremadeMediawikiExtensionGroups { break; case 'optional': case 'ignored': + case 'languages': $values = array_map( 'trim', explode( ',', $value ) ); if ( !isset( $newgroup[$key] ) ) { - $newgroup[$key] = array(); + $newgroup[$key] = []; } $newgroup[$key] = array_merge( $newgroup[$key], $values ); break; @@ -217,14 +251,14 @@ class PremadeMediawikiExtensionGroups { $newgroup['prefix'] = $prefix; if ( !isset( $newgroup['mangle'] ) ) { - $newgroup['mangle'] = array(); + $newgroup['mangle'] = []; } $messages = array_map( 'trim', explode( ',', $messages ) ); $newgroup['mangle'] = array_merge( $newgroup['mangle'], $messages ); break; default: - throw new MWException( "Unknown key:" . $key ); + throw new MWException( 'Unknown key:' . $key ); } } } @@ -242,10 +276,10 @@ class PremadeMediawikiExtensionGroups { protected function processGroups( $groups ) { $configureData = $this->loadConfigureExtensionData(); - $fixedGroups = array(); + $fixedGroups = []; foreach ( $groups as $g ) { if ( !is_array( $g ) ) { - $g = array( $g ); + $g = [ $g ]; } $name = $g['name']; @@ -256,17 +290,8 @@ class PremadeMediawikiExtensionGroups { $id = $this->idPrefix . preg_replace( '/\s+/', '', strtolower( $name ) ); } - // Default message file format is currently php - if ( !isset( $g['format'] ) ) { - $g['format'] = 'json'; - } - if ( !isset( $g['file'] ) ) { - if ( $g['format'] === 'json' ) { - $file = preg_replace( '/\s+/', '', "$name/i18n/%CODE%.json" ); - } else { - $file = preg_replace( '/\s+/', '', "$name/$name.i18n.php" ); - } + $file = preg_replace( '/\s+/', '', "$name/i18n/%CODE%.json" ); } else { $file = $g['file']; } @@ -284,24 +309,24 @@ class PremadeMediawikiExtensionGroups { $url = false; } - $newgroup = array( + $newgroup = [ 'name' => $name, 'file' => $file, 'descmsg' => $descmsg, 'url' => $url, - ); + ]; - $copyvars = array( + $copyvars = [ 'aliasfile', 'desc', - 'format', 'ignored', + 'languages', 'magicfile', 'mangle', 'optional', 'prefix', 'var', - ); + ]; foreach ( $copyvars as $var ) { if ( isset( $g[$var] ) ) { @@ -309,6 +334,15 @@ class PremadeMediawikiExtensionGroups { } } + // Mark some fixed form optional messages automatically + if ( !isset( $newgroup['optional' ] ) ) { + $newgroup['optional'] = []; + } + + // Mark extension name and skin names optional. + $newgroup['optional'][] = '*-extensionname'; + $newgroup['optional'][] = 'skinname-*'; + $fixedGroups[$id] = $newgroup; } @@ -317,21 +351,21 @@ class PremadeMediawikiExtensionGroups { protected function loadConfigureExtensionData() { if ( !$this->useConfigure ) { - return array(); + return []; } global $wgAutoloadClasses; $postfix = 'Configure/load_txt_def/TxtDef.php'; if ( !file_exists( "{$this->path}/$postfix" ) ) { - return array(); + return []; } $wgAutoloadClasses['TxtDef'] = "{$this->path}/$postfix"; $tmp = TxtDef::loadFromFile( "{$this->path}/Configure/settings/Settings-ext.txt" ); return array_combine( - array_map( array( __CLASS__, 'foldId' ), array_keys( $tmp ) ), + array_map( [ __CLASS__, 'foldId' ], array_keys( $tmp ) ), array_values( $tmp ) ); } |