2019-12-18 20:12:45 +00:00
|
|
|
<?php
|
|
|
|
|
2022-04-07 23:12:32 +00:00
|
|
|
namespace MediaWiki\Extension\Scribunto;
|
|
|
|
|
2023-06-09 12:43:44 +00:00
|
|
|
use Exception;
|
2023-08-19 18:18:41 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-04-07 23:12:32 +00:00
|
|
|
use Status;
|
|
|
|
|
2019-12-18 20:12:45 +00:00
|
|
|
/**
|
|
|
|
* An exception class which represents an error in the script. This does not
|
|
|
|
* normally abort the request, instead it is caught and shown to the user.
|
|
|
|
*/
|
2023-06-09 12:43:44 +00:00
|
|
|
class ScribuntoException extends Exception {
|
2019-12-18 20:12:45 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $messageName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $messageArgs;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $params;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $messageName
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
public function __construct( $messageName, $params = [] ) {
|
2022-09-28 14:34:34 +00:00
|
|
|
$this->messageArgs = $params['args'] ?? [];
|
2019-12-18 20:12:45 +00:00
|
|
|
if ( isset( $params['module'] ) && isset( $params['line'] ) ) {
|
|
|
|
$codeLocation = false;
|
|
|
|
if ( isset( $params['title'] ) ) {
|
|
|
|
$moduleTitle = Title::newFromText( $params['module'] );
|
|
|
|
if ( $moduleTitle && $moduleTitle->equals( $params['title'] ) ) {
|
|
|
|
$codeLocation = wfMessage( 'scribunto-line', $params['line'] )->inContentLanguage()->text();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $codeLocation === false ) {
|
|
|
|
$codeLocation = wfMessage(
|
|
|
|
'scribunto-module-line',
|
|
|
|
$params['module'],
|
|
|
|
$params['line']
|
|
|
|
)->inContentLanguage()->text();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$codeLocation = '[UNKNOWN]';
|
|
|
|
}
|
|
|
|
array_unshift( $this->messageArgs, $codeLocation );
|
2023-11-16 16:06:55 +00:00
|
|
|
$msg = wfMessage( $messageName )
|
|
|
|
->params( $this->messageArgs )
|
|
|
|
->inContentLanguage();
|
|
|
|
if ( isset( $params['title'] ) ) {
|
|
|
|
$msg = $msg->page( $params['title'] );
|
|
|
|
}
|
|
|
|
parent::__construct( $msg->text() );
|
2019-12-18 20:12:45 +00:00
|
|
|
|
|
|
|
$this->messageName = $messageName;
|
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMessageName() {
|
|
|
|
return $this->messageName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toStatus() {
|
|
|
|
$status = Status::newFatal( $this->messageName, ...$this->messageArgs );
|
2023-02-25 00:57:56 +00:00
|
|
|
$status->value = $this;
|
2019-12-18 20:12:45 +00:00
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the backtrace as HTML, or false if there is none available.
|
|
|
|
* @param array $options
|
|
|
|
* @return bool|string
|
|
|
|
*/
|
|
|
|
public function getScriptTraceHtml( $options = [] ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|