MediaWiki
REL1_19
|
00001 <?php 00031 class WikiError { 00037 function __construct( $message ) { 00038 wfDeprecated( __METHOD__, '1.17' ); 00039 $this->mMessage = $message; 00040 } 00041 00045 function getMessage() { 00046 return $this->mMessage; 00047 } 00048 00054 function toString() { 00055 return $this->getMessage(); 00056 } 00057 00067 public static function isError( $object ) { 00068 wfDeprecated( __METHOD__, '1.17' ); 00069 if ( $object instanceof WikiError ) { 00070 return true; 00071 } elseif ( $object instanceof Status ) { 00072 return !$object->isOK(); 00073 } else { 00074 return false; 00075 } 00076 } 00077 } 00078 00083 class WikiErrorMsg extends WikiError { 00090 function __construct( $message/*, ... */ ) { 00091 wfDeprecated( __METHOD__, '1.17' ); 00092 $args = func_get_args(); 00093 array_shift( $args ); 00094 $this->mMessage = wfMsgReal( $message, $args, true ); 00095 $this->mMsgKey = $message; 00096 $this->mMsgArgs = $args; 00097 } 00098 00099 function getMessageKey() { 00100 return $this->mMsgKey; 00101 } 00102 00103 function getMessageArgs() { 00104 return $this->mMsgArgs; 00105 } 00106 } 00107 00113 class WikiXmlError extends WikiError { 00122 function __construct( $parser, $message = 'XML parsing error', $context = null, $offset = 0 ) { 00123 wfDeprecated( __METHOD__, '1.17' ); 00124 $this->mXmlError = xml_get_error_code( $parser ); 00125 $this->mColumn = xml_get_current_column_number( $parser ); 00126 $this->mLine = xml_get_current_line_number( $parser ); 00127 $this->mByte = xml_get_current_byte_index( $parser ); 00128 $this->mContext = $this->_extractContext( $context, $offset ); 00129 $this->mMessage = $message; 00130 xml_parser_free( $parser ); 00131 wfDebug( "WikiXmlError: " . $this->getMessage() . "\n" ); 00132 } 00133 00135 function getMessage() { 00136 // '$1 at line $2, col $3 (byte $4): $5', 00137 return wfMsgHtml( 'xml-error-string', 00138 $this->mMessage, 00139 $this->mLine, 00140 $this->mColumn, 00141 $this->mByte . $this->mContext, 00142 xml_error_string( $this->mXmlError ) ); 00143 } 00144 00145 function _extractContext( $context, $offset ) { 00146 if( is_null( $context ) ) { 00147 return null; 00148 } else { 00149 // Hopefully integer overflow will be handled transparently here 00150 $inlineOffset = $this->mByte - $offset; 00151 return '; "' . substr( $context, $inlineOffset, 16 ) . '"'; 00152 } 00153 } 00154 }