00001 <?php
00029 class WikiError {
00033 function __construct( $message ) {
00034 $this->mMessage = $message;
00035 }
00036
00040 function getMessage() {
00041 return $this->mMessage;
00042 }
00043
00049 function toString() {
00050 return $this->getMessage();
00051 }
00052
00060 public static function isError( $object ) {
00061 return $object instanceof WikiError;
00062 }
00063 }
00064
00069 class WikiErrorMsg extends WikiError {
00074 function WikiErrorMsg( $message ) {
00075 $args = func_get_args();
00076 array_shift( $args );
00077 $this->mMessage = wfMsgReal( $message, $args, true );
00078 $this->mMsgKey = $message;
00079 $this->mMsgArgs = $args;
00080 }
00081
00082 function getMessageKey() {
00083 return $this->mMsgKey;
00084 }
00085
00086 function getMessageArgs() {
00087 return $this->mMsgArgs;
00088 }
00089 }
00090
00096 class WikiXmlError extends WikiError {
00103 function WikiXmlError( $parser, $message = 'XML parsing error', $context = null, $offset = 0 ) {
00104 $this->mXmlError = xml_get_error_code( $parser );
00105 $this->mColumn = xml_get_current_column_number( $parser );
00106 $this->mLine = xml_get_current_line_number( $parser );
00107 $this->mByte = xml_get_current_byte_index( $parser );
00108 $this->mContext = $this->_extractContext( $context, $offset );
00109 $this->mMessage = $message;
00110 xml_parser_free( $parser );
00111 wfDebug( "WikiXmlError: " . $this->getMessage() . "\n" );
00112 }
00113
00115 function getMessage() {
00116
00117 return wfMsgHtml( 'xml-error-string',
00118 $this->mMessage,
00119 $this->mLine,
00120 $this->mColumn,
00121 $this->mByte . $this->mContext,
00122 xml_error_string( $this->mXmlError ) );
00123 }
00124
00125 function _extractContext( $context, $offset ) {
00126 if( is_null( $context ) ) {
00127 return null;
00128 } else {
00129
00130 $inlineOffset = $this->mByte - $offset;
00131 return '; "' . substr( $context, $inlineOffset, 16 ) . '"';
00132 }
00133 }
00134 }