MediaWiki  master
LocalizedException.php
Go to the documentation of this file.
1 <?php
30 class 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 }
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:398
Sanitizer\stripAllTags
static stripAllTags( $html)
Take a fragment of (potentially invalid) HTML and return a version with any tags removed,...
Definition: Sanitizer.php:1577
MessageSpecifier
Definition: MessageSpecifier.php:24
ILocalizedException
Interface for MediaWiki-localized exceptions.
Definition: ILocalizedException.php:29
LocalizedException
Basic localized exception.
Definition: LocalizedException.php:30
LocalizedException\__construct
__construct( $messageSpec, $code=0, Throwable $previous=null)
Definition: LocalizedException.php:41
LocalizedException\getMessageObject
getMessageObject()
Return a Message object for this exception.
Definition: LocalizedException.php:53
LocalizedException\$messageSpec
string array MessageSpecifier $messageSpec
Definition: LocalizedException.php:32