MediaWiki REL1_34
LocalizedException.php
Go to the documentation of this file.
1<?php
28class 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}
Basic localized exception.
__construct( $messageSpec, $code=0, $previous=null)
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:427
Interface for MediaWiki-localized exceptions.