Make MalformedTitleException errorMessage non-null
[lhc/web/wiklou.git] / includes / title / MalformedTitleException.php
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.
7 *
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.
12 *
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
17 *
18 * @file
19 */
20
21 /**
22 * MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
23 * @since 1.23
24 */
25 class MalformedTitleException extends Exception implements ILocalizedException {
26 private $titleText = null;
27 private $errorMessage = null;
28 private $errorMessageParameters = [];
29
30 /**
31 * @param string $errorMessage Localisation message describing the error (since MW 1.26)
32 * @param string $titleText The invalid title text (since MW 1.26)
33 * @param string[] $errorMessageParameters Additional parameters for the error message.
34 * $titleText will be appended if it's not null. (since MW 1.26)
35 */
36 public function __construct(
37 $errorMessage, $titleText = null, $errorMessageParameters = []
38 ) {
39 $this->errorMessage = $errorMessage;
40 $this->titleText = $titleText;
41 if ( $titleText !== null ) {
42 $errorMessageParameters[] = $titleText;
43 }
44 $this->errorMessageParameters = $errorMessageParameters;
45
46 // Supply something useful for Exception::getMessage() to return.
47 $enMsg = wfMessage( $errorMessage, $errorMessageParameters );
48 $enMsg->inLanguage( 'en' )->useDatabase( false );
49 parent::__construct( $enMsg->text() );
50 }
51
52 /**
53 * @since 1.26
54 * @return string|null
55 */
56 public function getTitleText() {
57 return $this->titleText;
58 }
59
60 /**
61 * @since 1.26
62 * @return string
63 */
64 public function getErrorMessage() {
65 return $this->errorMessage;
66 }
67
68 /**
69 * @since 1.26
70 * @return string[]
71 */
72 public function getErrorMessageParameters() {
73 return $this->errorMessageParameters;
74 }
75
76 /**
77 * @since 1.29
78 * @return Message
79 */
80 public function getMessageObject() {
81 return wfMessage( $this->getErrorMessage(), $this->getErrorMessageParameters() );
82 }
83 }