Ensure that Scribunto exceptions have a page context set

Some exception messages add tracking categories, which fail when there
is no title context.

Bug: T351045
Change-Id: I47d0160010c9da5a9a9974718a432fd5e79f8286
This commit is contained in:
C. Scott Ananian 2023-11-16 11:06:55 -05:00 committed by jenkins-bot
parent 42212c1172
commit d97ce9851c
3 changed files with 13 additions and 3 deletions

View file

@ -155,6 +155,8 @@ abstract class ScribuntoEngineBase {
$params = [];
if ( $this->title ) {
$params['title'] = $this->title;
} else {
wfDeprecated( __METHOD__ . ' without valid title for engine', '1.42' );
}
return $params;
}

View file

@ -51,8 +51,13 @@ class ScribuntoException extends Exception {
$codeLocation = '[UNKNOWN]';
}
array_unshift( $this->messageArgs, $codeLocation );
$msg = wfMessage( $messageName )->params( $this->messageArgs )->inContentLanguage()->text();
parent::__construct( $msg );
$msg = wfMessage( $messageName )
->params( $this->messageArgs )
->inContentLanguage();
if ( isset( $params['title'] ) ) {
$msg = $msg->page( $params['title'] );
}
parent::__construct( $msg->text() );
$this->messageName = $messageName;
$this->params = $params;

View file

@ -13,6 +13,7 @@ use MediaWiki\Extension\Scribunto\Engines\LuaStandalone\LuaStandaloneInterpreter
use MediaWiki\Extension\Scribunto\Engines\LuaStandalone\LuaStandaloneInterpreterFunction;
use MediaWiki\Extension\Scribunto\ScribuntoException;
use MediaWiki\Extension\Scribunto\Tests\Engines\LuaCommon\LuaInterpreterTestBase;
use MediaWiki\Title\Title;
use Wikimedia\TestingAccessWrapper;
/**
@ -37,7 +38,9 @@ class StandaloneInterpreterTest extends LuaInterpreterTestBase {
protected function newInterpreter( $opts = [] ) {
$opts += $this->stdOpts;
$engine = new LuaStandaloneEngine( $this->stdOpts );
$engine = new LuaStandaloneEngine( $this->stdOpts + [
'title' => Title::makeTitle( NS_MODULE, 'StandaloneInterpreterTest' ),
] );
return new LuaStandaloneInterpreter( $engine, $opts );
}