123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- class WikiError {
-
- function __construct( $message ) {
- $this->mMessage = $message;
- }
-
- function getMessage() {
- return $this->mMessage;
- }
-
- function toString() {
- return $this->getMessage();
- }
-
- public static function isError( $object ) {
- return $object instanceof WikiError;
- }
- }
- class WikiErrorMsg extends WikiError {
-
- function WikiErrorMsg( $message ) {
- $args = func_get_args();
- array_shift( $args );
- $this->mMessage = wfMsgReal( $message, $args, true );
- $this->mMsgKey = $message;
- $this->mMsgArgs = $args;
- }
-
- function getMessageKey() {
- return $this->mMsgKey;
- }
-
- function getMessageArgs() {
- return $this->mMsgArgs;
- }
- }
- class WikiXmlError extends WikiError {
-
- function WikiXmlError( $parser, $message = 'XML parsing error', $context = null, $offset = 0 ) {
- $this->mXmlError = xml_get_error_code( $parser );
- $this->mColumn = xml_get_current_column_number( $parser );
- $this->mLine = xml_get_current_line_number( $parser );
- $this->mByte = xml_get_current_byte_index( $parser );
- $this->mContext = $this->_extractContext( $context, $offset );
- $this->mMessage = $message;
- xml_parser_free( $parser );
- wfDebug( "WikiXmlError: " . $this->getMessage() . "\n" );
- }
-
- function getMessage() {
-
- return wfMsgHtml( 'xml-error-string',
- $this->mMessage,
- $this->mLine,
- $this->mColumn,
- $this->mByte . $this->mContext,
- xml_error_string( $this->mXmlError ) );
- }
- function _extractContext( $context, $offset ) {
- if( is_null( $context ) ) {
- return null;
- } else {
-
- $inlineOffset = $this->mByte - $offset;
- return '; "' . substr( $context, $inlineOffset, 16 ) . '"';
- }
- }
- }
|