mediawiki-extensions-Scribunto/includes/common/ScribuntoException.php
Umherirrender 9c6f6f905a Split all classes in own files
Move autoload entries for test to TestAutoloadClasses key

Change-Id: Ie705db0e7225600b7b498cfa134733a65f1ae1c9
2019-12-21 10:20:18 +01:00

81 lines
1.9 KiB
PHP

<?php
/**
* 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.
*/
class ScribuntoException extends MWException {
/**
* @var string
*/
public $messageName;
/**
* @var array
*/
public $messageArgs;
/**
* @var array
*/
public $params;
/**
* @param string $messageName
* @param array $params
*/
public function __construct( $messageName, $params = [] ) {
if ( isset( $params['args'] ) ) {
$this->messageArgs = $params['args'];
} else {
$this->messageArgs = [];
}
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 );
$msg = wfMessage( $messageName )->params( $this->messageArgs )->inContentLanguage()->text();
parent::__construct( $msg );
$this->messageName = $messageName;
$this->params = $params;
}
/**
* @return string
*/
public function getMessageName() {
return $this->messageName;
}
public function toStatus() {
$status = Status::newFatal( $this->messageName, ...$this->messageArgs );
$status->scribunto_error = $this;
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;
}
}