mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 22:15:26 +00:00
d51ca862c6
IMHO these can be considered unit tests; they were already fast, but now they're executed in an instant. This requires several changes: 1 - delay retrieving messages in AFPUserVisibleException, to avoid having to deal with i18n whenever we want to test exceptions; 2 - Use some DI for Parser and Tokenizer. Equivset-dependend tests are also moved to a new class, thus helping to fix the AF part of T189560. Change-Id: If4585bf9bb696857005cf40a0d6985c36ac7e7a8
63 lines
2 KiB
PHP
63 lines
2 KiB
PHP
<?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 {
|
|
/** @var string */
|
|
public $mExceptionID;
|
|
/** @var int */
|
|
public $mPosition;
|
|
/** @var array */
|
|
public $mParams;
|
|
|
|
/**
|
|
* @param string $exception_id
|
|
* @param int $position
|
|
* @param array $params
|
|
*/
|
|
public function __construct( $exception_id, $position, $params ) {
|
|
$this->mExceptionID = $exception_id;
|
|
$this->mPosition = $position;
|
|
$this->mParams = $params;
|
|
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* @return Message
|
|
*/
|
|
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
|
|
// abusefilter-exception-notarray, abusefilter-exception-unclosedcomment
|
|
// abusefilter-exception-invalidiprange, abusefilter-exception-disabledvar
|
|
// abusefilter-exception-variablevariable, abusefilter-exception-toomanyargs
|
|
return wfMessage(
|
|
'abusefilter-exception-' . $this->mExceptionID,
|
|
$this->mPosition, ...$this->mParams
|
|
);
|
|
}
|
|
}
|