Merge "[Bug 41030] fix fatal error when rendering non-existing pages"
[lhc/web/wiklou.git] / includes / Status.php
index 7b583b1..147b0df 100644 (file)
@@ -1,4 +1,24 @@
 <?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
@@ -144,35 +164,6 @@ class Status {
                return $cleanParams;
        }
 
-       /**
-        * @param $item
-        * @return string
-        */
-       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
-        * @return string
-        */
-       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
         *
@@ -194,17 +185,17 @@ class Status {
                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;
@@ -222,18 +213,27 @@ class Status {
        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
@@ -357,4 +357,11 @@ class Status {
        public function getMessage() {
                return $this->getWikiText();
        }
+
+       /**
+        * @return mixed
+        */
+       public function getValue() {
+               return $this->value;
+       }
 }