MediaWiki master
LocalizedException.php
Go to the documentation of this file.
1<?php
24
34class LocalizedException extends Exception implements ILocalizedException {
36 protected $messageSpec;
37
45 public function __construct( $messageSpec, $code = 0, ?Throwable $previous = null ) {
46 $this->messageSpec = $messageSpec;
47
48 // Exception->getMessage() should be in plain English, not localized.
49 // So fetch the English version of the message, without local
50 // customizations, and make a basic attempt to turn markup into text.
51 $msg = $this->getMessageObject()->inLanguage( 'en' )->useDatabase( false )->text();
52 $msg = preg_replace( '!</?(var|kbd|samp|code)>!', '"', $msg );
53 $msg = Sanitizer::stripAllTags( $msg );
54 parent::__construct( $msg, $code, $previous );
55 }
56
57 public function getMessageObject() {
58 return Message::newFromSpecifier( $this->messageSpec );
59 }
60}
Basic localized exception.
__construct( $messageSpec, $code=0, ?Throwable $previous=null)
string array MessageSpecifier $messageSpec
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:155
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:46
Interface for MediaWiki-localized exceptions.