* Generic operation result class
* Has warning/error list, boolean status and arbitrary value
*
- * "Good" means the operation was completed with no warnings or errors.
+ * "Good" means the operation was completed with no warnings or errors.
*
* "OK" means the operation was partially or wholly completed.
*
- * An operation which is not OK should have errors so that the user can be
- * informed as to what went wrong. Calling the fatal() function sets an error
+ * An operation which is not OK should have errors so that the user can be
+ * informed as to what went wrong. Calling the fatal() function sets an error
* message and simultaneously switches off the OK flag.
*/
class Status {
}
function warning( $message /*, parameters... */ ) {
- $params = array_slice( func_get_args(), 1 );
- $this->errors[] = array(
- 'type' => 'warning',
- 'message' => $message,
+ $params = array_slice( func_get_args(), 1 );
+ $this->errors[] = array(
+ 'type' => 'warning',
+ 'message' => $message,
'params' => $params );
}
* This can be used for non-fatal errors
*/
function error( $message /*, parameters... */ ) {
- $params = array_slice( func_get_args(), 1 );
- $this->errors[] = array(
- 'type' => 'error',
- 'message' => $message,
+ $params = array_slice( func_get_args(), 1 );
+ $this->errors[] = array(
+ 'type' => 'error',
+ 'message' => $message,
'params' => $params );
}
* Add an error and set OK to false, indicating that the operation as a whole was fatal
*/
function fatal( $message /*, parameters... */ ) {
- $params = array_slice( func_get_args(), 1 );
- $this->errors[] = array(
- 'type' => 'error',
- 'message' => $message,
+ $params = array_slice( func_get_args(), 1 );
+ $this->errors[] = array(
+ 'type' => 'error',
+ 'message' => $message,
'params' => $params );
$this->ok = false;
}
+ /**
+ * Sanitize the callback parameter on wakeup, to avoid arbitrary execution.
+ */
+ function __wakeup() {
+ $this->cleanCallback = false;
+ }
+
protected function cleanParams( $params ) {
if ( !$this->cleanCallback ) {
return $params;
protected function getItemXML( $item ) {
$params = $this->cleanParams( $item['params'] );
- $xml = "<{$item['type']}>\n" .
+ $xml = "<{$item['type']}>\n" .
Xml::element( 'message', null, $item['message'] ) . "\n" .
Xml::element( 'text', null, wfMsgReal( $item['message'], $params ) ) ."\n";
foreach ( $params as $param ) {
/**
* Get the error list as a wikitext formatted list
- * @param string $shortContext A short enclosing context message name, to be used
+ * @param string $shortContext A short enclosing context message name, to be used
* when there is a single error
* @param string $longContext A long enclosing context message name, for a list
*/
$this->fatal( 'internalerror_info',
__METHOD__." called for a good result, this is incorrect\n" );
} else {
- $this->fatal( 'internalerror_info',
+ $this->fatal( 'internalerror_info',
__METHOD__.": Invalid result object: no error text but not OK\n" );
}
}
if ( $longContext ) {
$s = wfMsgNoTrans( $longContext, $s );
} elseif ( $shortContext ) {
- $s = wfMsgNoTrans( $shortContext, "\n* $s\n" );
+ $s = wfMsgNoTrans( $shortContext, "\n$s\n" );
}
}
return $s;
$this->successCount += $other->successCount;
$this->failCount += $other->failCount;
}
-}
+
+ function getErrorsArray() {
+ $result = array();
+ foreach ( $this->errors as $error ) {
+ if ( $error['type'] == 'error' )
+ if( $error['params'] )
+ $result[] = array_merge( array( $error['message'] ), $error['params'] );
+ else
+ $result[] = $error['message'];
+ }
+ return $result;
+ }
+ /**
+ * Returns true if the specified message is present as a warning or error
+ */
+ function hasMessage( $msg ) {
+ foreach ( $this->errors as $error ) {
+ if ( $error['message'] === $msg ) {
+ return true;
+ }
+ }
+ return false;
+ }
+}