3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\Title
;
24 use ILocalizedException
;
25 use MediaWiki\Message\Message
;
28 * MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
32 class MalformedTitleException
extends Exception
implements ILocalizedException
{
34 /** @var string|null */
37 private $errorMessage;
39 private $errorMessageParameters;
43 * @param string $errorMessage Localisation message describing the error (since MW 1.26)
44 * @param string|null $titleText The invalid title text (since MW 1.26)
45 * @param array $errorMessageParameters Additional parameters for the error message.
46 * $titleText will be appended if it's not null. (since MW 1.26)
48 public function __construct(
49 $errorMessage, $titleText = null, $errorMessageParameters = []
51 $this->errorMessage
= $errorMessage;
52 $this->titleText
= $titleText;
53 if ( $titleText !== null ) {
54 $errorMessageParameters[] = wfEscapeWikiText( $titleText );
56 $this->errorMessageParameters
= $errorMessageParameters;
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() );
68 public function getTitleText() {
69 return $this->titleText
;
76 public function getErrorMessage() {
77 return $this->errorMessage
;
84 public function getErrorMessageParameters() {
85 return $this->errorMessageParameters
;
92 public function getMessageObject() {
93 return wfMessage( $this->getErrorMessage(), $this->getErrorMessageParameters() );
97 /** @deprecated class alias since 1.41 */
98 class_alias( MalformedTitleException
::class, 'MalformedTitleException' );