| 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 | * |
| 17 | */ |
| 18 | |
| 19 | namespace MediaWiki\Extension\ParserFunctions; |
| 20 | |
| 21 | use Exception; |
| 22 | use MediaWiki\Message\Message; |
| 23 | |
| 24 | class ExprError extends Exception { |
| 25 | /** @var Message */ |
| 26 | private $mwMessage; |
| 27 | |
| 28 | /** |
| 29 | * @param string $msg |
| 30 | * @param string $parameter |
| 31 | */ |
| 32 | public function __construct( $msg, $parameter = '' ) { |
| 33 | // Give grep a chance to find the usages: |
| 34 | // pfunc_expr_stack_exhausted, pfunc_expr_unexpected_number, pfunc_expr_preg_match_failure, |
| 35 | // pfunc_expr_unrecognised_word, pfunc_expr_unexpected_operator, pfunc_expr_missing_operand, |
| 36 | // pfunc_expr_unexpected_closing_bracket, pfunc_expr_unrecognised_punctuation, |
| 37 | // pfunc_expr_unclosed_bracket, pfunc_expr_division_by_zero, pfunc_expr_invalid_argument, |
| 38 | // pfunc_expr_invalid_argument_ln, pfunc_expr_unknown_error, pfunc_expr_not_a_number |
| 39 | $this->mwMessage = wfMessage( "pfunc_expr_$msg", $parameter ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Replacement for getMessage() to prevent message parsing during tests which initializes |
| 44 | * whole bloody MediaWiki. |
| 45 | * |
| 46 | * @return string Error message to be to be displayed to end users |
| 47 | */ |
| 48 | public function getUserFriendlyMessage() { |
| 49 | return $this->mwMessage->inContentLanguage()->text(); |
| 50 | } |
| 51 | } |