2005-03-13 07:22:20 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* MediaWiki error classes
|
|
|
|
|
* Copyright (C) 2005 Brion Vibber <brion@pobox.com>
|
|
|
|
|
* http://www.mediawiki.org/
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-03-13 07:22:20 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2006-01-07 13:09:30 +00:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2005-03-13 07:22:20 +00:00
|
|
|
* (at your option) any later version.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-03-13 07:22:20 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-03-13 07:22:20 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2006-04-05 07:43:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-03-13 07:22:20 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Since PHP4 doesn't have exceptions, here's some error objects
|
|
|
|
|
* loosely modeled on the standard PEAR_Error model...
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Exception
|
2005-03-13 07:22:20 +00:00
|
|
|
*/
|
|
|
|
|
class WikiError {
|
|
|
|
|
/**
|
2008-05-22 19:48:26 +00:00
|
|
|
* @param $message string
|
2005-03-13 07:22:20 +00:00
|
|
|
*/
|
2007-01-20 13:34:31 +00:00
|
|
|
function __construct( $message ) {
|
2005-03-13 07:22:20 +00:00
|
|
|
$this->mMessage = $message;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-03-13 07:22:20 +00:00
|
|
|
/**
|
|
|
|
|
* @return string Plaintext error message to display
|
|
|
|
|
*/
|
2005-06-17 23:20:55 +00:00
|
|
|
function getMessage() {
|
2005-03-13 07:22:20 +00:00
|
|
|
return $this->mMessage;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-06-17 23:20:55 +00:00
|
|
|
/**
|
|
|
|
|
* In following PEAR_Error model this could be formatted differently,
|
|
|
|
|
* but so far it's not.
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function toString() {
|
|
|
|
|
return $this->getMessage();
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-03-13 07:22:20 +00:00
|
|
|
/**
|
|
|
|
|
* Returns true if the given object is a WikiError-descended
|
|
|
|
|
* error object, false otherwise.
|
|
|
|
|
*
|
2008-05-22 19:48:26 +00:00
|
|
|
* @param $object mixed
|
2005-03-13 07:22:20 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2006-11-29 11:43:58 +00:00
|
|
|
public static function isError( $object ) {
|
2006-11-29 05:45:03 +00:00
|
|
|
return $object instanceof WikiError;
|
2005-03-13 07:22:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Localized error message object
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Exception
|
2005-03-13 07:22:20 +00:00
|
|
|
*/
|
|
|
|
|
class WikiErrorMsg extends WikiError {
|
|
|
|
|
/**
|
2008-05-22 19:48:26 +00:00
|
|
|
* @param $message String: wiki message name
|
2005-03-13 07:22:20 +00:00
|
|
|
* @param ... parameters to pass to wfMsg()
|
|
|
|
|
*/
|
|
|
|
|
function WikiErrorMsg( $message/*, ... */ ) {
|
|
|
|
|
$args = func_get_args();
|
|
|
|
|
array_shift( $args );
|
|
|
|
|
$this->mMessage = wfMsgReal( $message, $args, true );
|
2009-02-04 20:11:27 +00:00
|
|
|
$this->mMsgKey = $message;
|
|
|
|
|
$this->mMsgArgs = $args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getMessageKey() {
|
|
|
|
|
return $this->mMsgKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getMessageArgs() {
|
|
|
|
|
return $this->mMsgArgs;
|
2005-03-13 07:22:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-09-13 06:21:18 +00:00
|
|
|
* Error class designed to handle errors involved with
|
|
|
|
|
* XML parsing
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Exception
|
2005-03-13 07:22:20 +00:00
|
|
|
*/
|
|
|
|
|
class WikiXmlError extends WikiError {
|
|
|
|
|
/**
|
2008-05-22 19:48:26 +00:00
|
|
|
* @param $parser resource
|
|
|
|
|
* @param $message string
|
|
|
|
|
* @param $context
|
|
|
|
|
* @param $offset Int
|
2005-03-13 07:22:20 +00:00
|
|
|
*/
|
2005-09-17 11:10:15 +00:00
|
|
|
function WikiXmlError( $parser, $message = 'XML parsing error', $context = null, $offset = 0 ) {
|
2005-03-13 07:22:20 +00:00
|
|
|
$this->mXmlError = xml_get_error_code( $parser );
|
2005-09-17 11:10:15 +00:00
|
|
|
$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 );
|
2005-03-13 07:22:20 +00:00
|
|
|
$this->mMessage = $message;
|
|
|
|
|
xml_parser_free( $parser );
|
2005-09-17 11:10:15 +00:00
|
|
|
wfDebug( "WikiXmlError: " . $this->getMessage() . "\n" );
|
2005-03-13 07:22:20 +00:00
|
|
|
}
|
2005-07-05 21:22:25 +00:00
|
|
|
|
2006-01-07 13:31:29 +00:00
|
|
|
/** @return string */
|
2005-06-17 23:20:55 +00:00
|
|
|
function getMessage() {
|
2008-01-22 20:59:22 +00:00
|
|
|
// '$1 at line $2, col $3 (byte $4): $5',
|
|
|
|
|
return wfMsgHtml( 'xml-error-string',
|
2005-09-17 11:10:15 +00:00
|
|
|
$this->mMessage,
|
|
|
|
|
$this->mLine,
|
|
|
|
|
$this->mColumn,
|
2008-01-22 20:59:22 +00:00
|
|
|
$this->mByte . $this->mContext,
|
2005-09-17 11:10:15 +00:00
|
|
|
xml_error_string( $this->mXmlError ) );
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-09-17 11:10:15 +00:00
|
|
|
function _extractContext( $context, $offset ) {
|
|
|
|
|
if( is_null( $context ) ) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
// Hopefully integer overflow will be handled transparently here
|
|
|
|
|
$inlineOffset = $this->mByte - $offset;
|
|
|
|
|
return '; "' . substr( $context, $inlineOffset, 16 ) . '"';
|
|
|
|
|
}
|
2005-03-13 07:22:20 +00:00
|
|
|
}
|
|
|
|
|
}
|