Ejemplo n.º 1
0
 /**
  * Get the error list as a Message object
  *
  * @param string|string[] $shortContext A short enclosing context message name (or an array of
  * message names), to be used when there is a single error.
  * @param string|string[] $longContext A long enclosing context message name (or an array of
  * message names), for a list.
  * @param string|Language $lang Language to use for processing messages
  * @return Message
  */
 public function getMessage($shortContext = false, $longContext = false, $lang = null)
 {
     $lang = $this->languageFromParam($lang);
     $rawErrors = $this->sv->getErrors();
     if (count($rawErrors) == 0) {
         if ($this->sv->isOK()) {
             $this->sv->fatal('internalerror_info', __METHOD__ . " called for a good result, this is incorrect\n");
         } else {
             $this->sv->fatal('internalerror_info', __METHOD__ . ": Invalid result object: no error text but not OK\n");
         }
         $rawErrors = $this->sv->getErrors();
         // just added a fatal
     }
     if (count($rawErrors) == 1) {
         $s = $this->getErrorMessage($rawErrors[0], $lang);
         if ($shortContext) {
             $s = wfMessage($shortContext, $s)->inLanguage($lang);
         } elseif ($longContext) {
             $wrapper = new RawMessage("* \$1\n");
             $wrapper->params($s)->parse();
             $s = wfMessage($longContext, $wrapper)->inLanguage($lang);
         }
     } else {
         $msgs = $this->getErrorMessageArray($rawErrors, $lang);
         $msgCount = count($msgs);
         if ($shortContext) {
             $msgCount++;
         }
         $s = new RawMessage('* $' . implode("\n* \$", range(1, $msgCount)));
         $s->params($msgs)->parse();
         if ($longContext) {
             $s = wfMessage($longContext, $s)->inLanguage($lang);
         } elseif ($shortContext) {
             $wrapper = new RawMessage("\n\$1\n", [$s]);
             $wrapper->parse();
             $s = wfMessage($shortContext, $wrapper)->inLanguage($lang);
         }
     }
     return $s;
 }