MediaWiki master
LocalizedException.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Exception;
22
23use Exception;
26use Throwable;
28
38class LocalizedException extends Exception implements ILocalizedException {
40 protected $messageSpec;
41
49 public function __construct( $messageSpec, $code = 0, ?Throwable $previous = null ) {
50 $this->messageSpec = $messageSpec;
51
52 // Exception->getMessage() should be in plain English, not localized.
53 // So fetch the English version of the message, without local
54 // customizations, and make a basic attempt to turn markup into text.
55 $msg = $this->getMessageObject()->inLanguage( 'en' )->useDatabase( false )->text();
56 $msg = preg_replace( '!</?(var|kbd|samp|code)>!', '"', $msg );
57 $msg = Sanitizer::stripAllTags( $msg );
58 parent::__construct( $msg, $code, $previous );
59 }
60
61 public function getMessageObject() {
62 return Message::newFromSpecifier( $this->messageSpec );
63 }
64}
65
67class_alias( LocalizedException::class, 'LocalizedException' );
string array MessageSpecifier $messageSpec
__construct( $messageSpec, $code=0, ?Throwable $previous=null)
getMessageObject()
Return a Message object for this exception.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:157
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:516
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:46
Interface for MediaWiki-localized exceptions.