X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMessage.php;h=74b4021ba896e6d25a886a64235e28fe23abbac3;hb=af94bc9c69db033c7308192b42a47a4f27e25878;hp=3bfaf4c554cecb4d45666a9f1ee61c1f66193a84;hpb=fac1ec45f1201c913f4dc1dc7a2a31d21f77993c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Message.php b/includes/Message.php index 3bfaf4c554..74b4021ba8 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -22,11 +22,11 @@ */ /** - * The Message class provides methods which fullfil two basic services: + * The Message class provides methods which fulfil two basic services: * - fetching interface messages * - processing messages into a variety of formats * - * First implemented with MediaWiki 1.17, the Message class is intented to + * First implemented with MediaWiki 1.17, the Message class is intended to * replace the old wfMsg* functions that over time grew unusable. * @see https://www.mediawiki.org/wiki/Manual:Messages_API for equivalences * between old and new functions. @@ -234,7 +234,13 @@ class Message { * @return string */ public function getKey() { - return $this->key; + if ( is_array( $this->key ) ) { + // May happen if some kind of fallback is applied. + // For now, just use the first key. We really need a better solution. + return $this->key[0]; + } else { + return $this->key; + } } /** @@ -261,7 +267,7 @@ class Message { /** * Factory function that is just wrapper for the real constructor. It is - * intented to be used instead of the real constructor, because it allows + * intended to be used instead of the real constructor, because it allows * chaining method calls, while new objects don't. * @since 1.17 * @param string $key message key @@ -326,7 +332,7 @@ class Message { if ( isset( $params[0] ) && is_array( $params[0] ) ) { $params = $params[0]; } - foreach( $params as $param ) { + foreach ( $params as $param ) { $this->parameters[] = self::rawParam( $param ); } return $this; @@ -344,7 +350,7 @@ class Message { if ( isset( $params[0] ) && is_array( $params[0] ) ) { $params = $params[0]; } - foreach( $params as $param ) { + foreach ( $params as $param ) { $this->parameters[] = self::numParam( $param ); } return $this; @@ -377,7 +383,7 @@ class Message { if ( $lang instanceof Language || $lang instanceof StubUserLang ) { $this->language = $lang; } elseif ( is_string( $lang ) ) { - if( $this->language->getCode() != $lang ) { + if ( $this->language->getCode() != $lang ) { $this->language = Language::factory( $lang ); } } else { @@ -484,17 +490,17 @@ class Message { $string = $this->replaceParameters( $string, 'before' ); # Maybe transform using the full parser - if( $this->format === 'parse' ) { + if ( $this->format === 'parse' ) { $string = $this->parseText( $string ); $m = array(); - if( preg_match( '/^

(.*)\n?<\/p>\n?$/sU', $string, $m ) ) { + if ( preg_match( '/^

(.*)\n?<\/p>\n?$/sU', $string, $m ) ) { $string = $m[1]; } - } elseif( $this->format === 'block-parse' ) { + } elseif ( $this->format === 'block-parse' ) { $string = $this->parseText( $string ); - } elseif( $this->format === 'text' ) { + } elseif ( $this->format === 'text' ) { $string = $this->transformText( $string ); - } elseif( $this->format === 'escaped' ) { + } elseif ( $this->format === 'escaped' ) { $string = $this->transformText( $string ); $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false ); } @@ -554,7 +560,7 @@ class Message { } /** - * Returns the message text as-is, only parameters are subsituted. + * Returns the message text as-is, only parameters are substituted. * @since 1.17 * @return String: Unescaped untransformed message text. */ @@ -633,7 +639,7 @@ class Message { } /** - * Substitutes any paramaters into the message text. + * Substitutes any parameters into the message text. * @since 1.17 * @param string $message the message text * @param string $type either before or after @@ -641,10 +647,10 @@ class Message { */ protected function replaceParameters( $message, $type = 'before' ) { $replacementKeys = array(); - foreach( $this->parameters as $n => $param ) { + foreach ( $this->parameters as $n => $param ) { list( $paramType, $value ) = $this->extractParam( $param ); if ( $type === $paramType ) { - $replacementKeys['$' . ($n + 1)] = $value; + $replacementKeys['$' . ( $n + 1 )] = $value; } } $message = strtr( $message, $replacementKeys ); @@ -760,7 +766,7 @@ class RawMessage extends Message { */ public function fetchMessage() { // Just in case the message is unset somewhere. - if( !isset( $this->message ) ) { + if ( !isset( $this->message ) ) { $this->message = $this->key; } return $this->message;