* (bug 1938) Fix normalization of character references in link text and
[mediawiki.git] / includes / WikiError.php
blob65a64556b28a4d98bc39dd20817a9784ba7c48a1
1 <?php
2 /**
3 * MediaWiki error classes
4 * Copyright (C) 2005 Brion Vibber <brion@pobox.com>
5 * http://www.mediawiki.org/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @package MediaWiki
25 /**
26 * Since PHP4 doesn't have exceptions, here's some error objects
27 * loosely modeled on the standard PEAR_Error model...
29 class WikiError {
30 /**
31 * @param string $message
33 function WikiError( $message ) {
34 $this->mMessage = $message;
37 /**
38 * @return string Plaintext error message to display
40 function toString() {
41 return $this->mMessage;
44 /**
45 * Returns true if the given object is a WikiError-descended
46 * error object, false otherwise.
48 * @param mixed $object
49 * @return bool
50 * @static
52 function isError( &$object ) {
53 return is_a( $object, 'WikiError' );
57 /**
58 * Localized error message object
60 class WikiErrorMsg extends WikiError {
61 /**
62 * @param string $message Wiki message name
63 * @param ... parameters to pass to wfMsg()
65 function WikiErrorMsg( $message/*, ... */ ) {
66 $args = func_get_args();
67 array_shift( $args );
68 $this->mMessage = wfMsgReal( $message, $args, true );
72 /**
75 class WikiXmlError extends WikiError {
76 /**
77 * @param resource $parser
78 * @param string $message
80 function WikiXmlError( $parser, $message = '' ) {
81 $this->mXmlError = xml_get_error_code( $parser );
82 $this->mMessage = $message;
83 xml_parser_free( $parser );
86 function toString() {
87 return $this->mMessage . ': ' . xml_error_string( $this->mXmlError );