MediaWiki
master
Toggle main menu visibility
LocalizedException.php
Go to the documentation of this file.
1
<?php
6
7
namespace
MediaWiki\Exception;
8
9
use
Exception
;
10
use MediaWiki\Message\Message;
11
use MediaWiki\Parser\Sanitizer;
12
use Throwable;
13
use Wikimedia\Message\MessageSpecifier;
14
24
class
LocalizedException
extends
Exception
implements
ILocalizedException
{
26
protected
$messageSpec
;
27
35
public
function
__construct
(
$messageSpec
, $code = 0, ?Throwable $previous =
null
) {
36
$this->messageSpec =
$messageSpec
;
37
38
// Exception->getMessage() should be in plain English, not localized.
39
// So fetch the English version of the message, without local
40
// customizations, and make a basic attempt to turn markup into text.
41
$msg = $this->
getMessageObject
()->inLanguage(
'en'
)->useDatabase(
false
)->text();
42
$msg = preg_replace(
'!</?(var|kbd|samp|code)>!'
,
'"'
, $msg );
43
$msg = Sanitizer::stripAllTags( $msg );
44
parent::__construct( $msg, $code, $previous );
45
}
46
48
public
function
getMessageObject
() {
49
return
Message::newFromSpecifier
( $this->messageSpec );
50
}
51
}
52
54
class_alias( LocalizedException::class,
'LocalizedException'
);
MediaWiki\Exception\LocalizedException
Basic localized exception.
Definition
LocalizedException.php:24
MediaWiki\Exception\LocalizedException\$messageSpec
string array MessageSpecifier $messageSpec
Definition
LocalizedException.php:26
MediaWiki\Exception\LocalizedException\__construct
__construct( $messageSpec, $code=0, ?Throwable $previous=null)
Definition
LocalizedException.php:35
MediaWiki\Exception\LocalizedException\getMessageObject
getMessageObject()
Return a Message object for this exception.Message
Definition
LocalizedException.php:48
MediaWiki\Message\Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition
Message.php:492
MediaWiki\Exception\ILocalizedException
Interface for MediaWiki-localized exceptions.
Definition
ILocalizedException.php:19
Wikimedia\Message\MessageSpecifier
Definition
MessageSpecifier.php:12
MediaWiki\Exception
Definition
BadRequestError.php:7
includes
Exception
LocalizedException.php
Generated on
for MediaWiki by
1.18.0