<?php
+/**
+ * Generic operation result.
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
/**
* Generic operation result class
/** Counters for batch operations */
public $successCount = 0, $failCount = 0;
- /** Array to indicate which items of the batch operations failed */
+ /** Array to indicate which items of the batch operations were successful */
public $success = array();
/*semi-private*/ var $errors = array();
* Factory function for fatal errors
*
* @param $message String: message name
+ * @return Status
*/
static function newFatal( $message /*, parameters...*/ ) {
$params = func_get_args();
* Factory function for good results
*
* @param $value Mixed
+ * @return Status
*/
static function newGood( $value = null ) {
$result = new self;
/**
* Change operation result
*
- * @param $ok Boolean: whether to operation completed
+ * @param $ok Boolean: whether the operation completed
* @param $value Mixed
*/
function setResult( $ok, $value = null ) {
$this->cleanCallback = false;
}
+ /**
+ * @param $params array
+ * @return array
+ */
protected function cleanParams( $params ) {
if ( !$this->cleanCallback ) {
return $params;
return $cleanParams;
}
- protected function getItemXML( $item ) {
- $params = $this->cleanParams( $item['params'] );
- $xml = "<{$item['type']}>\n" .
- Xml::element( 'message', null, $item['message'] ) . "\n" .
- Xml::element( 'text', null, wfMsg( $item['message'], $params ) ) ."\n";
- foreach ( $params as $param ) {
- $xml .= Xml::element( 'param', null, $param );
- }
- $xml .= "</{$item['type']}>\n";
- return $xml;
- }
-
- /**
- * Get the error list as XML
- */
- function getXML() {
- $xml = "<errors>\n";
- foreach ( $this->errors as $error ) {
- $xml .= $this->getItemXML( $error );
- }
- $xml .= "</errors>\n";
- return $xml;
- }
-
/**
* Get the error list as a wikitext formatted list
*
if ( count( $this->errors ) == 1 ) {
$s = $this->getWikiTextForError( $this->errors[0], $this->errors[0] );
if ( $shortContext ) {
- $s = wfMsgNoTrans( $shortContext, $s );
+ $s = wfMessage( $shortContext, $s )->plain();
} elseif ( $longContext ) {
- $s = wfMsgNoTrans( $longContext, "* $s\n" );
+ $s = wfMessage( $longContext, "* $s\n" )->plain();
}
} else {
$s = '* '. implode("\n* ",
$this->getWikiTextArray( $this->errors ) ) . "\n";
if ( $longContext ) {
- $s = wfMsgNoTrans( $longContext, $s );
+ $s = wfMessage( $longContext, $s )->plain();
} elseif ( $shortContext ) {
- $s = wfMsgNoTrans( $shortContext, "\n$s\n" );
+ $s = wfMessage( $shortContext, "\n$s\n" )->plain();
}
}
return $s;
protected function getWikiTextForError( $error ) {
if ( is_array( $error ) ) {
if ( isset( $error['message'] ) && isset( $error['params'] ) ) {
- return wfMsgNoTrans( $error['message'],
- array_map( 'wfEscapeWikiText', $this->cleanParams( $error['params'] ) ) );
+ return wfMessage( $error['message'],
+ array_map( 'wfEscapeWikiText', $this->cleanParams( $error['params'] ) ) )->plain();
} else {
$message = array_shift($error);
- return wfMsgNoTrans( $message,
- array_map( 'wfEscapeWikiText', $this->cleanParams( $error ) ) );
+ return wfMessage( $message,
+ array_map( 'wfEscapeWikiText', $this->cleanParams( $error ) ) )->plain();
}
} else {
- return wfMsgNoTrans( $error );
+ return wfMessage( $error )->plain();
}
}
+ /**
+ * Get the error message as HTML. This is done by parsing the wikitext error
+ * message.
+ */
+ public function getHTML( $shortContext = false, $longContext = false ) {
+ $text = $this->getWikiText( $shortContext, $longContext );
+ return MessageCache::singleton()->transform( $text, true );
+ }
+
/**
* Return an array with the wikitext for each item in the array.
* @param $errors Array
}
return $result;
}
-
+
/**
* Returns a list of status messages of the given type, with message and
* params left untouched, like a sane version of getStatusArray
- *
+ *
* @param $type String
*
* @return Array
foreach ( $this->errors as $error ) {
if ( $error['type'] === $type ) {
$result[] = $error;
- }
+ }
}
return $result;
}
}
/**
- * If the specified source message exists, replace it with the specified
+ * If the specified source message exists, replace it with the specified
* destination message, but keep the same parameters as in the original error.
*
* Return true if the replacement was done, false otherwise.
+ *
+ * @return bool
*/
function replaceMessage( $source, $dest ) {
$replaced = false;
public function getMessage() {
return $this->getWikiText();
}
+
+ /**
+ * @return mixed
+ */
+ public function getValue() {
+ return $this->value;
+ }
}