summaryrefslogtreecommitdiff
path: root/includes/Status.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2013-12-08 09:55:49 +0100
committerPierre Schmitz <pierre@archlinux.de>2013-12-08 09:55:49 +0100
commit4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch)
treeaf68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /includes/Status.php
parentaf4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff)
Update to MediaWiki 1.22.0
Diffstat (limited to 'includes/Status.php')
-rw-r--r--includes/Status.php91
1 files changed, 71 insertions, 20 deletions
diff --git a/includes/Status.php b/includes/Status.php
index 5d6236f7..928f8ebd 100644
--- a/includes/Status.php
+++ b/includes/Status.php
@@ -31,6 +31,11 @@
* 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.
+ *
+ * The recommended pattern for Status objects is to return a Status object
+ * unconditionally, i.e. both on success and on failure -- so that the
+ * developer of the calling code is reminded that the function can fail, and
+ * so that a lack of error-handling will be explicit.
*/
class Status {
var $ok = true;
@@ -183,15 +188,18 @@ class Status {
}
}
if ( count( $this->errors ) == 1 ) {
- $s = $this->getErrorMessage( $this->errors[0] );
+ $s = $this->getErrorMessage( $this->errors[0] )->plain();
if ( $shortContext ) {
$s = wfMessage( $shortContext, $s )->plain();
} elseif ( $longContext ) {
$s = wfMessage( $longContext, "* $s\n" )->plain();
}
} else {
- $s = '* '. implode( "\n* ",
- $this->getErrorMessageArray( $this->errors ) ) . "\n";
+ $errors = $this->getErrorMessageArray( $this->errors );
+ foreach ( $errors as &$error ) {
+ $error = $error->plain();
+ }
+ $s = '* ' . implode( "\n* ", $errors ) . "\n";
if ( $longContext ) {
$s = wfMessage( $longContext, $s )->plain();
} elseif ( $shortContext ) {
@@ -202,6 +210,56 @@ class Status {
}
/**
+ * Get the error list as a Message object
+ *
+ * @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
+ * @return Message
+ */
+ function getMessage( $shortContext = false, $longContext = false ) {
+ if ( count( $this->errors ) == 0 ) {
+ if ( $this->ok ) {
+ $this->fatal( 'internalerror_info',
+ __METHOD__ . " called for a good result, this is incorrect\n" );
+ } else {
+ $this->fatal( 'internalerror_info',
+ __METHOD__ . ": Invalid result object: no error text but not OK\n" );
+ }
+ }
+ if ( count( $this->errors ) == 1 ) {
+ $s = $this->getErrorMessage( $this->errors[0] );
+ if ( $shortContext ) {
+ $s = wfMessage( $shortContext, $s );
+ } elseif ( $longContext ) {
+ $wrapper = new RawMessage( "* \$1\n" );
+ $wrapper->params( $s )->parse();
+ $s = wfMessage( $longContext, $wrapper );
+ }
+ } else {
+ $msgs = $this->getErrorMessageArray( $this->errors );
+ $msgCount = count( $msgs );
+
+ if ( $shortContext ) {
+ $msgCount++;
+ }
+
+ $wrapper = new RawMessage( '* $' . implode( "\n* \$", range( 1, $msgCount ) ) );
+ $s = $wrapper->params( $msgs )->parse();
+
+ if ( $longContext ) {
+ $s = wfMessage( $longContext, $wrapper );
+ } elseif ( $shortContext ) {
+ $wrapper = new RawMessage( "\n\$1\n", $wrapper );
+ $wrapper->parse();
+ $s = wfMessage( $shortContext, $wrapper );
+ }
+ }
+
+ return $s;
+ }
+
+ /**
* Return the message for a single error.
* @param $error Mixed With an array & two values keyed by
* 'message' and 'params', use those keys-value pairs.
@@ -212,7 +270,7 @@ class Status {
*/
protected function getErrorMessage( $error ) {
if ( is_array( $error ) ) {
- if( isset( $error['message'] ) && $error['message'] instanceof Message ) {
+ if ( isset( $error['message'] ) && $error['message'] instanceof Message ) {
$msg = $error['message'];
} elseif ( isset( $error['message'] ) && isset( $error['params'] ) ) {
$msg = wfMessage( $error['message'],
@@ -225,7 +283,7 @@ class Status {
} else {
$msg = wfMessage( $error );
}
- return $msg->plain();
+ return $msg;
}
/**
@@ -234,7 +292,7 @@ class Status {
*
* @note: this does not perform a full wikitext to HTML conversion, it merely applies
* a message transformation.
- * @todo: figure out whether that is actually The Right Thing.
+ * @todo figure out whether that is actually The Right Thing.
*/
public function getHTML( $shortContext = false, $longContext = false ) {
$text = $this->getWikiText( $shortContext, $longContext );
@@ -269,7 +327,8 @@ class Status {
/**
* Get the list of errors (but not warnings)
*
- * @return Array
+ * @return array A list in which each entry is an array with a message key as its first element.
+ * The remaining array elements are the message parameters.
*/
function getErrorsArray() {
return $this->getStatusArray( "error" );
@@ -278,7 +337,8 @@ class Status {
/**
* Get the list of warnings (but not errors)
*
- * @return Array
+ * @return array A list in which each entry is an array with a message key as its first element.
+ * The remaining array elements are the message parameters.
*/
function getWarningsArray() {
return $this->getStatusArray( "warning" );
@@ -294,9 +354,9 @@ class Status {
$result = array();
foreach ( $this->errors as $error ) {
if ( $error['type'] === $type ) {
- if( $error['message'] instanceof Message ) {
- $result[] = $error['message'];
- } elseif( $error['params'] ) {
+ if ( $error['message'] instanceof Message ) {
+ $result[] = array_merge( array( $error['message']->getKey() ), $error['message']->getParams() );
+ } elseif ( $error['params'] ) {
$result[] = array_merge( array( $error['message'] ), $error['params'] );
} else {
$result[] = array( $error['message'] );
@@ -365,15 +425,6 @@ class Status {
}
/**
- * Backward compatibility function for WikiError -> Status migration
- *
- * @return String
- */
- public function getMessage() {
- return $this->getWikiText();
- }
-
- /**
* @return mixed
*/
public function getValue() {