2016-12-17 17:52:36 +00:00
|
|
|
<?php
|
|
|
|
|
2020-12-03 22:22:43 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Parser;
|
|
|
|
|
|
|
|
use Message;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exceptions that we might conceivably want to report to ordinary users
|
|
|
|
* (i.e. exceptions that don't represent bugs in the extension itself)
|
|
|
|
*/
|
2016-12-17 17:52:36 +00:00
|
|
|
class AFPUserVisibleException extends AFPException {
|
2018-04-29 17:52:45 +00:00
|
|
|
/** @var string */
|
|
|
|
public $mExceptionID;
|
|
|
|
/** @var int */
|
2020-12-18 16:53:36 +00:00
|
|
|
protected $mPosition;
|
2018-04-29 17:52:45 +00:00
|
|
|
/** @var array */
|
2020-12-18 16:53:36 +00:00
|
|
|
protected $mParams;
|
2016-12-17 17:52:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 );
|
|
|
|
}
|
|
|
|
|
2020-12-18 16:53:36 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getPosition() : int {
|
|
|
|
return $this->mPosition;
|
|
|
|
}
|
|
|
|
|
2019-08-21 10:04:10 +00:00
|
|
|
/**
|
2021-01-10 19:26:01 +00:00
|
|
|
* Returns the error message for use in logs
|
2019-08-21 10:04:10 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-01-10 19:26:01 +00:00
|
|
|
public function getMessageForLogs() : string {
|
|
|
|
return "ID: {$this->mExceptionID}; position: {$this->mPosition}; params: " . implode( $this->mParams );
|
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
|
|
|
*/
|
2021-01-10 19:26:01 +00:00
|
|
|
public function getMessageObj() : Message {
|
2016-12-17 17:52:36 +00:00
|
|
|
// 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
|
2021-01-10 19:26:01 +00:00
|
|
|
return new Message(
|
2016-12-17 17:52:36 +00:00
|
|
|
'abusefilter-exception-' . $this->mExceptionID,
|
2021-01-10 19:26:01 +00:00
|
|
|
array_merge( [ $this->mPosition ], $this->mParams )
|
2016-12-17 17:52:36 +00:00
|
|
|
);
|
|
|
|
}
|
2021-02-09 11:03:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Serialize data for edit stash
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray() : array {
|
|
|
|
return [
|
|
|
|
'class' => static::class,
|
|
|
|
'exceptionID' => $this->mExceptionID,
|
|
|
|
'position' => $this->mPosition,
|
|
|
|
'params' => $this->mParams,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deserialize data from edit stash
|
|
|
|
* @param array $value
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public static function fromArray( array $value ) {
|
|
|
|
$cls = $value['class'];
|
|
|
|
return new $cls( $value['exceptionID'], $value['position'], $value['params'] );
|
|
|
|
}
|
|
|
|
|
2016-12-17 17:52:36 +00:00
|
|
|
}
|