ErrorPageError.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * An error page which can definitely be safely rendered using the OutputPage.
  22. *
  23. * @since 1.7
  24. * @ingroup Exception
  25. */
  26. class ErrorPageError extends MWException implements ILocalizedException {
  27. public $title, $msg, $params;
  28. /**
  29. * Note: these arguments are keys into wfMessage(), not text!
  30. *
  31. * @param string|Message $title Message key (string) for page title, or a Message object
  32. * @param string|Message $msg Message key (string) for error text, or a Message object
  33. * @param array $params Array with parameters to wfMessage()
  34. */
  35. public function __construct( $title, $msg, $params = [] ) {
  36. $this->title = $title;
  37. $this->msg = $msg;
  38. $this->params = $params;
  39. // T46111: Messages in the log files should be in English and not
  40. // customized by the local wiki. So get the default English version for
  41. // passing to the parent constructor. Our overridden report() below
  42. // makes sure that the page shown to the user is not forced to English.
  43. $enMsg = $this->getMessageObject();
  44. $enMsg->inLanguage( 'en' )->useDatabase( false );
  45. parent::__construct( $enMsg->text() );
  46. }
  47. /**
  48. * Return a Message object for this exception
  49. * @since 1.29
  50. * @return Message
  51. */
  52. public function getMessageObject() {
  53. if ( $this->msg instanceof Message ) {
  54. return clone $this->msg;
  55. }
  56. return wfMessage( $this->msg, $this->params );
  57. }
  58. public function report() {
  59. if ( self::isCommandLine() || defined( 'MW_API' ) ) {
  60. parent::report();
  61. } else {
  62. global $wgOut;
  63. $wgOut->showErrorPage( $this->title, $this->msg, $this->params );
  64. $wgOut->output();
  65. }
  66. }
  67. }