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