MediaWiki  master
MalformedTitleException.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Title;
22 
23 use Exception;
25 use Message;
26 
32 class MalformedTitleException extends Exception implements ILocalizedException {
33 
35  private $titleText;
37  private $errorMessage;
39  private $errorMessageParameters;
40 
48  public function __construct(
49  $errorMessage, $titleText = null, $errorMessageParameters = []
50  ) {
51  $this->errorMessage = $errorMessage;
52  $this->titleText = $titleText;
53  if ( $titleText !== null ) {
54  $errorMessageParameters[] = wfEscapeWikiText( $titleText );
55  }
56  $this->errorMessageParameters = $errorMessageParameters;
57 
58  // Supply something useful for Exception::getMessage() to return.
59  $enMsg = wfMessage( $errorMessage, $errorMessageParameters );
60  $enMsg->inLanguage( 'en' )->useDatabase( false );
61  parent::__construct( $enMsg->text() );
62  }
63 
68  public function getTitleText() {
69  return $this->titleText;
70  }
71 
76  public function getErrorMessage() {
77  return $this->errorMessage;
78  }
79 
84  public function getErrorMessageParameters() {
85  return $this->errorMessageParameters;
86  }
87 
92  public function getMessageObject() {
93  return wfMessage( $this->getErrorMessage(), $this->getErrorMessageParameters() );
94  }
95 }
96 
101 class_alias( MalformedTitleException::class, 'MalformedTitleException' );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
__construct( $errorMessage, $titleText=null, $errorMessageParameters=[])
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:144
Interface for MediaWiki-localized exceptions.