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