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