MalformedTitleException.php 2.4 KB

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