2016-12-17 17:52:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Exceptions that we might conceivably want to report to ordinary users
|
|
|
|
// (i.e. exceptions that don't represent bugs in the extension itself)
|
|
|
|
class AFPUserVisibleException extends AFPException {
|
2018-04-29 17:52:45 +00:00
|
|
|
/** @var string */
|
|
|
|
public $mExceptionID;
|
|
|
|
/** @var int */
|
2016-12-17 17:52:36 +00:00
|
|
|
public $mPosition;
|
2018-04-29 17:52:45 +00:00
|
|
|
/** @var array */
|
2016-12-17 17:52:36 +00:00
|
|
|
public $mParams;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $exception_id
|
|
|
|
* @param int $position
|
|
|
|
* @param array $params
|
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function __construct( $exception_id, $position, $params ) {
|
2016-12-17 17:52:36 +00:00
|
|
|
$this->mExceptionID = $exception_id;
|
|
|
|
$this->mPosition = $position;
|
|
|
|
$this->mParams = $params;
|
|
|
|
|
2019-08-21 10:04:10 +00:00
|
|
|
parent::__construct( $exception_id );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the message of the exception to a localized version
|
|
|
|
*/
|
|
|
|
public function setLocalizedMessage() {
|
|
|
|
$this->message = $this->getMessageObj()->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the error message in English for use in logs
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMessageForLogs() {
|
|
|
|
return $this->getMessageObj()->inLanguage( 'en' )->useDatabase( false )->text();
|
2016-12-17 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2018-06-08 06:11:09 +00:00
|
|
|
* @return Message
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2016-12-17 17:52:36 +00:00
|
|
|
public function getMessageObj() {
|
|
|
|
// Give grep a chance to find the usages:
|
|
|
|
// abusefilter-exception-unexpectedatend, abusefilter-exception-expectednotfound
|
|
|
|
// abusefilter-exception-unrecognisedkeyword, abusefilter-exception-unexpectedtoken
|
|
|
|
// abusefilter-exception-unclosedstring, abusefilter-exception-invalidoperator
|
|
|
|
// abusefilter-exception-unrecognisedtoken, abusefilter-exception-noparams
|
|
|
|
// abusefilter-exception-dividebyzero, abusefilter-exception-unrecognisedvar
|
|
|
|
// abusefilter-exception-notenoughargs, abusefilter-exception-regexfailure
|
|
|
|
// abusefilter-exception-overridebuiltin, abusefilter-exception-outofbounds
|
2018-04-16 15:37:10 +00:00
|
|
|
// abusefilter-exception-notarray, abusefilter-exception-unclosedcomment
|
2018-05-04 13:43:30 +00:00
|
|
|
// abusefilter-exception-invalidiprange, abusefilter-exception-disabledvar
|
2019-08-21 09:01:50 +00:00
|
|
|
// abusefilter-exception-variablevariable, abusefilter-exception-toomanyargs
|
2019-11-04 17:45:58 +00:00
|
|
|
// abusefilter-exception-negativeoffset
|
2016-12-17 17:52:36 +00:00
|
|
|
return wfMessage(
|
|
|
|
'abusefilter-exception-' . $this->mExceptionID,
|
2018-06-08 03:16:42 +00:00
|
|
|
$this->mPosition, ...$this->mParams
|
2016-12-17 17:52:36 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|