MediaWiki master
LocalizedException.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Exception;
8
9use Exception;
12use Throwable;
14
24class 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
54class_alias( LocalizedException::class, 'LocalizedException' );
string array MessageSpecifier $messageSpec
__construct( $messageSpec, $code=0, ?Throwable $previous=null)
getMessageObject()
Return a Message object for this exception.Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:144
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:492
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:32
Interface for MediaWiki-localized exceptions.