3 * MediaWiki error classes
4 * Copyright (C) 2005 Brion Vibber <brion@pobox.com>
5 * http://www.mediawiki.org/
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
26 * Since PHP4 doesn't have exceptions, here's some error objects
27 * loosely modeled on the standard PEAR_Error model...
32 * @param string $message
34 function WikiError( $message ) {
35 $this->mMessage
= $message;
39 * @return string Plaintext error message to display
41 function getMessage() {
42 return $this->mMessage
;
46 * In following PEAR_Error model this could be formatted differently,
47 * but so far it's not.
51 return $this->getMessage();
55 * Returns true if the given object is a WikiError-descended
56 * error object, false otherwise.
58 * @param mixed $object
62 function isError( &$object ) {
63 return is_a( $object, 'WikiError' );
68 * Localized error message object
71 class WikiErrorMsg
extends WikiError
{
73 * @param string $message Wiki message name
74 * @param ... parameters to pass to wfMsg()
76 function WikiErrorMsg( $message/*, ... */ ) {
77 $args = func_get_args();
79 $this->mMessage
= wfMsgReal( $message, $args, true );
87 class WikiXmlError
extends WikiError
{
89 * @param resource $parser
90 * @param string $message
92 function WikiXmlError( $parser, $message = '' ) {
93 $this->mXmlError
= xml_get_error_code( $parser );
94 $this->mMessage
= $message;
95 xml_parser_free( $parser );
99 function getMessage() {
100 return $this->mMessage
. ': ' . xml_error_string( $this->mXmlError
);