ece931f4383327ff1530085b73ddc05030ceb0f8
[lhc/web/wiklou.git] / includes / WikiError.php
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.
11 *
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.
16 *
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
21 *
22 * @package MediaWiki
23 */
24
25 /**
26 * Since PHP4 doesn't have exceptions, here's some error objects
27 * loosely modeled on the standard PEAR_Error model...
28 */
29 class WikiError {
30 /**
31 * @param string $message
32 */
33 function WikiError( $message ) {
34 $this->mMessage = $message;
35 }
36
37 /**
38 * @return string Plaintext error message to display
39 */
40 function getMessage() {
41 return $this->mMessage;
42 }
43
44 /**
45 * In following PEAR_Error model this could be formatted differently,
46 * but so far it's not.
47 * @return string
48 */
49 function toString() {
50 return $this->getMessage();
51 }
52
53 /**
54 * Returns true if the given object is a WikiError-descended
55 * error object, false otherwise.
56 *
57 * @param mixed $object
58 * @return bool
59 * @static
60 */
61 function isError( &$object ) {
62 return is_a( $object, 'WikiError' );
63 }
64 }
65
66 /**
67 * Localized error message object
68 */
69 class WikiErrorMsg extends WikiError {
70 /**
71 * @param string $message Wiki message name
72 * @param ... parameters to pass to wfMsg()
73 */
74 function WikiErrorMsg( $message/*, ... */ ) {
75 $args = func_get_args();
76 array_shift( $args );
77 $this->mMessage = wfMsgReal( $message, $args, true );
78 }
79 }
80
81 /**
82 *
83 */
84 class WikiXmlError extends WikiError {
85 /**
86 * @param resource $parser
87 * @param string $message
88 */
89 function WikiXmlError( $parser, $message = '' ) {
90 $this->mXmlError = xml_get_error_code( $parser );
91 $this->mMessage = $message;
92 xml_parser_free( $parser );
93 }
94
95 function getMessage() {
96 return $this->mMessage . ': ' . xml_error_string( $this->mXmlError );
97 }
98 }
99
100 ?>