Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / title / MalformedTitleException.php
blob59a08490aa01852d95b4aba37be4b30e47bb59dd
1 <?php
2 /**
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
18 * @file
21 namespace MediaWiki\Title;
23 use Exception;
24 use ILocalizedException;
25 use MediaWiki\Message\Message;
27 /**
28 * MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
29 * @newable
30 * @since 1.23
32 class MalformedTitleException extends Exception implements ILocalizedException {
34 /** @var string|null */
35 private $titleText;
36 /** @var string */
37 private $errorMessage;
38 /** @var array */
39 private $errorMessageParameters;
41 /**
42 * @stable to call
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 = []
50 ) {
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() );
64 /**
65 * @since 1.26
66 * @return string|null
68 public function getTitleText() {
69 return $this->titleText;
72 /**
73 * @since 1.26
74 * @return string
76 public function getErrorMessage() {
77 return $this->errorMessage;
80 /**
81 * @since 1.26
82 * @return array
84 public function getErrorMessageParameters() {
85 return $this->errorMessageParameters;
88 /**
89 * @since 1.29
90 * @return Message
92 public function getMessageObject() {
93 return wfMessage( $this->getErrorMessage(), $this->getErrorMessageParameters() );
97 /** @deprecated class alias since 1.41 */
98 class_alias( MalformedTitleException::class, 'MalformedTitleException' );