mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-12-01 03:16:14 +00:00
aa4d72e3ff
The following continue to be ignored: * Generic.Arrays.DisallowLongArraySyntax.Found, because I'm not sure Scribunto is ready to abandon old version support in master. * MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures, because it's overly strict for its purpose. Squiz.Classes.ValidClassName.NotCamelCaps isn't ignored globally, we just ignore it explicitly every place it's needed. Change-Id: I307668da6ef7b3e23da19b1fd1e08914239b99b3
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
// @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps
|
|
class Scribunto_LuaMessageLibrary extends Scribunto_LuaLibraryBase {
|
|
function register() {
|
|
$lib = array(
|
|
'plain' => array( $this, 'messagePlain' ),
|
|
'check' => array( $this, 'messageCheck' ),
|
|
);
|
|
|
|
// Get the correct default language from the parser
|
|
if ( $this->getParser() ) {
|
|
$lang = $this->getParser()->getTargetLanguage();
|
|
} else {
|
|
global $wgContLang;
|
|
$lang = $wgContLang;
|
|
}
|
|
|
|
return $this->getEngine()->registerInterface( 'mw.message.lua', $lib, array(
|
|
'lang' => $lang->getCode(),
|
|
) );
|
|
}
|
|
|
|
private function makeMessage( $data, $setParams ) {
|
|
if ( isset( $data['rawMessage'] ) ) {
|
|
$msg = new RawMessage( $data['rawMessage'] );
|
|
} else {
|
|
$msg = Message::newFallbackSequence( $data['keys'] );
|
|
}
|
|
$msg->inLanguage( $data['lang'] )
|
|
->useDatabase( $data['useDB'] );
|
|
if ( $setParams ) {
|
|
$msg->params( array_values( $data['params'] ) );
|
|
}
|
|
return $msg;
|
|
}
|
|
|
|
function messagePlain( $data ) {
|
|
try {
|
|
$msg = $this->makeMessage( $data, true );
|
|
return array( $msg->plain() );
|
|
} catch ( MWException $ex ) {
|
|
throw new Scribunto_LuaError( "msg:plain() failed (" . $ex->getMessage() . ")" );
|
|
}
|
|
}
|
|
|
|
function messageCheck( $what, $data ) {
|
|
if ( !in_array( $what, array( 'exists', 'isBlank', 'isDisabled' ) ) ) {
|
|
throw new Scribunto_LuaError( "invalid what for 'messageCheck'" );
|
|
}
|
|
|
|
try {
|
|
$msg = $this->makeMessage( $data, false );
|
|
return array( call_user_func( array( $msg, $what ) ) );
|
|
} catch ( MWException $ex ) {
|
|
throw new Scribunto_LuaError( "msg:$what() failed (" . $ex->getMessage() . ")" );
|
|
}
|
|
}
|
|
}
|