MediaWiki  1.34.0
LocalizedException.php
Go to the documentation of this file.
1 <?php
28 class LocalizedException extends Exception implements ILocalizedException {
30  protected $messageSpec;
31 
38  public function __construct( $messageSpec, $code = 0, $previous = null ) {
39  $this->messageSpec = $messageSpec;
40 
41  // Exception->getMessage() should be in plain English, not localized.
42  // So fetch the English version of the message, without local
43  // customizations, and make a basic attempt to turn markup into text.
44  $msg = $this->getMessageObject()->inLanguage( 'en' )->useDatabase( false )->text();
45  $msg = preg_replace( '!</?(var|kbd|samp|code)>!', '"', $msg );
46  $msg = Sanitizer::stripAllTags( $msg );
47  parent::__construct( $msg, $code, $previous );
48  }
49 
50  public function getMessageObject() {
51  return Message::newFromSpecifier( $this->messageSpec );
52  }
53 }
MessageSpecifier
Definition: MessageSpecifier.php:21
ILocalizedException
Interface for MediaWiki-localized exceptions.
Definition: ILocalizedException.php:27
LocalizedException
Basic localized exception.
Definition: LocalizedException.php:28
LocalizedException\getMessageObject
getMessageObject()
Return a Message object for this exception.
Definition: LocalizedException.php:50
LocalizedException\$messageSpec
string array MessageSpecifier $messageSpec
Definition: LocalizedException.php:30
LocalizedException\__construct
__construct( $messageSpec, $code=0, $previous=null)
Definition: LocalizedException.php:38